Coverage Report - org.apache.giraph.graph.Edge
 
Classes in this File Line Coverage Branch Coverage Complexity
Edge
72%
21/29
31%
7/22
2.3
 
 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  
 
 19  
 package org.apache.giraph.graph;
 20  
 
 21  
 import org.apache.hadoop.io.Writable;
 22  
 import org.apache.hadoop.io.WritableComparable;
 23  
 
 24  
 /**
 25  
  * A complete edge, the target vertex and the edge value.  Can only be one
 26  
  * edge with a destination vertex id per edge map.
 27  
  *
 28  
  * @param <I> Vertex index
 29  
  * @param <E> Edge value
 30  
  */
 31  14
 @SuppressWarnings("rawtypes")
 32  
 public class Edge<I extends WritableComparable, E extends Writable>
 33  
     implements Comparable<Edge<I, E>> {
 34  
   /** Target vertex id */
 35  5227
   private I targetVertexId = null;
 36  
   /** Edge value */
 37  5227
   private E value = null;
 38  
 
 39  
   /**
 40  
    * Constructor for reflection
 41  
    */
 42  10
   public Edge() { }
 43  
 
 44  
   /**
 45  
    * Create the edge with final values
 46  
    *
 47  
    * @param targetVertexId Desination vertex id.
 48  
    * @param value Value of the edge.
 49  
    */
 50  5222
   public Edge(I targetVertexId, E value) {
 51  5222
     this.targetVertexId = targetVertexId;
 52  5222
     this.value = value;
 53  5222
   }
 54  
 
 55  
   /**
 56  
    * Get the target vertex index of this edge
 57  
    *
 58  
    * @return Target vertex index of this edge
 59  
    */
 60  
   public I getTargetVertexId() {
 61  9056
     return targetVertexId;
 62  
   }
 63  
 
 64  
   /**
 65  
    * Get the edge value of the edge
 66  
    *
 67  
    * @return Edge value of this edge
 68  
    */
 69  
   public E getValue() {
 70  3319
     return value;
 71  
   }
 72  
 
 73  
   /**
 74  
    * Set the destination vertex index of this edge.
 75  
    *
 76  
    * @param targetVertexId new destination vertex
 77  
    */
 78  
   public void setTargetVertexId(I targetVertexId) {
 79  11
     this.targetVertexId = targetVertexId;
 80  11
   }
 81  
 
 82  
   /**
 83  
    * Set the value for this edge.
 84  
    *
 85  
    * @param value new edge value
 86  
    */
 87  
   public void setValue(E value) {
 88  11
     this.value = value;
 89  11
   }
 90  
 
 91  
   @Override
 92  
   public String toString() {
 93  0
     return "(TargetVertexId = " + targetVertexId + ", " +
 94  
         "value = " + value + ")";
 95  
   }
 96  
 
 97  
   @SuppressWarnings("unchecked")
 98  
   @Override
 99  
   public int compareTo(Edge<I, E> edge) {
 100  14
     return targetVertexId.compareTo(edge.getTargetVertexId());
 101  
   }
 102  
 
 103  
   @Override
 104  
   public boolean equals(Object o) {
 105  1011
     if (this == o) {
 106  0
       return true;
 107  
     }
 108  1011
     if (o == null || getClass() != o.getClass()) {
 109  0
       return false;
 110  
     }
 111  
 
 112  1011
     Edge edge = (Edge) o;
 113  
 
 114  1011
     if (targetVertexId != null ? !targetVertexId.equals(edge.targetVertexId) :
 115  
       edge.targetVertexId != null) {
 116  0
       return false;
 117  
     }
 118  1011
     if (value != null ? !value.equals(edge.value) : edge.value != null) {
 119  0
       return false;
 120  
     }
 121  
 
 122  1011
     return true;
 123  
   }
 124  
 
 125  
   @Override
 126  
   public int hashCode() {
 127  0
     int result = targetVertexId != null ? targetVertexId.hashCode() : 0;
 128  0
     result = 31 * result + (value != null ? value.hashCode() : 0);
 129  0
     return result;
 130  
   }
 131  
 }