/** * Extracts the {@link Vertex} that is holding the specified object. * * @throws IllegalStateException if the object is not a graph element type */ public static Vertex getHostingVertex(final Object object) { Object obj = object; while (true) { if (obj instanceof Vertex) return (Vertex) obj; else if (obj instanceof Edge) return ((Edge) obj).outVertex(); else if (obj instanceof Property) obj = ((Property) obj).element(); else throw new IllegalStateException("The host of the object is unknown: " + obj.toString() + ':' + obj.getClass().getCanonicalName()); } } }
protected DetachedProperty(final Property<V> property) { this.key = property.key(); this.value = property.value(); this.element = DetachedFactory.detach(property.element(), false); }
@Override public Element element() { final Element element = this.property.element(); if (element instanceof Vertex) return new ComputerVertex((Vertex) element); else if (element instanceof Edge) return new ComputerEdge((Edge) element); else return new ComputerVertexProperty((VertexProperty) element); }
@Override public <O extends OutputShim> void write(final KryoShim<?, O> kryo, final O output, final Property property) { output.writeString(property.key()); kryo.writeClassAndObject(output, property.value()); kryo.writeClassAndObject(output, property.element().id()); output.writeString(property.element().label()); }
public static Optional<Property> getProperty(final Attachable<Property> attachableProperty, final Vertex hostVertex) { final Property baseProperty = attachableProperty.get(); final Element propertyElement = attachableProperty.get().element(); if (propertyElement instanceof Vertex) { return (Optional) Method.getVertexProperty((Attachable) attachableProperty, hostVertex); while (vertexPropertyIterator.hasNext()) { final VertexProperty vertexProperty = vertexPropertyIterator.next(); if (ElementHelper.areEqual(vertexProperty, baseProperty.element())) { final Property property = vertexProperty.property(baseProperty.key()); if (property.isPresent() && property.value().equals(baseProperty.value()))
public static void validatePropertyEquality(final Property originalProperty, final Property otherProperty) { assertEquals(originalProperty, otherProperty); assertEquals(otherProperty, originalProperty); if (originalProperty.isPresent()) { assertEquals(originalProperty.key(), otherProperty.key()); assertEquals(originalProperty.value(), otherProperty.value()); assertEquals(originalProperty.element(), otherProperty.element()); } }
public static Property createProperty(final Attachable<Property> attachableProperty, final Vertex hostVertex) { final Property baseProperty = attachableProperty.get(); final Element baseElement = baseProperty.element(); if (baseElement instanceof Vertex) { return Method.createVertexProperty((Attachable) attachableProperty, hostVertex); } else if (baseElement instanceof Edge) { final Iterator<Edge> edgeIterator = hostVertex.edges(Direction.OUT); if (edgeIterator.hasNext()) return edgeIterator.next().property(baseProperty.key(), baseProperty.value()); throw new IllegalStateException("Could not find edge to create the property on"); } else { // vertex property final Iterator<VertexProperty<Object>> vertexPropertyIterator = hostVertex.properties(((VertexProperty) baseElement).key()); while (vertexPropertyIterator.hasNext()) { final VertexProperty<Object> vp = vertexPropertyIterator.next(); if (ElementHelper.areEqual(vp, baseElement)) return vp.property(baseProperty.key(), baseProperty.value()); } throw new IllegalStateException("Could not find vertex property to create the attachable property on"); } } }
public static Optional<Property> getProperty(final Attachable<Property> attachableProperty, final Graph hostGraph) { final Property baseProperty = attachableProperty.get(); final Element propertyElement = attachableProperty.get().element(); if (propertyElement instanceof Vertex) { return (Optional) Method.getVertexProperty((Attachable) attachableProperty, hostGraph); while (vertexPropertyIterator.hasNext()) { final VertexProperty vertexProperty = vertexPropertyIterator.next(); if (ElementHelper.areEqual(vertexProperty, baseProperty.element())) { final Property property = vertexProperty.property(baseProperty.key()); if (property.isPresent() && property.value().equals(baseProperty.value()))
/** * A standard method for determining if two {@link org.apache.tinkerpop.gremlin.structure.Property} objects are equal. This method should be used by any * {@link Object#equals(Object)} implementation to ensure consistent behavior. * * @param a the first {@link org.apache.tinkerpop.gremlin.structure.Property} * @param b the second {@link org.apache.tinkerpop.gremlin.structure.Property} * @return true if equal and false otherwise */ public static boolean areEqual(final Property a, final Object b) { if (null == b || null == a) return false; if (a == b) return true; if (!(b instanceof Property)) return false; if (!a.isPresent() && !((Property) b).isPresent()) return true; if (!a.isPresent() && ((Property) b).isPresent() || a.isPresent() && !((Property) b).isPresent()) return false; return a.key().equals(((Property) b).key()) && a.value().equals(((Property) b).value()) && areEqual(a.element(), ((Property) b).element()); }
public static Property createProperty(final Attachable<Property> attachableProperty, final Graph hostGraph) { final Property baseProperty = attachableProperty.get(); final Element baseElement = baseProperty.element(); if (baseElement instanceof Vertex) { return Method.createVertexProperty((Attachable) attachableProperty, hostGraph); } else if (baseElement instanceof Edge) { final Iterator<Edge> edgeIterator = hostGraph.edges(baseElement.id()); if (edgeIterator.hasNext()) return edgeIterator.next().property(baseProperty.key(), baseProperty.value()); throw new IllegalStateException("Could not find edge to create the attachable property on"); } else { // vertex property final Iterator<Vertex> vertexIterator = hostGraph.vertices(((VertexProperty) baseElement).element().id()); if (vertexIterator.hasNext()) { final Vertex vertex = vertexIterator.next(); final Iterator<VertexProperty<Object>> vertexPropertyIterator = vertex.properties(((VertexProperty) baseElement).key()); while (vertexPropertyIterator.hasNext()) { final VertexProperty<Object> vp = vertexPropertyIterator.next(); if (ElementHelper.areEqual(vp, baseElement)) return vp.property(baseProperty.key(), baseProperty.value()); } } throw new IllegalStateException("Could not find vertex property to create the attachable property on"); } }
final EventStrategy eventStrategy = getTraversal().getStrategies().getStrategy(EventStrategy.class).get(); final Event.ElementPropertyEvent removeEvent; if (toRemove.element() instanceof Edge) removeEvent = new Event.EdgePropertyRemovedEvent(eventStrategy.detach((Edge) toRemove.element()), eventStrategy.detach(toRemove)); else if (toRemove.element() instanceof VertexProperty) removeEvent = new Event.VertexPropertyPropertyRemovedEvent(eventStrategy.detach((VertexProperty) toRemove.element()), eventStrategy.detach(toRemove)); else throw new IllegalStateException("The incoming object is not removable: " + s);
public <V> Iterator<VertexProperty<V>> properties(final String... propertyKeys) { Iterator<? extends Property<V>> properties = super.properties(propertyKeys); return StreamUtils.asStream(properties).filter(p -> !INTERNAL_FIELDS.contains(p.key())).filter(p -> !p.key().startsWith("out_")) .filter(p -> !p.key().startsWith("in_")).filter(p -> !p.key().startsWith("_meta_")) .map(p -> (VertexProperty<V>) new OrientVertexProperty<>(p.key(), p.value(), (OrientVertex) p.element())).iterator(); }
@Override public Element element() { final Element element = this.property.element(); if (element instanceof Vertex) return new ComputerVertex((Vertex) element); else if (element instanceof Edge) return new ComputerEdge((Edge) element); else return new ComputerVertexProperty((VertexProperty) element); }
protected DetachedProperty(final Property<V> property) { this.key = property.key(); this.value = property.value(); this.element = DetachedFactory.detach(property.element(), false); }
@Override public <O extends OutputShim> void write(final KryoShim<?, O> kryo, final O output, final Property property) { output.writeString(property.key()); kryo.writeClassAndObject(output, property.value()); kryo.writeClassAndObject(output, property.element().id()); output.writeString(property.element().label()); }
public static Property createProperty(final Attachable<Property> attachableProperty, final Vertex hostVertex) { final Property baseProperty = attachableProperty.get(); final Element baseElement = baseProperty.element(); if (baseElement instanceof Vertex) { return Method.createVertexProperty((Attachable) attachableProperty, hostVertex); } else if (baseElement instanceof Edge) { final Iterator<Edge> edgeIterator = hostVertex.edges(Direction.OUT); if (edgeIterator.hasNext()) return edgeIterator.next().property(baseProperty.key(), baseProperty.value()); throw new IllegalStateException("Could not find edge to create the property on"); } else { // vertex property final Iterator<VertexProperty<Object>> vertexPropertyIterator = hostVertex.properties(((VertexProperty) baseElement).key()); while (vertexPropertyIterator.hasNext()) { final VertexProperty<Object> vp = vertexPropertyIterator.next(); if (ElementHelper.areEqual(vp, baseElement)) return vp.property(baseProperty.key(), baseProperty.value()); } throw new IllegalStateException("Could not find vertex property to create the attachable property on"); } } }
public static void validatePropertyEquality(final Property originalProperty, final Property otherProperty) { assertEquals(originalProperty, otherProperty); assertEquals(otherProperty, originalProperty); if (originalProperty.isPresent()) { assertEquals(originalProperty.key(), otherProperty.key()); assertEquals(originalProperty.value(), otherProperty.value()); assertEquals(originalProperty.element(), otherProperty.element()); } }