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 network that looks like:29 * 1 530 * / \ / \ 631 * 0---2 3---432 *33 * where 6 is disconnected from the rest of the network.34 *35 * @param <I> Vertex id type36 * @param <V> Vertex value type37 * @param <E> Edge value type38 */39publicclass Small2GraphInit<I extends WritableComparable,
40 V extends Writable, E extends Writable>
41implements TestGraphModifier<I, V, E> {
42privatefinal Supplier<E> edgeSupplier;
4344publicSmall2GraphInit() {
45this(null);
46 }
4748publicSmall2GraphInit(Supplier<E> edgeSupplier) {
49this.edgeSupplier = edgeSupplier;
50 }
5152 @Override
53publicvoid modifyGraph(NumericTestGraph<I, V, E> graph) {
54 graph.addSymmetricEdge(0, 1, createEdgeValue());
55 graph.addSymmetricEdge(0, 2, createEdgeValue());
56 graph.addSymmetricEdge(1, 2, createEdgeValue());
57 graph.addSymmetricEdge(3, 4, createEdgeValue());
58 graph.addSymmetricEdge(3, 5, createEdgeValue());
59 graph.addSymmetricEdge(4, 5, createEdgeValue());
6061 graph.addVertex(6);
62 }
6364private E createEdgeValue() {
65return edgeSupplier != null ? edgeSupplier.get() : null;
66 }
67 }
68