Coverage Report - org.apache.giraph.types.JavaWritablePair
 
Classes in this File Line Coverage Branch Coverage Complexity
JavaWritablePair
0%
0/36
0%
0/8
1.714
 
 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.types;
 19  
 
 20  
 import com.google.common.base.MoreObjects;
 21  
 import org.apache.hadoop.io.BooleanWritable;
 22  
 import org.apache.hadoop.io.ByteWritable;
 23  
 import org.apache.hadoop.io.DoubleWritable;
 24  
 import org.apache.hadoop.io.FloatWritable;
 25  
 import org.apache.hadoop.io.IntWritable;
 26  
 import org.apache.hadoop.io.LongWritable;
 27  
 import org.apache.hadoop.io.Writable;
 28  
 
 29  
 import com.google.common.base.Objects;
 30  
 
 31  
 /**
 32  
  * Holder for java and writable class pair.
 33  
  *
 34  
  * @param <W> writable class type
 35  
  * @param <J> java class type
 36  
  */
 37  
 public class JavaWritablePair<W extends Writable, J> {
 38  
   /** Boolean,BooleanWritable */
 39  
   public static final JavaWritablePair<BooleanWritable, Boolean>
 40  0
   BOOLEAN_BOOLEAN_WRITABLE = create(BooleanWritable.class, Boolean.class);
 41  
   /** Byte,ByteWritable */
 42  
   public static final JavaWritablePair<ByteWritable, Byte>
 43  0
   BYTE_BYTE_WRITABLE = create(ByteWritable.class, Byte.class);
 44  
   /** Byte,IntWritable */
 45  
   public static final JavaWritablePair<IntWritable, Byte>
 46  0
   BYTE_INT_WRITABLE = create(IntWritable.class, Byte.class);
 47  
   /** Byte,LongWritable */
 48  
   public static final JavaWritablePair<LongWritable, Byte>
 49  0
   BYTE_LONG_WRITABLE = create(LongWritable.class, Byte.class);
 50  
   /** Double,FloatWritable */
 51  
   public static final JavaWritablePair<FloatWritable, Double>
 52  0
   DOUBLE_FLOAT_WRITABLE = create(FloatWritable.class, Double.class);
 53  
   /** Double,DoubleWritable */
 54  
   public static final JavaWritablePair<DoubleWritable, Double>
 55  0
   DOUBLE_DOUBLE_WRITABLE = create(DoubleWritable.class, Double.class);
 56  
   /** Float,FloatWritable */
 57  
   public static final JavaWritablePair<FloatWritable, Float>
 58  0
   FLOAT_FLOAT_WRITABLE = create(FloatWritable.class, Float.class);
 59  
   /** Float,DoubleWritable */
 60  
   public static final JavaWritablePair<DoubleWritable, Float>
 61  0
   FLOAT_DOUBLE_WRITABLE = create(DoubleWritable.class, Float.class);
 62  
   /** Integer,ByteWritable */
 63  
   public static final JavaWritablePair<ByteWritable, Integer>
 64  0
   INT_BYTE_WRITABLE = create(ByteWritable.class, Integer.class);
 65  
   /** Integer,IntWritable */
 66  
   public static final JavaWritablePair<IntWritable, Integer>
 67  0
   INT_INT_WRITABLE = create(IntWritable.class, Integer.class);
 68  
   /** Integer,LongWritable */
 69  
   public static final JavaWritablePair<LongWritable, Integer>
 70  0
   INT_LONG_WRITABLE = create(LongWritable.class, Integer.class);
 71  
   /** Long,ByteWritable */
 72  
   public static final JavaWritablePair<ByteWritable, Long>
 73  0
   LONG_BYTE_WRITABLE = create(ByteWritable.class, Long.class);
 74  
   /** Long,IntWritable */
 75  
   public static final JavaWritablePair<IntWritable, Long>
 76  0
   LONG_INT_WRITABLE = create(IntWritable.class, Long.class);
 77  
   /** Long,LongWritable */
 78  
   public static final JavaWritablePair<LongWritable, Long>
 79  0
   LONG_LONG_WRITABLE = create(LongWritable.class, Long.class);
 80  
   /** Short,ByteWritable */
 81  
   public static final JavaWritablePair<ByteWritable, Short>
 82  0
   SHORT_BYTE_WRITABLE = create(ByteWritable.class, Short.class);
 83  
   /** Short,IntWritable */
 84  
   public static final JavaWritablePair<IntWritable, Short>
 85  0
   SHORT_INT_WRITABLE = create(IntWritable.class, Short.class);
 86  
   /** Short,LongWritable */
 87  
   public static final JavaWritablePair<LongWritable, Short>
 88  0
   SHORT_LONG_WRITABLE = create(LongWritable.class, Short.class);
 89  
 
 90  
   /** java class */
 91  
   private final Class<J> javaClass;
 92  
   /** writable class */
 93  
   private final Class<W> writableClass;
 94  
 
 95  
   /**
 96  
    * Constructor
 97  
    *
 98  
    * @param javaClass java class
 99  
    * @param writableClass writable class
 100  
    */
 101  0
   private JavaWritablePair(Class<W> writableClass, Class<J> javaClass) {
 102  0
     this.javaClass = javaClass;
 103  0
     this.writableClass = writableClass;
 104  0
   }
 105  
 
 106  
   /**
 107  
    * Create holder for classes
 108  
    *
 109  
    * @param writableClass writable class
 110  
    * @param javaClass java class
 111  
    * @param <W> writable class type
 112  
    * @param <J> java class type
 113  
    * @return JavaAndWritableClasses
 114  
    */
 115  
   public static <W extends Writable, J> JavaWritablePair<W, J> create(
 116  
       Class<W> writableClass, Class<J> javaClass) {
 117  0
     return new JavaWritablePair<W, J>(writableClass, javaClass);
 118  
   }
 119  
 
 120  
   @Override
 121  
   public boolean equals(Object obj) {
 122  0
     if (this == obj) {
 123  0
       return true;
 124  
     }
 125  0
     if (obj instanceof JavaWritablePair) {
 126  0
       JavaWritablePair other = (JavaWritablePair) obj;
 127  0
       return Objects.equal(javaClass, other.javaClass) &&
 128  0
           Objects.equal(writableClass, other.writableClass);
 129  
     }
 130  0
     return false;
 131  
   }
 132  
 
 133  
   @Override
 134  
   public int hashCode() {
 135  0
     return Objects.hashCode(javaClass, writableClass);
 136  
   }
 137  
 
 138  
   @Override
 139  
   public String toString() {
 140  0
     return MoreObjects.toStringHelper(this)
 141  0
         .add("javaClass", javaClass.getSimpleName())
 142  0
         .add("writableClass", writableClass.getSimpleName())
 143  0
         .toString();
 144  
   }
 145  
 
 146  
   public Class<J> getJavaClass() {
 147  0
     return javaClass;
 148  
   }
 149  
 
 150  
   public Class<W> getWritableClass() {
 151  0
     return writableClass;
 152  
   }
 153  
 }