
com.tinkerpop.gremlin.structure.strategy.StrategyWrappedProperty Maven / Gradle / Ivy
package com.tinkerpop.gremlin.structure.strategy;
import com.tinkerpop.gremlin.structure.Edge;
import com.tinkerpop.gremlin.structure.Element;
import com.tinkerpop.gremlin.structure.Property;
import com.tinkerpop.gremlin.structure.Vertex;
import java.util.NoSuchElementException;
import java.util.function.Consumer;
import java.util.function.Supplier;
/**
* @author Stephen Mallette (http://stephen.genoprime.com)
*/
public class StrategyWrappedProperty implements Property, StrategyWrapped {
private final Property baseProperty;
private final Strategy.Context> strategyContext;
private final StrategyWrappedGraph strategyWrappedGraph;
public StrategyWrappedProperty(final Property baseProperty, final StrategyWrappedGraph strategyWrappedGraph) {
if (baseProperty instanceof StrategyWrapped) throw new IllegalArgumentException(
String.format("The property %s is already StrategyWrapped and must be a base Property", baseProperty));
this.baseProperty = baseProperty;
this.strategyContext = new Strategy.Context<>(strategyWrappedGraph.getBaseGraph(), this);
this.strategyWrappedGraph = strategyWrappedGraph;
}
@Override
public String key() {
return this.baseProperty.key();
}
@Override
public V value() throws NoSuchElementException {
return this.baseProperty.value();
}
@Override
public boolean isPresent() {
return this.baseProperty.isPresent();
}
@Override
public E getElement() {
final Element baseElement = this.baseProperty.getElement();
return (E) (baseElement instanceof Vertex ? new StrategyWrappedVertex((Vertex) baseElement, strategyWrappedGraph) :
new StrategyWrappedEdge((Edge) baseElement, strategyWrappedGraph));
}
@Override
public V orElseThrow(final Supplier extends E> exceptionSupplier) throws E {
return this.baseProperty.orElseThrow(exceptionSupplier);
}
@Override
public V orElseGet(final Supplier extends V> edgeSupplier) {
return this.baseProperty.orElseGet(edgeSupplier);
}
@Override
public V orElse(final V otherValue) {
return this.baseProperty.orElse(otherValue);
}
@Override
public void ifPresent(final Consumer super V> consumer) {
this.baseProperty.ifPresent(consumer);
}
@Override
public boolean isHidden() {
return this.baseProperty.isHidden();
}
@Override
public void remove() {
this.strategyWrappedGraph.strategy().compose(
s -> s.getRemovePropertyStrategy(strategyContext),
() -> {
this.baseProperty.remove();
return null;
}).get();
}
@Override
public String toString() {
return baseProperty.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy