org.securegraph.mutation.ExistingElementMutationImpl Maven / Gradle / Ivy
The newest version!
package org.securegraph.mutation;
import org.securegraph.*;
import org.securegraph.property.MutablePropertyImpl;
import org.securegraph.search.IndexHint;
import java.util.ArrayList;
import java.util.List;
import static org.securegraph.util.Preconditions.checkNotNull;
public abstract class ExistingElementMutationImpl implements ElementMutation, ExistingElementMutation {
private final List properties = new ArrayList<>();
private final List propertyRemoves = new ArrayList<>();
private Visibility newElementVisibility;
private final List alterPropertyVisibilities = new ArrayList<>();
private final List setPropertyMetadatas = new ArrayList<>();
private final T element;
private IndexHint indexHint = IndexHint.INDEX;
public ExistingElementMutationImpl(T element) {
this.element = element;
}
public abstract T save(Authorizations authorizations);
public ElementMutation setProperty(String name, Object value, Visibility visibility) {
return setProperty(name, value, new Metadata(), visibility);
}
public ElementMutation setProperty(String name, Object value, Metadata metadata, Visibility visibility) {
return addPropertyValue(DEFAULT_KEY, name, value, metadata, visibility);
}
public ElementMutation addPropertyValue(String key, String name, Object value, Visibility visibility) {
return addPropertyValue(key, name, value, new Metadata(), visibility);
}
public ElementMutation addPropertyValue(String key, String name, Object value, Metadata metadata, Visibility visibility) {
checkNotNull(name, "property name cannot be null for property: " + name + ":" + key);
checkNotNull(value, "property value cannot be null for property: " + name + ":" + key);
properties.add(new MutablePropertyImpl(key, name, value, metadata, null, visibility));
return this;
}
public Iterable getProperties() {
return properties;
}
@Override
public Iterable getPropertyRemoves() {
return propertyRemoves;
}
@Override
public ElementMutation removeProperty(Property property) {
checkNotNull(property, "property cannot be null");
propertyRemoves.add(new PropertyPropertyRemoveMutation(property));
return this;
}
@Override
public ExistingElementMutation removeProperties(String name) {
for (Property prop : this.element.getProperties(name)) {
removeProperty(prop);
}
return this;
}
@Override
public ExistingElementMutation removeProperties(String key, String name) {
for (Property prop : this.element.getProperties(key, name)) {
removeProperty(prop);
}
return this;
}
@Override
public ElementMutation removeProperty(String name, Visibility visibility) {
Property property = this.element.getProperty(name, visibility);
if (property != null) {
removeProperty(property);
}
return this;
}
@Override
public ElementMutation removeProperty(String key, String name, Visibility visibility) {
Property property = this.element.getProperty(key, name, visibility);
if (property != null) {
removeProperty(property);
}
return this;
}
@Override
public ExistingElementMutation alterPropertyVisibility(Property property, Visibility visibility) {
this.alterPropertyVisibilities.add(new AlterPropertyVisibility(property.getKey(), property.getName(), property.getVisibility(), visibility));
return this;
}
@Override
public ExistingElementMutation alterPropertyVisibility(String name, Visibility visibility) {
return alterPropertyVisibility(DEFAULT_KEY, name, visibility);
}
@Override
public ExistingElementMutation alterPropertyVisibility(String key, String name, Visibility visibility) {
this.alterPropertyVisibilities.add(new AlterPropertyVisibility(key, name, null, visibility));
return this;
}
@Override
public ExistingElementMutation alterElementVisibility(Visibility visibility) {
this.newElementVisibility = visibility;
return this;
}
@Override
public ExistingElementMutation setPropertyMetadata(Property property, String metadataName, Object newValue, Visibility visibility) {
this.setPropertyMetadatas.add(new SetPropertyMetadata(property.getKey(), property.getName(), property.getVisibility(), metadataName, newValue, visibility));
return this;
}
@Override
public ExistingElementMutation setPropertyMetadata(String propertyName, String metadataName, Object newValue, Visibility visibility) {
return setPropertyMetadata(DEFAULT_KEY, propertyName, metadataName, newValue, visibility);
}
@Override
public ExistingElementMutation setPropertyMetadata(String propertyKey, String propertyName, String metadataName, Object newValue, Visibility visibility) {
this.setPropertyMetadatas.add(new SetPropertyMetadata(propertyKey, propertyName, null, metadataName, newValue, visibility));
return this;
}
@Override
public T getElement() {
return element;
}
public Visibility getNewElementVisibility() {
return newElementVisibility;
}
public List getAlterPropertyVisibilities() {
return alterPropertyVisibilities;
}
public List getSetPropertyMetadatas() {
return setPropertyMetadatas;
}
public IndexHint getIndexHint() {
return indexHint;
}
@Override
public ElementMutation setIndexHint(IndexHint indexHint) {
this.indexHint = indexHint;
return this;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy