Coverage Report - org.apache.giraph.reducers.impl.MaxReduce
 
Classes in this File Line Coverage Branch Coverage Complexity
MaxReduce
0%
0/17
0%
0/2
0
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *     http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 package org.apache.giraph.reducers.impl;
 19  
 
 20  
 import java.io.DataInput;
 21  
 import java.io.DataOutput;
 22  
 import java.io.IOException;
 23  
 
 24  
 import org.apache.giraph.reducers.ReduceSameTypeOperation;
 25  
 import org.apache.giraph.types.ops.DoubleTypeOps;
 26  
 import org.apache.giraph.types.ops.IntTypeOps;
 27  
 import org.apache.giraph.types.ops.LongTypeOps;
 28  
 import org.apache.giraph.types.ops.NumericTypeOps;
 29  
 import org.apache.giraph.types.ops.TypeOpsUtils;
 30  
 import org.apache.hadoop.io.DoubleWritable;
 31  
 import org.apache.hadoop.io.IntWritable;
 32  
 import org.apache.hadoop.io.LongWritable;
 33  
 import org.apache.hadoop.io.WritableComparable;
 34  
 
 35  
 /**
 36  
  * Reducer for calculating max of values
 37  
  * @param <T> Value type
 38  
  */
 39  0
 public class MaxReduce<T extends WritableComparable>
 40  
     extends ReduceSameTypeOperation<T> {
 41  
   /** DoubleWritable specialization */
 42  0
   public static final MaxReduce<DoubleWritable> DOUBLE =
 43  
       new MaxReduce<>(DoubleTypeOps.INSTANCE);
 44  
   /** LongWritable specialization */
 45  0
   public static final MaxReduce<LongWritable> LONG =
 46  
       new MaxReduce<>(LongTypeOps.INSTANCE);
 47  
   /** IntWritable specialization */
 48  0
   public static final MaxReduce<IntWritable> INT =
 49  
       new MaxReduce<>(IntTypeOps.INSTANCE);
 50  
 
 51  
   /** Value type operations */
 52  
   private NumericTypeOps<T> typeOps;
 53  
 
 54  
   /** Constructor used for deserialization only */
 55  0
   public MaxReduce() {
 56  0
   }
 57  
 
 58  
   /**
 59  
    * Constructor
 60  
    * @param typeOps Value type operations
 61  
    */
 62  0
   public MaxReduce(NumericTypeOps<T> typeOps) {
 63  0
     this.typeOps = typeOps;
 64  0
   }
 65  
 
 66  
   @Override
 67  
   public T createInitialValue() {
 68  0
     return typeOps.createMinNegativeValue();
 69  
   }
 70  
 
 71  
   @Override
 72  
   public T reduce(T curValue, T valueToReduce) {
 73  0
     if (curValue.compareTo(valueToReduce) < 0) {
 74  0
       typeOps.set(curValue, valueToReduce);
 75  
     }
 76  0
     return curValue;
 77  
   }
 78  
 
 79  
   @Override
 80  
   public void write(DataOutput out) throws IOException {
 81  0
     TypeOpsUtils.writeTypeOps(typeOps, out);
 82  0
   }
 83  
 
 84  
   @Override
 85  
   public void readFields(DataInput in) throws IOException {
 86  0
     typeOps = TypeOpsUtils.readTypeOps(in);
 87  0
   }
 88  
 }