Coverage Report - org.apache.giraph.combiner.SumMessageCombiner
 
Classes in this File Line Coverage Branch Coverage Complexity
SumMessageCombiner
0%
0/10
N/A
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.combiner;
 19  
 
 20  
 import org.apache.giraph.types.ops.DoubleTypeOps;
 21  
 import org.apache.giraph.types.ops.FloatTypeOps;
 22  
 import org.apache.giraph.types.ops.IntTypeOps;
 23  
 import org.apache.giraph.types.ops.LongTypeOps;
 24  
 import org.apache.giraph.types.ops.NumericTypeOps;
 25  
 import org.apache.hadoop.io.DoubleWritable;
 26  
 import org.apache.hadoop.io.FloatWritable;
 27  
 import org.apache.hadoop.io.IntWritable;
 28  
 import org.apache.hadoop.io.LongWritable;
 29  
 import org.apache.hadoop.io.Writable;
 30  
 import org.apache.hadoop.io.WritableComparable;
 31  
 
 32  
 /**
 33  
  * Message combiner which sums all messages.
 34  
  *
 35  
  * @param <M> Message type
 36  
  */
 37  
 public class SumMessageCombiner<M extends Writable>
 38  
   implements MessageCombiner<WritableComparable, M> {
 39  
   /** DoubleWritable specialization */
 40  0
   public static final SumMessageCombiner<DoubleWritable> DOUBLE =
 41  
       new SumMessageCombiner<>(DoubleTypeOps.INSTANCE);
 42  
   /** DoubleWritable specialization */
 43  0
   public static final SumMessageCombiner<FloatWritable> FLOAT =
 44  
       new SumMessageCombiner<>(FloatTypeOps.INSTANCE);
 45  
   /** LongWritable specialization */
 46  0
   public static final SumMessageCombiner<LongWritable> LONG =
 47  
       new SumMessageCombiner<>(LongTypeOps.INSTANCE);
 48  
   /** IntWritable specialization */
 49  0
   public static final SumMessageCombiner<IntWritable> INT =
 50  
       new SumMessageCombiner<>(IntTypeOps.INSTANCE);
 51  
 
 52  
   /** Value type operations */
 53  
   private final NumericTypeOps<M> typeOps;
 54  
 
 55  
   /**
 56  
    * Constructor
 57  
    * @param typeOps Value type operations
 58  
    */
 59  0
   public SumMessageCombiner(NumericTypeOps<M> typeOps) {
 60  0
     this.typeOps = typeOps;
 61  0
   }
 62  
 
 63  
   @Override
 64  
   public void combine(
 65  
       WritableComparable vertexIndex, M originalMessage, M messageToCombine) {
 66  0
     typeOps.plusInto(originalMessage, messageToCombine);
 67  0
   }
 68  
 
 69  
   @Override
 70  
   public M createInitialMessage() {
 71  0
     return typeOps.createZero();
 72  
   }
 73  
 }