Coverage Report - org.apache.giraph.io.formats.JsonLongDoubleFloatDoubleVertexOutputFormat
 
Classes in this File Line Coverage Branch Coverage Complexity
JsonLongDoubleFloatDoubleVertexOutputFormat
0%
0/2
N/A
2.5
JsonLongDoubleFloatDoubleVertexOutputFormat$1
N/A
N/A
2.5
JsonLongDoubleFloatDoubleVertexOutputFormat$JsonLongDoubleFloatDoubleVertexWriter
0%
0/16
0%
0/2
2.5
 
 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.io.formats;
 20  
 
 21  
 import org.apache.giraph.edge.Edge;
 22  
 import org.apache.giraph.graph.Vertex;
 23  
 import org.apache.hadoop.io.DoubleWritable;
 24  
 import org.apache.hadoop.io.FloatWritable;
 25  
 import org.apache.hadoop.io.LongWritable;
 26  
 import org.apache.hadoop.io.Text;
 27  
 import org.apache.hadoop.mapreduce.TaskAttemptContext;
 28  
 import org.json.JSONArray;
 29  
 import org.json.JSONException;
 30  
 
 31  
 import java.io.IOException;
 32  
 
 33  
 /**
 34  
  * VertexOutputFormat that supports JSON encoded vertices featuring
 35  
  * <code>double</code> values and <code>float</code> out-edge weights
 36  
  */
 37  0
 public class JsonLongDoubleFloatDoubleVertexOutputFormat extends
 38  
   TextVertexOutputFormat<LongWritable, DoubleWritable,
 39  
   FloatWritable> {
 40  
 
 41  
   @Override
 42  
   public TextVertexWriter createVertexWriter(
 43  
       TaskAttemptContext context) {
 44  0
     return new JsonLongDoubleFloatDoubleVertexWriter();
 45  
   }
 46  
 
 47  
  /**
 48  
   * VertexWriter that supports vertices with <code>double</code>
 49  
   * values and <code>float</code> out-edge weights.
 50  
   */
 51  0
   private class JsonLongDoubleFloatDoubleVertexWriter extends
 52  
     TextVertexWriterToEachLine {
 53  
     @Override
 54  
     public Text convertVertexToLine(
 55  
       Vertex<LongWritable, DoubleWritable, FloatWritable> vertex
 56  
     ) throws IOException {
 57  0
       JSONArray jsonVertex = new JSONArray();
 58  
       try {
 59  0
         jsonVertex.put(vertex.getId().get());
 60  0
         jsonVertex.put(vertex.getValue().get());
 61  0
         JSONArray jsonEdgeArray = new JSONArray();
 62  0
         for (Edge<LongWritable, FloatWritable> edge : vertex.getEdges()) {
 63  0
           JSONArray jsonEdge = new JSONArray();
 64  0
           jsonEdge.put(edge.getTargetVertexId().get());
 65  0
           jsonEdge.put(edge.getValue().get());
 66  0
           jsonEdgeArray.put(jsonEdge);
 67  0
         }
 68  0
         jsonVertex.put(jsonEdgeArray);
 69  0
       } catch (JSONException e) {
 70  0
         throw new IllegalArgumentException(
 71  
           "writeVertex: Couldn't write vertex " + vertex);
 72  0
       }
 73  0
       return new Text(jsonVertex.toString());
 74  
     }
 75  
   }
 76  
 }