org.vertexium.ExtendedDataRowBase Maven / Gradle / Ivy
package org.vertexium;
import com.google.common.collect.Lists;
import org.vertexium.mutation.ElementMutation;
import org.vertexium.property.MutablePropertyImpl;
import org.vertexium.util.ConvertingIterable;
import org.vertexium.util.FilterIterable;
import java.util.Iterator;
public abstract class ExtendedDataRowBase implements ExtendedDataRow {
private final FetchHints fetchHints;
private transient Property rowIdProperty;
private transient Property tableNameProperty;
private transient Property elementIdProperty;
private transient Property elementTypeProperty;
protected ExtendedDataRowBase(FetchHints fetchHints) {
this.fetchHints = fetchHints;
}
@Override
public abstract ExtendedDataRowId getId();
@Override
public Iterable getPropertyNames() {
return new ConvertingIterable(getProperties()) {
@Override
protected String convert(Property prop) {
return prop.getName();
}
};
}
@Override
public abstract Iterable getProperties();
@Override
public Property getProperty(String name) {
return getProperty(null, name, null);
}
@Override
public Object getPropertyValue(String name) {
return getPropertyValue(null, name);
}
@Override
public Property getProperty(String key, String name, Visibility visibility) {
if (ExtendedDataRow.ROW_ID.equals(name)) {
return getRowIdProperty();
} else if (ExtendedDataRow.TABLE_NAME.equals(name)) {
return getTableNameProperty();
} else if (ExtendedDataRow.ELEMENT_ID.equals(name)) {
return getElementIdProperty();
} else if (ExtendedDataRow.ELEMENT_TYPE.equals(name)) {
return getElementTypeProperty();
}
getFetchHints().assertPropertyIncluded(name);
for (Property property : getProperties()) {
if (isMatch(property, key, name, visibility)) {
return property;
}
}
return null;
}
private boolean isMatch(Property property, String key, String name, Visibility visibility) {
if (name != null && !property.getName().equals(name)) {
return false;
}
if (key != null && !property.getKey().equals(key)) {
return false;
}
if (visibility != null && !property.getVisibility().equals(visibility)) {
return false;
}
return true;
}
@Override
public Property getProperty(String name, Visibility visibility) {
return getProperty(null, name, visibility);
}
@Override
public Iterable getProperties(String name) {
return getProperties(null, name);
}
@Override
public Iterable getProperties(String key, String name) {
if (ExtendedDataRow.ROW_ID.equals(name)) {
return Lists.newArrayList(getRowIdProperty());
} else if (ExtendedDataRow.TABLE_NAME.equals(name)) {
return Lists.newArrayList(getTableNameProperty());
} else if (ExtendedDataRow.ELEMENT_ID.equals(name)) {
return Lists.newArrayList(getElementIdProperty());
} else if (ExtendedDataRow.ELEMENT_TYPE.equals(name)) {
return Lists.newArrayList(getElementTypeProperty());
}
getFetchHints().assertPropertyIncluded(name);
return new FilterIterable(getProperties()) {
@Override
protected boolean isIncluded(Property prop) {
return isMatch(prop, key, name, null);
}
};
}
@Override
public Object getPropertyValue(String key, String name) {
Property prop = getProperty(key, name);
if (prop == null) {
return null;
}
return prop.getValue();
}
@Override
public Object getPropertyValue(String name, int index) {
return getPropertyValue(null, name, index);
}
@Override
public Object getPropertyValue(String key, String name, int index) {
if (ExtendedDataRow.ROW_ID.equals(name)) {
return getRowIdProperty().getValue();
} else if (ExtendedDataRow.TABLE_NAME.equals(name)) {
return getTableNameProperty().getValue();
} else if (ExtendedDataRow.ELEMENT_ID.equals(name)) {
return getElementIdProperty().getValue();
} else if (ExtendedDataRow.ELEMENT_TYPE.equals(name)) {
return getElementTypeProperty().getValue();
}
Iterator
© 2015 - 2025 Weber Informatics LLC | Privacy Policy