public static <V> Optional<VertexProperty<V>> stageVertexProperty(final Vertex vertex,
                                                                      final VertexProperty.Cardinality cardinality,
                                                                      final String key, final V value, final Object... keyValues) {
        if (cardinality.equals(VertexProperty.Cardinality.single)) {
            final Iterator<VertexProperty<Object>> properties = vertex.properties(key);
            if (null != properties)
                properties.forEachRemaining(VertexProperty::remove);
        }
        else if (cardinality.equals(VertexProperty.Cardinality.set)) {
            final Iterator<VertexProperty<V>> itty = vertex.properties(key);
            while (itty.hasNext()) {
                final VertexProperty<V> property = itty.next();
                if (property.value().equals(value)) {
                    ElementHelper.attachProperties(property, keyValues);
                    return Optional.of(property);
                }
            }
        } // do nothing on Cardinality.list
        return Optional.empty();
    }
This is a helper method for dealing with vertex property cardinality and typically used in {@link Vertex#property(VertexProperty.Cardinality, String, Object, Object...)}.
If the cardinality is list, simply return {@link Optional#empty}.
If the cardinality is single, delete all existing properties of the provided key and return {@link Optional#empty}.
If the cardinality is set, find one that has the same key/value and attached the properties to it and return it. Else, if no equal value is found, return {@link Optional#empty}.

@param vertex      the vertex to stage a vertex property for
@param cardinality the cardinality of the vertex property
@param key         the key of the vertex property
@param value       the value of the vertex property
@param keyValues   the properties of vertex property
@param <V>         the type of the vertex property value
@return a vertex property if it has been found in set with equal value
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelper.java