MinFrequency.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.algorithms.fsm.transactional.tle.functions;

  17. import org.apache.flink.api.common.functions.MapFunction;
  18. import org.gradoop.flink.algorithms.fsm.transactional.common.FSMConfig;

  19. import java.math.BigDecimal;

  20. /**
  21.  * Calculates the min frequency based on a configured min support.
  22.  */
  23. public class MinFrequency implements MapFunction<Long, Long> {

  24.   /**
  25.    * FSM configuration
  26.    */
  27.   private final FSMConfig fsmConfig;

  28.   /**
  29.    * Constructor.
  30.    * @param fsmConfig FSM configuration
  31.    */
  32.   public MinFrequency(FSMConfig fsmConfig) {
  33.     this.fsmConfig = fsmConfig;
  34.   }

  35.   @Override
  36.   public Long map(Long count) throws Exception {
  37.     return BigDecimal.valueOf(count)
  38.       .multiply(
  39.         BigDecimal.valueOf(fsmConfig.getMinSupport())
  40.           .setScale(2, BigDecimal.ROUND_HALF_UP)
  41.       )
  42.       .setScale(0, BigDecimal.ROUND_UP)
  43.       .longValue();
  44.   }
  45. }