private Property captureRemovedProperty(final Element element, final String key, final Object value,
                                            final EventStrategy es){
        Property removedProperty = VertexProperty.empty();

        if (element instanceof Vertex) {
            if (cardinality == VertexProperty.Cardinality.set) {
                final Iterator<? extends Property> properties = element.properties(key);
                while (properties.hasNext()) {
                    final Property property = properties.next();
                    if (Objects.equals(property.value(), value)) {
                        removedProperty = property;
                        break;
                    }
                }
            } else if (cardinality == VertexProperty.Cardinality.single) {
                removedProperty = element.property(key);
            }
        } else {
            removedProperty = element.property(key);
        }

        // detach removed property
        if (removedProperty.isPresent()) {
            removedProperty = es.detach(removedProperty);
        } else {
            removedProperty = element instanceof Vertex ? new KeyedVertexProperty(key) : new KeyedProperty(key);
        }

        return removedProperty;
    }
@author Marko A. Rodriguez (http://markorodriguez.com)
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/AddPropertyStep.java