SumProperty.java

  1. /*
  2.  * Copyright © 2014 - 2021 Leipzig University (Database Research Group)
  3.  *
  4.  * Licensed under the Apache License, Version 2.0 (the "License");
  5.  * you may not use this file except in compliance with the License.
  6.  * You may obtain a copy of the License at
  7.  *
  8.  *     http://www.apache.org/licenses/LICENSE-2.0
  9.  *
  10.  * Unless required by applicable law or agreed to in writing, software
  11.  * distributed under the License is distributed on an "AS IS" BASIS,
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.  * See the License for the specific language governing permissions and
  14.  * limitations under the License.
  15.  */
  16. package org.gradoop.flink.model.impl.operators.aggregation.functions.sum;

  17. import org.gradoop.common.model.api.entities.Element;
  18. import org.gradoop.common.model.impl.properties.PropertyValue;
  19. import org.gradoop.flink.model.impl.operators.aggregation.functions.BaseAggregateFunction;

  20. import java.util.Objects;

  21. /**
  22.  * Superclass of aggregate functions that sum property values of elements.
  23.  */
  24. public class SumProperty extends BaseAggregateFunction implements Sum {

  25.   /**
  26.    * Property key whose value should be aggregated.
  27.    */
  28.   private final String propertyKey;

  29.   /**
  30.    * Creates a new instance of a SumProperty aggregate function.
  31.    *
  32.    * @param propertyKey property key to aggregate
  33.    */
  34.   public SumProperty(String propertyKey) {
  35.     this(propertyKey, "sum_" + propertyKey);
  36.   }

  37.   /**
  38.    * Creates a new instance of a SumProperty aggregate function.
  39.    *
  40.    * @param propertyKey property key to aggregate
  41.    * @param aggregatePropertyKey aggregate property key
  42.    */
  43.   public SumProperty(String propertyKey, String aggregatePropertyKey) {
  44.     super(aggregatePropertyKey);
  45.     Objects.requireNonNull(propertyKey);
  46.     this.propertyKey = propertyKey;
  47.   }

  48.   @Override
  49.   public PropertyValue getIncrement(Element element) {
  50.     return element.getPropertyValue(propertyKey);
  51.   }
  52. }