1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing, software13 * 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 and16 * limitations under the License.17 */18package org.apache.giraph.block_app.test_setup.graphs;
1920import org.apache.giraph.block_app.test_setup.NumericTestGraph;
21import org.apache.giraph.block_app.test_setup.TestGraphModifier;
22import org.apache.giraph.function.Supplier;
23import org.apache.hadoop.io.Writable;
24import org.apache.hadoop.io.WritableComparable;
252627/**28 * Create a directed forest that looks like:29 *30 * 0 4 631 * / \ | / \32 * 1 2 5 7 833 * |34 * 335 *36 * Edges are directed from top to bottom.37 * Vertices with no edges are created.38 *39 * @param <I> Vertex id type40 * @param <V> Vertex value type41 * @param <E> Edge value type42 */43publicclass SmallDirectedForestGraphInit<I extends WritableComparable,
44 V extends Writable, E extends Writable>
45implements TestGraphModifier<I, V, E> {
4647privatefinal Supplier<E> edgeSupplier;
4849publicSmallDirectedForestGraphInit() {
50this(null);
51 }
5253publicSmallDirectedForestGraphInit(Supplier<E> edgeSupplier) {
54this.edgeSupplier = edgeSupplier;
55 }
5657 @Override
58publicvoid modifyGraph(NumericTestGraph<I, V, E> graph) {
59 graph.addEdge(0, 1, createEdgeValue());
60 graph.addEdge(0, 2, createEdgeValue());
61 graph.addEdge(2, 3, createEdgeValue());
62 graph.addEdge(4, 5, createEdgeValue());
63 graph.addEdge(6, 7, createEdgeValue());
64 graph.addEdge(6, 8, createEdgeValue());
6566 graph.addVertex(1);
67 graph.addVertex(3);
68 graph.addVertex(5);
69 graph.addVertex(7);
70 graph.addVertex(8);
71 }
7273private E createEdgeValue() {
74return edgeSupplier != null ? edgeSupplier.get() : null;
75 }
76 }