Refine search
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 <V> Property<V> property(final String key) { return this.baseElement.property(key); }
public static Map<String, Object> propertyValueMap(final Element element, final String... propertyKeys) { final Map<String, Object> values = new HashMap<>(); element.properties(propertyKeys).forEachRemaining(property -> values.put(property.key(), property.value())); return values; }
@Override protected Iterator<E> flatMap(final Traverser.Admin<Element> traverser) { if (useMultiQuery) { //it is guaranteed that all elements are vertices assert multiQueryResults != null; return convertIterator(multiQueryResults.get(traverser.get())); } else if (traverser.get() instanceof Vertex) { TitanVertexQuery query = makeQuery((TitanTraversalUtil.getTitanVertex(traverser)).query()); return convertIterator(query.properties()); } else { //It is some other element (edge or vertex property) Iterator<E> iter; if (getReturnType().forValues()) { assert orders.isEmpty() && hasContainers.isEmpty(); iter = traverser.get().values(getPropertyKeys()); } else { //this asks for properties assert orders.isEmpty(); //HasContainers don't apply => empty result set if (!hasContainers.isEmpty()) return Collections.emptyIterator(); iter = (Iterator<E>) traverser.get().properties(getPropertyKeys()); } if (limit!=Query.NO_LIMIT) iter = Iterators.limit(iter,limit); return iter; } }
@Override protected Map<K, E> map(final Traverser.Admin<Element> traverser) { final Map<Object, Object> map = new LinkedHashMap<>(); final Element element = traverser.get(); final boolean isVertex = element instanceof Vertex; if (this.returnType == PropertyType.VALUE) { if (includeToken(WithOptions.ids)) map.put(T.id, element.id()); if (element instanceof VertexProperty) { if (includeToken(WithOptions.keys)) map.put(T.key, ((VertexProperty<?>) element).key()); if (includeToken(WithOptions.values)) map.put(T.value, ((VertexProperty<?>) element).value()); } else { if (includeToken(WithOptions.labels)) map.put(T.label, element.label()); element.properties(this.propertyKeys) : TraversalUtil.applyAll(traverser, this.propertyTraversal); final Object value = this.returnType == PropertyType.VALUE ? property.value() : property; if (isVertex) { map.compute(property.key(), (k, v) -> { final List<Object> values = v != null ? (List<Object>) v : new ArrayList<>(); values.add(value); }); } else { map.put(property.key(), value);
@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 void createKeyIndex(final String key) { if (null == key) throw Graph.Exceptions.argumentCanNotBeNull("key"); if (key.isEmpty()) throw new IllegalArgumentException("The key for the index cannot be an empty string"); if (this.indexedKeys.contains(key)) return; this.indexedKeys.add(key); (Vertex.class.isAssignableFrom(this.indexClass) ? this.graph.vertices.values().<T>parallelStream() : this.graph.edges.values().<T>parallelStream()) .map(e -> new Object[]{((T) e).property(key), e}) .filter(a -> ((Property) a[0]).isPresent()) .forEach(a -> this.put(key, ((Property) a[0]).value(), (T) a[1])); }
public static Map<String, Property> propertyMap(final Element element, final String... propertyKeys) { final Map<String, Property> propertyMap = new HashMap<>(); element.properties(propertyKeys).forEachRemaining(property -> propertyMap.put(property.key(), property)); return propertyMap; }
/** * A string representation of this vertex, showing it's properties in a JSON-like format. */ default String toPrettyString() { Element v = getElement(); StringBuilder result = new StringBuilder(); result.append("[").append(v.toString()).append("="); result.append("{"); boolean hasSome = false; for (String propKey : v.keys()) { hasSome = true; Iterator<? extends Property<Object>> propVal = v.properties(propKey); List<Object> propValues = new ArrayList<>(); propVal.forEachRemaining(prop -> propValues.add(prop.value())); if (propValues.size() == 1) result.append(propKey).append(": ").append(propValues.get(0)); else result.append(propKey).append(": ").append(propValues); result.append(", "); } if (hasSome) { result.delete(result.length() - 2, result.length()); } result.append("}]"); return result.toString(); }
/** * Retrieve the properties associated with a particular element. * The result is a Object[] where odd indices are String keys and even indices are the values. * * @param element the element to retrieve properties from * @param includeId include Element.ID in the key/value list * @param includeLabel include Element.LABEL in the key/value list * @param propertiesToCopy the properties to include with an empty list meaning copy all properties * @return a key/value array of properties where odd indices are String keys and even indices are the values. */ public static Object[] getProperties(final Element element, final boolean includeId, final boolean includeLabel, final Set<String> propertiesToCopy) { final List<Object> keyValues = new ArrayList<>(); if (includeId) { keyValues.add(T.id); keyValues.add(element.id()); } if (includeLabel) { keyValues.add(T.label); keyValues.add(element.label()); } element.keys().forEach(key -> { if (propertiesToCopy.isEmpty() || propertiesToCopy.contains(key)) { keyValues.add(key); keyValues.add(element.value(key)); } }); return keyValues.toArray(new Object[keyValues.size()]); }
@Override public boolean isBackendInternal(Element element) { return (element instanceof Vertex && element.property(Constants.Property.__type.name()).value().equals( Constants.InternalType.__identityHash.name())) || (element instanceof Edge && ( element.label().equals(Constants.InternalEdge.__withIdentityHash.name()) || element.label().equals(Constants.InternalEdge.__containsIdentityHash.name()) )); }
/** * Get the values of properties as an {@link Iterator}. */ public default <V> Iterator<V> values(final String... propertyKeys) { return IteratorUtils.map(this.<V>properties(propertyKeys), property -> property.value()); }
public final boolean test(final Element element) { // it is OK to evaluate equality of ids via toString(), given that the test suite enforces the value of // id().toString() to be a first class representation of the identifier. a string test is only executed // if the predicate value is a String. this allows stuff like: g.V().has(id,lt(10)) to work properly if (this.key.equals(T.id.getAccessor())) return testingIdString ? testIdAsString(element) : testId(element); else if (this.key.equals(T.label.getAccessor())) return testLabel(element); else if (element instanceof VertexProperty && this.key.equals(T.value.getAccessor())) return testValue((VertexProperty) element); else if (element instanceof VertexProperty && this.key.equals(T.key.getAccessor())) return testKey((VertexProperty) element); else { if (element instanceof Vertex) { final Iterator<? extends Property> itty = element.properties(this.key); while (itty.hasNext()) { if (testValue(itty.next())) return true; } return false; } else { final Property property = element.property(this.key); return property.isPresent() && testValue(property); } } }
private void updateExistingProperties(LogOutput dbLog) { Set<String> existing = Sets.intersection(newKeys, oldKeys); existing.forEach(key -> { Property<Object> latestProperty = element.property(key); if (!Objects.equals(latestProperty.value(), prevElement.value(key))) { dbLog.updateProperty(latestProperty); } }); }
private void assertPropertyValue(final Element element) { if (value instanceof Map) tryCommit(graph, graph -> { final Map map = element.<Map>property("aKey").value(); assertEquals(((Map) value).size(), map.size()); ((Map) value).keySet().forEach(k -> assertEquals(((Map) value).get(k), map.get(k))); else if (value instanceof List) tryCommit(graph, graph -> { final List l = element.<List>property("aKey").value(); assertEquals(((List) value).size(), l.size()); for (int ix = 0; ix < ((List) value).size(); ix++) { else if (value instanceof MockSerializable) tryCommit(graph, graph -> { final MockSerializable mock = element.<MockSerializable>property("aKey").value(); assertEquals(((MockSerializable) value).getTestField(), mock.getTestField()); }); else if (value instanceof boolean[]) tryCommit(graph, graph -> { final boolean[] l = element.<boolean[]>property("aKey").value(); assertEquals(((boolean[]) value).length, l.length); for (int ix = 0; ix < ((boolean[]) value).length; ix++) { else if (value instanceof double[]) tryCommit(graph, graph -> { final double[] l = element.<double[]>property("aKey").value(); assertEquals(((double[]) value).length, l.length); for (int ix = 0; ix < ((double[]) value).length; ix++) {
@Override public boolean apply(final V element) { ChronoElement chronoElement = (ChronoElement) element; if (chronoElement.isRemoved()) { // never consider removed elements return false; } for (SearchSpecification<?> searchSpec : this.searchSpecifications) { if (element.property(searchSpec.getProperty()).isPresent() == false) { // the property in question is not present, it is NOT possible to make // any decision if it matches the given search criterion or not. In particular, // when the search is negated (e.g. 'not equals'), we decide to have a non-match // for non-existing properties return false; } Object propertyValue = element.value(searchSpec.getProperty()); boolean searchSpecApplies = ChronoGraphQueryUtil.searchSpecApplies(searchSpec, propertyValue); if (searchSpecApplies == false) { // element failed to pass this filter return false; } } // element passed all filters return true; }
/** * Add or set a property value for the {@code Element} given its key. */ public <V> Property<V> property(final String key, final V value);