Exemple #1
0
  public Iterable<Edge> getEdges(final Direction direction, final String... labels) {
    final List<List<Edge>> edgeLists = new ArrayList<List<Edge>>();

    if (direction.equals(OUT) || direction.equals(BOTH)) {
      if (null == labels || labels.length == 0) {
        for (final List<Edge> temp : this.outEdges.values()) {
          edgeLists.add(temp);
        }
      } else {
        for (final String label : labels) {
          final List<Edge> temp = this.outEdges.get(label);
          if (null != temp) edgeLists.add(temp);
        }
      }
    }

    if (direction.equals(IN) || direction.equals(BOTH)) {
      if (null == labels || labels.length == 0) {
        for (final List<Edge> temp : this.inEdges.values()) {
          edgeLists.add(temp);
        }
      } else {
        for (final String label : labels) {
          final List<Edge> temp = this.inEdges.get(label);
          if (null != temp) edgeLists.add(temp);
        }
      }
    }
    return new EdgeList(edgeLists);
  }
Exemple #2
0
 public Vertex getVertex(final Direction direction) {
   this.graph.autoStartTransaction();
   if (direction.equals(Direction.OUT))
     return new Neo4j2Vertex(((Relationship) this.rawElement).getStartNode(), this.graph);
   else if (direction.equals(Direction.IN))
     return new Neo4j2Vertex(((Relationship) this.rawElement).getEndNode(), this.graph);
   else throw ExceptionFactory.bothIsNotSupported();
 }
Exemple #3
0
 public Set<String> getEdgeLabels(final Direction direction) {
   if (direction.equals(Direction.OUT)) return this.outEdges.keySet();
   else if (direction.equals(Direction.IN)) return this.inEdges.keySet();
   else {
     final Set<String> labels = new HashSet<String>();
     labels.addAll(this.outEdges.keySet());
     labels.addAll(this.inEdges.keySet());
     return labels;
   }
 }
Exemple #4
0
  public void addEdges(final Direction direction, final FaunusVertex vertex) {
    if (direction.equals(OUT) || direction.equals(BOTH)) {
      for (final String label : vertex.getEdgeLabels(OUT)) {
        this.addEdges(OUT, label, (List) vertex.getEdges(OUT, label));
      }
    }

    if (direction.equals(IN) || direction.equals(BOTH)) {
      for (final String label : vertex.getEdgeLabels(IN)) {
        this.addEdges(IN, label, (List) vertex.getEdges(IN, label));
      }
    }
  }
Exemple #5
0
  private void addEdges(
      final Direction direction, final String label, final List<FaunusEdge> edges) {
    List<Edge> list;
    if (direction.equals(OUT)) list = this.outEdges.get(label);
    else if (direction.equals(IN)) list = this.inEdges.get(label);
    else throw ExceptionFactory.bothIsNotSupported();

    if (null == list) {
      list = new ArrayList<Edge>();
      if (direction.equals(OUT)) this.outEdges.put(label, list);
      else this.inEdges.put(label, list);
    }
    list.addAll(edges);
  }
 public Object processEdge(
     final Range annotation,
     final Method method,
     final Object[] arguments,
     final FramedGraph framedGraph,
     final Edge edge,
     final Direction direction) {
   return framedGraph.frame(edge.getVertex(direction.opposite()), method.getReturnType());
 }
Exemple #7
0
  public void removeEdges(
      final Tokens.Action action, final Direction direction, final String... labels) {
    if (action.equals(Tokens.Action.KEEP)) {
      final Set<String> keep = new HashSet<String>(Arrays.asList(labels));
      if (direction.equals(BOTH) || direction.equals(OUT)) {
        if (labels.length > 0) {
          for (final String label : new ArrayList<String>(this.outEdges.keySet())) {
            if (!keep.contains(label)) this.outEdges.remove(label);
          }
        }
      }

      if (direction.equals(BOTH) || direction.equals(IN)) {
        if (labels.length > 0) {
          for (final String label : new ArrayList<String>(this.inEdges.keySet())) {
            if (!keep.contains(label)) this.inEdges.remove(label);
          }
        }
      }
    } else {
      if (direction.equals(BOTH) || direction.equals(OUT)) {
        if (labels.length == 0) {
          this.outEdges.clear();
        } else {
          for (final String label : labels) {
            this.outEdges.remove(label);
          }
        }
      }

      if (direction.equals(BOTH) || direction.equals(IN)) {
        if (labels.length == 0) {
          this.inEdges.clear();
        } else {
          for (final String label : labels) {
            this.inEdges.remove(label);
          }
        }
      }
    }
  }
Exemple #8
0
 public static Map<String, List<FaunusEdge>> readFields(
     final DataInput in, final Direction idToRead, final long otherId) throws IOException {
   final Map<String, List<FaunusEdge>> edges = new HashMap<String, List<FaunusEdge>>();
   int edgeTypes = in.readShort();
   for (int i = 0; i < edgeTypes; i++) {
     final String label = in.readUTF();
     final int size = WritableUtils.readVInt(in);
     final List<FaunusEdge> temp = new ArrayList<FaunusEdge>(size);
     for (int j = 0; j < size; j++) {
       final FaunusEdge edge = new FaunusEdge();
       edge.readFieldsCompressed(in, idToRead);
       edge.setLabel(label);
       if (idToRead.equals(Direction.OUT)) edge.inVertex = otherId;
       else edge.outVertex = otherId;
       temp.add(edge);
     }
     edges.put(label, temp);
   }
   return edges;
 }
Exemple #9
0
 public Vertex getVertex(final Direction direction) {
   if (direction.equals(Direction.OUT)) return outVertex;
   else if (direction.equals(Direction.IN)) return inVertex;
   else throw Edge.Exceptions.bothIsNotSupported();
 }