EMlab-generation Documentation  1.0
Documentation of the EMLab-Generation model.
LabeledEdgePipe.java
1 /*******************************************************************************
2  * Copyright 2012 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  ******************************************************************************/
16 package emlab.gen.repository;
17 
18 import java.util.NoSuchElementException;
19 
20 import com.tinkerpop.blueprints.pgm.Edge;
21 import com.tinkerpop.blueprints.pgm.Vertex;
22 import com.tinkerpop.pipes.AbstractPipe;
23 import com.tinkerpop.pipes.Pipe;
24 import com.tinkerpop.gremlin.pipes.transform.BothEdgesPipe;
25 import com.tinkerpop.gremlin.pipes.transform.BothVerticesPipe;
26 import com.tinkerpop.gremlin.pipes.transform.InEdgesPipe;
27 import com.tinkerpop.gremlin.pipes.transform.InVertexPipe;
28 import com.tinkerpop.gremlin.pipes.transform.OutEdgesPipe;
29 import com.tinkerpop.gremlin.pipes.transform.OutVertexPipe;
30 import com.tinkerpop.pipes.util.Pipeline;
31 
32 public class LabeledEdgePipe extends AbstractPipe<Vertex, Vertex> implements Pipe<Vertex, Vertex> {
33 
34  public enum Step {
35  OUT_IN, IN_OUT, BOTH_BOTH
36  }
37 
38  Pipe<Vertex, Vertex> pipe;
39 
40  public LabeledEdgePipe(final String label, Step step) {
41  super();
42  Pipe<Vertex, Edge> edges = null;
43  Pipe<Edge, Vertex> vertices = null;
44  switch (step) {
45  case OUT_IN:
46 // edges = new VertexEdgePipe(VertexEdgePipe.Step.OUT_EDGES);
47  edges = new OutEdgesPipe(label);
48 // vertices = new EdgeVertexPipe(EdgeVertexPipe.Step.IN_VERTEX);
49  vertices = new InVertexPipe();
50  break;
51  case IN_OUT:
52 // edges = new VertexEdgePipe(VertexEdgePipe.Step.IN_EDGES);
53  edges = new InEdgesPipe(label);
54 // vertices = new EdgeVertexPipe(EdgeVertexPipe.Step.OUT_VERTEX);
55  vertices = new OutVertexPipe();
56  break;
57  case BOTH_BOTH:
58 // edges = new VertexEdgePipe(VertexEdgePipe.Step.BOTH_EDGES);
59  edges = new BothEdgesPipe(label);
60 // vertices = new EdgeVertexPipe(EdgeVertexPipe.Step.BOTH_VERTICES);
61  vertices = new BothVerticesPipe();
62  break;
63  default:
64  break;
65  }
66  pipe = new Pipeline<Vertex, Vertex>(edges, vertices);
67  }
68 
69  @Override
70  protected Vertex processNextStart() throws NoSuchElementException {
71  pipe.setStarts(this.starts);
72  return pipe.next();
73  }
74 
75 }