Coverage Report - org.apache.giraph.examples.LongDoubleDoubleTextInputFormat
 
Classes in this File Line Coverage Branch Coverage Complexity
LongDoubleDoubleTextInputFormat
0%
0/5
N/A
1.2
LongDoubleDoubleTextInputFormat$LongDoubleDoubleDoubleVertexReader
0%
0/15
0%
0/2
1.2
 
 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.examples;
 20  
 
 21  
 import org.apache.giraph.conf.ImmutableClassesGiraphConfigurable;
 22  
 import org.apache.giraph.conf.ImmutableClassesGiraphConfiguration;
 23  
 import org.apache.giraph.edge.Edge;
 24  
 import org.apache.giraph.edge.EdgeFactory;
 25  
 import org.apache.giraph.graph.Vertex;
 26  
 import org.apache.giraph.io.formats.TextVertexInputFormat;
 27  
 import org.apache.hadoop.io.DoubleWritable;
 28  
 import org.apache.hadoop.io.LongWritable;
 29  
 import org.apache.hadoop.mapreduce.InputSplit;
 30  
 import org.apache.hadoop.mapreduce.TaskAttemptContext;
 31  
 
 32  
 import com.google.common.collect.Lists;
 33  
 
 34  
 import java.io.IOException;
 35  
 import java.util.List;
 36  
 import java.util.regex.Pattern;
 37  
 
 38  
 /**
 39  
  * Simple text-based {@link org.apache.giraph.io.VertexInputFormat} for
 40  
  * unweighted graphs with long ids. Each line consists of: vertex neighbor1
 41  
  * neighbor2 ...
 42  
  */
 43  0
 public class LongDoubleDoubleTextInputFormat
 44  
     extends TextVertexInputFormat<LongWritable, DoubleWritable,
 45  
     DoubleWritable>
 46  
     implements ImmutableClassesGiraphConfigurable<LongWritable, DoubleWritable,
 47  
     DoubleWritable> {
 48  
 
 49  
   /** Configuration. */
 50  
   private ImmutableClassesGiraphConfiguration<LongWritable, DoubleWritable,
 51  
       DoubleWritable> conf;
 52  
 
 53  
   @Override
 54  
   public TextVertexReader createVertexReader(InputSplit split,
 55  
       TaskAttemptContext context)
 56  
     throws IOException {
 57  0
     return new LongDoubleDoubleDoubleVertexReader();
 58  
   }
 59  
 
 60  
   @Override
 61  
   public void setConf(ImmutableClassesGiraphConfiguration<LongWritable,
 62  
       DoubleWritable, DoubleWritable> configuration) {
 63  0
     this.conf = configuration;
 64  0
   }
 65  
 
 66  
   @Override
 67  
   public ImmutableClassesGiraphConfiguration<LongWritable, DoubleWritable,
 68  
       DoubleWritable> getConf() {
 69  0
     return conf;
 70  
   }
 71  
 
 72  
   /**
 73  
    * Vertex reader associated with
 74  
    * {@link LongDoubleDoubleTextInputFormat}.
 75  
    */
 76  0
   public class LongDoubleDoubleDoubleVertexReader extends
 77  
     TextVertexInputFormat<LongWritable, DoubleWritable,
 78  
         DoubleWritable>.TextVertexReader {
 79  
     /** Separator of the vertex and neighbors */
 80  0
     private final Pattern separator = Pattern.compile("[\t ]");
 81  
 
 82  
     @Override
 83  
     public Vertex<LongWritable, DoubleWritable, DoubleWritable>
 84  
     getCurrentVertex() throws IOException, InterruptedException {
 85  
       Vertex<LongWritable, DoubleWritable, DoubleWritable>
 86  0
         vertex = conf.createVertex();
 87  
 
 88  0
       String[] tokens =
 89  0
           separator.split(getRecordReader().getCurrentValue().toString());
 90  0
       List<Edge<LongWritable, DoubleWritable>> edges =
 91  0
           Lists.newArrayListWithCapacity(tokens.length - 1);
 92  0
       float weight = 1.0f / (tokens.length - 1);
 93  0
       for (int n = 1; n < tokens.length; n++) {
 94  0
         edges.add(EdgeFactory.create(
 95  0
             new LongWritable(Long.parseLong(tokens[n])),
 96  
             new DoubleWritable(weight)));
 97  
       }
 98  
 
 99  0
       LongWritable vertexId = new LongWritable(Long.parseLong(tokens[0]));
 100  0
       vertex.initialize(vertexId, new DoubleWritable(), edges);
 101  
 
 102  0
       return vertex;
 103  
     }
 104  
 
 105  
     @Override
 106  
     public boolean nextVertex() throws IOException, InterruptedException {
 107  0
       return getRecordReader().nextKeyValue();
 108  
     }
 109  
   }
 110  
 }