@Override public <V> Property<V> property(final String key) { return this.baseElement.property(key); }
@Override public <V> Property<V> property(final String key) { return new ComputerProperty<>(this.element.property(key)); }
/** * Assign key/value pairs as properties to an {@link org.apache.tinkerpop.gremlin.structure.Element}. If the value of {@link T#id} or * {@link T#label} is in the set of pairs, then they are ignored. * * @param element the graph element to assign the {@code propertyKeyValues} * @param propertyKeyValues the key/value pairs to assign to the {@code element} * @throws ClassCastException if the value of the key is not a {@link String} * @throws IllegalArgumentException if the value of {@code element} is null */ public static void attachProperties(final Element element, final Object... propertyKeyValues) { if (null == element) throw Graph.Exceptions.argumentCanNotBeNull("element"); for (int i = 0; i < propertyKeyValues.length; i = i + 2) { if (!propertyKeyValues[i].equals(T.id) && !propertyKeyValues[i].equals(T.label)) element.property((String) propertyKeyValues[i], propertyKeyValues[i + 1]); } }
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])); }
/** * Get the value of a {@link Property} given it's key. * The default implementation calls {@link Element#property} and then returns the associated value. * * @throws NoSuchElementException if the property does not exist on the {@code Element}. */ public default <V> V value(final String key) throws NoSuchElementException { return this.<V>property(key).orElseThrow(() -> Property.Exceptions.propertyDoesNotExist(this,key)); }
@Override public <V> Property<V> property(final String key, final V value) { if (state.equals(State.MAP_REDUCE)) throw GraphComputer.Exceptions.vertexPropertiesCanNotBeUpdatedInMapReduce(); return new ComputerProperty<>(this.element.property(key, 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 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++) {
final Property currentProperty = traverser.get().property(key); final boolean newProperty = element instanceof Vertex ? currentProperty == VertexProperty.empty() : currentProperty == Property.empty(); final Event.ElementPropertyChangedEvent evt; ((Vertex) element).property(key, value, vertexPropertyKeyValues); else element.property(key, value);
private Map<String, Object> aggregateProperties(Element element) { Map<String, Object> mention = new HashMap<>(); mention.put(ID_PROPERTY, element.id()); options .getAggregateProperties() .forEach(p -> element.property(p).ifPresent(value -> mention.put(p, value))); return mention; }
@Override public <T> T getProperty(final String name, final Class<T> type) { final Property<T> nameProperty = getElement().property(name); if( !nameProperty.isPresent() ) return null; final T nameValue = nameProperty.value(); if (type.isEnum()) { return (T) Enum.valueOf((Class<Enum>) type, nameValue.toString()); } return nameValue; }
@Override public <T> T getProperty(final String name, final Class<T> type) { final Property<T> nameProperty = getElement().property(name); if( !nameProperty.isPresent() ) return null; final T nameValue = nameProperty.value(); if (type.isEnum()) { return (T) Enum.valueOf((Class<Enum>) type, nameValue.toString()); } return nameValue; }
@Override public void setProperty(String propertyName, Object value) { try { getWrappedElement().property(propertyName, value); } catch(SchemaViolationException e) { throw new AtlasSchemaViolationException(e); } }
@Override public boolean test(final Traverser<T> toCheck) { final Property<String> property = toCheck.get().property(typeResolutionKey); if( !property.isPresent() ) return true; final String resolvedType = property.value(); if( allAllowedValues.contains(resolvedType) ) return false; else return true; } });
@Override public <V> Property<V> property(final String key, final V value) { if (state.equals(State.MAP_REDUCE)) throw GraphComputer.Exceptions.vertexPropertiesCanNotBeUpdatedInMapReduce(); return new ComputerProperty<>(this.element.property(key, value)); }
@Override public <T> T getProperty(final String name) { final Property<T> property = getElement().<T>property(name); if( property.isPresent()) return property.value(); else return null; }
@Override public Class<?> resolve(final Element element) { final Property<String> typeResolutionName = element.<String>property(this.typeResolutionKey); if( typeResolutionName.isPresent() ) return this.reflectionCache.forName(typeResolutionName.value()); else return null; }
@Override public Element visitMetricType(MetricType.Blueprint type, Void parameter) { Element entity = common(path, type.getName(), type.getProperties(), MetricType.class); entity.property(Constants.Property.__metric_data_type.name(), type.getMetricDataType() .getDisplayName()); entity.property(Constants.Property.__metric_interval.name(), type.getCollectionInterval()); return entity; }
@Override public Element visitMetric(Metric.Blueprint metric, Void parameter) { Element entity = common(path, metric.getName(), metric.getProperties(), Metric.class); if (metric.getCollectionInterval() != null) { entity.property(Constants.Property.__metric_interval.name(), metric.getCollectionInterval()); } return entity; }