Java Code Examples for org.apache.tinkerpop.gremlin.structure.VertexProperty#empty()

The following examples show how to use org.apache.tinkerpop.gremlin.structure.VertexProperty#empty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Neo4JVertex.java    From neo4j-gremlin-bolt with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
@SuppressWarnings("unchecked")
public <V> VertexProperty<V> property(String key) {
    Objects.requireNonNull(key, "key cannot be null");
    // check we have a property with the given key
    Collection<?> collection = properties.get(key);
    if (collection != null) {
        // check size
        if (collection.size() == 1) {
            // iterator
            Iterator<?> iterator = collection.iterator();
            // advance iterator to first element
            if (iterator.hasNext()) {
                // first element
                return (VertexProperty<V>)iterator.next();
            }
            return VertexProperty.empty();
        }
        // exception
        throw Vertex.Exceptions.multiplePropertiesExistForProvidedKey(key);
    }
    return VertexProperty.empty();
}
 
Example 2
Source File: Neo4jVertex.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Override
public <V> VertexProperty<V> property(final VertexProperty.Cardinality cardinality, final String key, final V value, final Object... keyValues) {
    ElementHelper.validateProperty(key, value);
    if (ElementHelper.getIdValue(keyValues).isPresent())
        throw Vertex.Exceptions.userSuppliedIdsNotSupported();
    this.graph.tx().readWrite();

    if (cardinality != VertexProperty.Cardinality.single)
        throw VertexProperty.Exceptions.multiPropertiesNotSupported();

    if (null == value) {
        properties(key).forEachRemaining(VertexProperty::remove);
        return VertexProperty.empty();
    }

    if (keyValues.length > 0)
        throw VertexProperty.Exceptions.metaPropertiesNotSupported();
    try {
        this.baseElement.setProperty(key, value);
        return new Neo4jVertexProperty<>(this, key, value);
    } catch (final IllegalArgumentException iae) {
        throw Property.Exceptions.dataTypeOfPropertyValueNotSupported(value, iae);
    }
}
 
Example 3
Source File: BitsyVertex.java    From bitsy with Apache License 2.0 5 votes vote down vote up
@Override
public <T> VertexProperty<T> property(String key) {
    T value = value(key);
    if (value == null) {
        return VertexProperty.<T>empty();
    } else {
        return new BitsyVertexProperty<T>(this, key, value);
    }
}
 
Example 4
Source File: HadoopVertex.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public <V> VertexProperty<V> property(final String key) {
    final VertexProperty<V> vertexProperty = getBaseVertex().<V>property(key);
    return vertexProperty.isPresent() ?
            new HadoopVertexProperty<>((VertexProperty<V>) ((Vertex) this.baseElement).property(key), this) :
            VertexProperty.<V>empty();
}
 
Example 5
Source File: DetachedVertex.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public <V> VertexProperty<V> property(final String key) {
    if (null != this.properties && this.properties.containsKey(key)) {
        final List<VertexProperty> list = (List) this.properties.get(key);
        if (list.size() > 1)
            throw Vertex.Exceptions.multiplePropertiesExistForProvidedKey(key);
        else
            return list.get(0);
    } else
        return VertexProperty.<V>empty();
}
 
Example 6
Source File: HBaseVertex.java    From hgraphdb with Apache License 2.0 4 votes vote down vote up
@Override
public <V> VertexProperty<V> property(final String key) {
    V value = getProperty(key);
    return value != null ? new HBaseVertexProperty<>(graph, this, key, value) : VertexProperty.empty();
}
 
Example 7
Source File: Neo4jVertex.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
public <V> VertexProperty<V> property(final String key) {
    this.graph.tx().readWrite();
    return baseElement.hasProperty(key) ? new Neo4jVertexProperty<>(this, key, (V) baseElement.getProperty(key)) : VertexProperty.<V>empty();
}