Preconditions.checkNotNull(value); VertexProperty.Cardinality card = getPropertyKeyCardinality(type.name()); tv.property(card, type.name(), value, T.id, relation.relationId); } else { assert type.isEdgeLabel(); te = (TinkerEdge)outV.addEdge(type.name(), tv, T.id, relation.relationId); } else if (relation.direction.equals(Direction.OUT)) { te = (TinkerEdge)tv.addEdge(type.name(), inV, T.id, relation.relationId); } else { throw new RuntimeException("Direction.BOTH is not supported"); log.trace("Vertex {} has unknown lifecycle state", vertexId); return null; } else if (!tv.edges(Direction.BOTH).hasNext() && !tv.properties().hasNext()) { log.trace("Vertex {} has no relations", vertexId); return null;
@Override public Vertex addVertex(final Object... keyValues) { ElementHelper.legalPropertyKeyValueArray(keyValues); Object idValue = vertexIdManager.convert(ElementHelper.getIdValue(keyValues).orElse(null)); final String label = ElementHelper.getLabelValue(keyValues).orElse(Vertex.DEFAULT_LABEL); if (null != idValue) { if (this.vertices.containsKey(idValue)) throw Exceptions.vertexWithIdAlreadyExists(idValue); } else { idValue = vertexIdManager.getNextId(this); } final Vertex vertex = new TinkerVertex(idValue, label, this); this.vertices.put(vertex.id(), vertex); ElementHelper.attachProperties(vertex, VertexProperty.Cardinality.list, keyValues); return vertex; }
@Override public Edge addEdge(final String label, final Vertex vertex, final Object... keyValues) { if (null == vertex) throw Graph.Exceptions.argumentCanNotBeNull("vertex"); if (this.removed) throw elementAlreadyRemoved(Vertex.class, this.id); return TinkerHelper.addEdge(this.graph, this, (TinkerVertex) vertex, label, keyValues); }
@Override public void remove() { final List<Edge> edges = new ArrayList<>(); this.edges(Direction.BOTH).forEachRemaining(edges::add); edges.stream().filter(edge -> !((TinkerEdge) edge).removed).forEach(Edge::remove); this.properties = null; TinkerHelper.removeElementIndex(this); this.graph.vertices.remove(this.id); this.removed = true; }
@Override public void remove() { if (null != this.vertex.properties && this.vertex.properties.containsKey(this.key)) { this.vertex.properties.get(this.key).remove(this); if (this.vertex.properties.get(this.key).size() == 0) { this.vertex.properties.remove(this.key); TinkerHelper.removeIndex(this.vertex, this.key, this.value); } final AtomicBoolean delete = new AtomicBoolean(true); this.vertex.properties(this.key).forEachRemaining(property -> { if (property.value().equals(this.value)) delete.set(false); }); if (delete.get()) TinkerHelper.removeIndex(this.vertex, this.key, this.value); this.properties = null; this.removed = true; } }
public static void removeElementIndex(final TinkerVertex vertex) { final TinkerGraph graph = (TinkerGraph) vertex.graph(); if (graph.vertexIndex != null) graph.vertexIndex.removeElement(vertex); }
+ ". Mixing specialized and generic elements is not (yet) supported"); return super.addEdge(label, vertex, keyValues);
@Override public Iterator<Vertex> vertices(final Direction direction, final String... edgeLabels) { return TinkerHelper.inComputerMode(this.graph) ? direction.equals(Direction.BOTH) ? IteratorUtils.concat( IteratorUtils.map(this.edges(Direction.OUT, edgeLabels), Edge::inVertex), IteratorUtils.map(this.edges(Direction.IN, edgeLabels), Edge::outVertex)) : IteratorUtils.map(this.edges(direction, edgeLabels), edge -> edge.vertices(direction.opposite()).next()) : (Iterator) TinkerHelper.getVertices(this, direction, edgeLabels); }
@Override public void remove() { if (null != this.vertex.properties && this.vertex.properties.containsKey(this.key)) { this.vertex.properties.get(this.key).remove(this); if (this.vertex.properties.get(this.key).size() == 0) { this.vertex.properties.remove(this.key); TinkerHelper.removeIndex(this.vertex, this.key, this.value); } final AtomicBoolean delete = new AtomicBoolean(true); this.vertex.properties(this.key).forEachRemaining(property -> { if (property.value().equals(this.value)) delete.set(false); }); if (delete.get()) TinkerHelper.removeIndex(this.vertex, this.key, this.value); this.properties = null; this.removed = true; } }
public static void autoUpdateIndex(final TinkerVertex vertex, final String key, final Object newValue, final Object oldValue) { final TinkerGraph graph = (TinkerGraph) vertex.graph(); if (graph.vertexIndex != null) graph.vertexIndex.autoUpdate(key, newValue, oldValue, vertex); }
Preconditions.checkNotNull(value); VertexProperty.Cardinality card = getPropertyKeyCardinality(type.name()); tv.property(card, type.name(), value, T.id, relation.relationId); } else { assert type.isEdgeLabel(); if (tv.equals(adjacentVertex) && isLoopAdded(tv, type.name())) { continue; te = (TinkerEdge)adjacentVertex.addEdge(type.name(), tv, T.id, relation.relationId); } else if (relation.direction.equals(Direction.OUT)) { te = (TinkerEdge)tv.addEdge(type.name(), adjacentVertex, T.id, relation.relationId); } else { throw new RuntimeException("Direction.BOTH is not supported"); if (!tv.edges(Direction.BOTH).hasNext() && !tv.properties().hasNext()) { log.trace("Vertex {} has no relations", vertexId); return null;
@Override public void remove() { final List<Edge> edges = new ArrayList<>(); this.edges(Direction.BOTH).forEachRemaining(edges::add); edges.stream().filter(edge -> !((TinkerEdge) edge).removed).forEach(Edge::remove); this.properties = null; TinkerHelper.removeElementIndex(this); this.graph.vertices.remove(this.id); this.removed = true; }
@Override public void remove() { if (null != this.vertex.properties && this.vertex.properties.containsKey(this.key)) { this.vertex.properties.get(this.key).remove(this); if (this.vertex.properties.get(this.key).size() == 0) { this.vertex.properties.remove(this.key); TinkerHelper.removeIndex(this.vertex, this.key, this.value); } final AtomicBoolean delete = new AtomicBoolean(true); this.vertex.properties(this.key).forEachRemaining(property -> { if (property.value().equals(this.value)) delete.set(false); }); if (delete.get()) TinkerHelper.removeIndex(this.vertex, this.key, this.value); this.properties = null; this.removed = true; } }
public static void removeIndex(final TinkerVertex vertex, final String key, final Object value) { final TinkerGraph graph = (TinkerGraph) vertex.graph(); if (graph.vertexIndex != null) graph.vertexIndex.remove(key, value, vertex); }
@Override public <V> VertexProperty<V> property(final VertexProperty.Cardinality cardinality, final String key, final V value, final Object... keyValues) { if (this.removed) throw elementAlreadyRemoved(Vertex.class, id); ElementHelper.legalPropertyKeyValueArray(keyValues); ElementHelper.validateProperty(key, value); final Optional<Object> optionalId = ElementHelper.getIdValue(keyValues); final Optional<VertexProperty<V>> optionalVertexProperty = ElementHelper.stageVertexProperty(this, cardinality, key, value, keyValues); if (optionalVertexProperty.isPresent()) return optionalVertexProperty.get(); if (TinkerHelper.inComputerMode(this.graph)) { final VertexProperty<V> vertexProperty = (VertexProperty<V>) this.graph.graphComputerView.addProperty(this, key, value); ElementHelper.attachProperties(vertexProperty, keyValues); return vertexProperty; } else { final Object idValue = optionalId.isPresent() ? graph.vertexPropertyIdManager.convert(optionalId.get()) : graph.vertexPropertyIdManager.getNextId(graph); final VertexProperty<V> vertexProperty = new TinkerVertexProperty<V>(idValue, this, key, value); if (null == this.properties) this.properties = new HashMap<>(); final List<VertexProperty> list = this.properties.getOrDefault(key, new ArrayList<>()); list.add(vertexProperty); this.properties.put(key, list); TinkerHelper.autoUpdateIndex(this, key, value, null); ElementHelper.attachProperties(vertexProperty, keyValues); return vertexProperty; } }
@Override public Vertex addVertex(final Object... keyValues) { ElementHelper.legalPropertyKeyValueArray(keyValues); Object idValue = vertexIdManager.convert(ElementHelper.getIdValue(keyValues).orElse(null)); final String label = ElementHelper.getLabelValue(keyValues).orElse(Vertex.DEFAULT_LABEL); if (null != idValue) { if (this.vertices.containsKey(idValue)) throw Exceptions.vertexWithIdAlreadyExists(idValue); } else { idValue = vertexIdManager.getNextId(this); } final Vertex vertex = new TinkerVertex(idValue, label, this); this.vertices.put(vertex.id(), vertex); ElementHelper.attachProperties(vertex, VertexProperty.Cardinality.list, keyValues); return vertex; }
Preconditions.checkNotNull(value); VertexProperty.Cardinality card = getPropertyKeyCardinality(type.name()); tv.property(card, type.name(), value, T.id, relation.relationId); } else { assert type.isEdgeLabel(); if (tv.equals(adjacentVertex) && isLoopAdded(tv, type.name())) { continue; te = (TinkerEdge)adjacentVertex.addEdge(type.name(), tv, T.id, relation.relationId); } else if (relation.direction.equals(Direction.OUT)) { te = (TinkerEdge)tv.addEdge(type.name(), adjacentVertex, T.id, relation.relationId); } else { throw new RuntimeException("Direction.BOTH is not supported"); if (!tv.edges(Direction.BOTH).hasNext() && !tv.properties().hasNext()) { log.trace("Vertex {} has no relations", vertexId); return null;
@Override public void remove() { final List<Edge> edges = new ArrayList<>(); this.edges(Direction.BOTH).forEachRemaining(edges::add); edges.stream().filter(edge -> !((TinkerEdge) edge).removed).forEach(Edge::remove); this.properties = null; TinkerHelper.removeElementIndex(this); this.graph.vertices.remove(this.id); this.removed = true; }
@Override public Set<String> keys() { if (null == this.properties) return Collections.emptySet(); return TinkerHelper.inComputerMode((TinkerGraph) graph()) ? Vertex.super.keys() : this.properties.keySet(); }
@Override public Edge addEdge(final String label, final Vertex vertex, final Object... keyValues) { if (null == vertex) throw Graph.Exceptions.argumentCanNotBeNull("vertex"); if (this.removed) throw elementAlreadyRemoved(Vertex.class, this.id); return TinkerHelper.addEdge(this.graph, this, (TinkerVertex) vertex, label, keyValues); }