本文整理了Java中org.apache.tinkerpop.gremlin.structure.Element
类的一些代码示例,展示了Element
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element
类的具体详情如下:
包路径:org.apache.tinkerpop.gremlin.structure.Element
类名称:Element
[英]An Element is the base class for both Vertex and Edge. An Element has an identifier that must be unique to its inheriting classes ( Vertex or Edge). An Element can maintain a collection of Property objects. Typically, objects are Java primitives (e.g. String, long, int, boolean, etc.)
[中]元素是顶点和边的基类。元素的标识符必须对其继承类(顶点或边)唯一。元素可以维护属性对象的集合。通常,对象是Java原语(例如String、long、int、boolean等)
代码示例来源:origin: thinkaurelius/titan
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);
}
代码示例来源:origin: apache/tinkerpop
@Override
public <V> Property<V> property(final String key) {
return this.baseElement.property(key);
}
代码示例来源:origin: apache/tinkerpop
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;
}
代码示例来源:origin: thinkaurelius/titan
@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;
}
}
代码示例来源:origin: apache/tinkerpop
protected DetachedElement(final Element element) {
this.id = element.id();
try {
this.label = element.label();
} catch (final UnsupportedOperationException e) { // ghetto.
this.label = Vertex.DEFAULT_LABEL;
}
}
代码示例来源:origin: apache/tinkerpop
@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);
代码示例来源:origin: apache/tinkerpop
@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());
}
代码示例来源:origin: apache/tinkerpop
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]));
}
代码示例来源:origin: apache/tinkerpop
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;
}
代码示例来源:origin: org.jboss.windup.graph/windup-graph-api
/**
* 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();
}
代码示例来源:origin: apache/tinkerpop
/**
* 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()]);
}
代码示例来源:origin: org.hawkular.inventory/hawkular-inventory-impl-tinkerpop
@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())
));
}
代码示例来源:origin: apache/tinkerpop
/**
* 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());
}
代码示例来源:origin: apache/tinkerpop
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);
}
}
}
代码示例来源:origin: HuygensING/timbuctoo
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);
}
});
}
代码示例来源:origin: apache/tinkerpop
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++) {
代码示例来源:origin: MartinHaeusler/chronos
@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;
}
代码示例来源:origin: uk.gov.dstl.baleen/baleen-graph
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;
}
代码示例来源:origin: com.syncleus.ferma/ferma
@Override
public void setProperty(final String name, final Object value) {
if (value == null) {
getElement().property(name).remove();
} else if (value instanceof Enum) {
getElement().property(name, value.toString());
} else {
getElement().property(name, value);
}
}
代码示例来源:origin: apache/tinkerpop
/**
* Add or set a property value for the {@code Element} given its key.
*/
public <V> Property<V> property(final String key, final V value);
内容来源于网络,如有侵权,请联系作者删除!