public static long getCompareId(Element element) { Object id = element.id(); if (id instanceof Long) return (Long)id; else if (id instanceof RelationIdentifier) return ((RelationIdentifier)id).getRelationId(); else throw new IllegalArgumentException("Element identifier has unrecognized type: " + id); }
public static long getCompareId(Element element) { Object id = element.id(); if (id instanceof Long) return (Long)id; else if (id instanceof RelationIdentifier) return ((RelationIdentifier)id).getRelationId(); else throw new IllegalArgumentException("Element identifier has unrecognized type: " + id); }
@Override public boolean equals(Object other) { if (other==null) return false; if (this==other) return true; if (!((this instanceof Vertex && other instanceof Vertex) || (this instanceof Edge && other instanceof Edge) || (this instanceof VertexProperty && other instanceof VertexProperty))) return false; //Same type => they are the same if they have identical ids. if (other instanceof AbstractElement) { return getCompareId()==((AbstractElement)other).getCompareId(); } else if (other instanceof TitanElement) { return ((TitanElement) other).hasId() && getCompareId()==((TitanElement)other).longId(); } else if (other instanceof Element) { Object otherId = ((Element)other).id(); if (otherId instanceof RelationIdentifier) return ((RelationIdentifier) otherId).getRelationId()==getCompareId(); else return otherId.equals(getCompareId()); } else return false; }
@Override public boolean equals(Object other) { if (other==null) return false; if (this==other) return true; if (!((this instanceof Vertex && other instanceof Vertex) || (this instanceof Edge && other instanceof Edge) || (this instanceof VertexProperty && other instanceof VertexProperty))) return false; //Same type => they are the same if they have identical ids. if (other instanceof AbstractElement) { return getCompareId()==((AbstractElement)other).getCompareId(); } else if (other instanceof JanusGraphElement) { return ((JanusGraphElement) other).hasId() && getCompareId()==((JanusGraphElement)other).longId(); } else { Object otherId = ((Element)other).id(); if (otherId instanceof RelationIdentifier) return ((RelationIdentifier) otherId).getRelationId()==getCompareId(); else return otherId.equals(getCompareId()); } }
@Override public Object apply(final Element element) { return element.id(); } },
public void convertElementsToIds() { for (int i = 0; i < this.ids.length; i++) { // if this is going to OLAP, convert to ids so you don't serialize elements if (this.ids[i] instanceof Element) this.ids[i] = ((Element) this.ids[i]).id(); } }
@Override public Object id() { return this.baseElement.id(); }
@Override public Object id() { return this.element.id(); }
/** * Simply tests if the value returned from {@link org.apache.tinkerpop.gremlin.structure.Element#id()} are {@code equal()}. * * @param a the first {@link org.apache.tinkerpop.gremlin.structure.Element} * @param b the second {@link org.apache.tinkerpop.gremlin.structure.Element} * @return true if ids are equal and false otherwise */ public static boolean haveEqualIds(final Element a, final Element b) { return a.id().equals(b.id()); }
elementIds[i] = ((Element) ids[i]).id();
/** * If two {@link Element} instances are equal, then they must have the same hash codes. This methods ensures consistent hashCode values. * * @param element the element to get the hashCode for * @return the hash code of the element */ public static int hashCode(final Element element) { return element.id().hashCode(); }
@Override public void apply(final Traversal.Admin<?, ?> traversal) { if (TraversalHelper.onGraphComputer(traversal)) return; TraversalHelper.getStepsOfClass(GraphStep.class, traversal).forEach(originalGraphStep -> { if (originalGraphStep.getIds() == null || originalGraphStep.getIds().length == 0) { //Try to optimize for index calls final JanusGraphStep<?, ?> janusGraphStep = new JanusGraphStep<>(originalGraphStep); TraversalHelper.replaceStep(originalGraphStep, janusGraphStep, traversal); HasStepFolder.foldInIds(janusGraphStep, traversal); HasStepFolder.foldInHasContainer(janusGraphStep, traversal, traversal); HasStepFolder.foldInOrder(janusGraphStep, janusGraphStep.getNextStep(), traversal, traversal, janusGraphStep.returnsVertex(), null); HasStepFolder.foldInRange(janusGraphStep, JanusGraphTraversalUtil.getNextNonIdentityStep(janusGraphStep), traversal, null); } else { //Make sure that any provided "start" elements are instantiated in the current transaction final Object[] ids = originalGraphStep.getIds(); ElementUtils.verifyArgsMustBeEitherIdOrElement(ids); if (ids[0] instanceof Element) { //GraphStep constructor ensures that the entire array is elements final Object[] elementIds = new Object[ids.length]; for (int i = 0; i < ids.length; i++) { elementIds[i] = ((Element) ids[i]).id(); } originalGraphStep.setIteratorSupplier(() -> originalGraphStep.returnsVertex() ? ((Graph) originalGraphStep.getTraversal().getGraph().get()).vertices(elementIds) : ((Graph) originalGraphStep.getTraversal().getGraph().get()).edges(elementIds)); } } }); }
protected DetachedElement(final Element element) { this.id = element.id(); try { this.label = element.label(); } catch (final UnsupportedOperationException e) { // ghetto. this.label = Vertex.DEFAULT_LABEL; } }
@Override protected Object map(final Traverser.Admin<S> traverser) { return traverser.get().id(); }
protected boolean testIdAsString(Element element) { return this.predicate.test(element.id().toString()); }
private void ser(final Object o, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider) throws IOException { if (Element.class.isAssignableFrom(o.getClass())) jsonGenerator.writeFieldName((((Element) o).id()).toString()); else super.serialize(o, jsonGenerator, serializerProvider); } }
private void ser(final Object o, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider) throws IOException { if (Element.class.isAssignableFrom(o.getClass())) jsonGenerator.writeFieldName((((Element) o).id()).toString()); else super.serialize(o, jsonGenerator, serializerProvider); } }
private void ser(final Object o, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider) throws IOException { if (Element.class.isAssignableFrom(o.getClass())) jsonGenerator.writeFieldName((((Element) o).id()).toString()); else super.serialize(o, jsonGenerator, serializerProvider); } }
@Override public boolean equals(Object obj) { if (!(obj instanceof Element)) { return false; } Element other = (Element) obj; if (this.id() == null) { return false; } return this.id().equals(other.id()); }
@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()); }