Coverage Report - org.apache.giraph.function.ObjectHolder
 
Classes in this File Line Coverage Branch Coverage Complexity
ObjectHolder
0%
0/9
N/A
1
 
 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.function;
 19  
 
 20  
 /**
 21  
  * Default object holder, intermediary between producers and consumers.
 22  
  *
 23  
  * Holds value in memory, so can be used only when producer and consumer
 24  
  * are in the same context.
 25  
  *
 26  
  * Useful when value is set on the master, and later read in block logic
 27  
  * (RepeatUntilBlock), or in a different Piece, either on worker or master.
 28  
  * If it is read within the same piece - just use local field.
 29  
  *
 30  
  * @param <T> Type of object to hold.
 31  
  */
 32  
 public class ObjectHolder<T> implements Supplier<T>, Consumer<T> {
 33  
   /** value */
 34  
   private T value;
 35  
 
 36  
   /**
 37  
    * Constructor
 38  
    * @param value initial value
 39  
    */
 40  0
   public ObjectHolder(T value) {
 41  0
     this.value = value;
 42  0
   }
 43  
 
 44  
   /** Constructor */
 45  0
   public ObjectHolder() {
 46  0
   }
 47  
 
 48  
   @Override
 49  
   public T get() {
 50  0
     return value;
 51  
   }
 52  
 
 53  
   @Override
 54  
   public void apply(T value) {
 55  0
     this.value = value;
 56  0
   }
 57  
 
 58  
   @Override
 59  
   public String toString() {
 60  0
     return getClass() + " [value=" + value + "]";
 61  
   }
 62  
 }