org.vertexium.query.GeoCompare Maven / Gradle / Ivy
package org.vertexium.query;
import org.vertexium.Property;
import org.vertexium.PropertyDefinition;
import org.vertexium.VertexiumNotSupportedException;
import org.vertexium.type.GeoShape;
import java.util.Collection;
public enum GeoCompare implements Predicate {
INTERSECTS("intersects"),
DISJOINT("disjoint"),
WITHIN("within"),
CONTAINS("contains");
private final String compareName;
GeoCompare(String compareName) {
this.compareName = compareName;
}
public String getCompareName() {
return compareName;
}
@Override
public boolean evaluate(Iterable properties, Object second, Collection propertyDefinitions) {
for (Property property : properties) {
if (evaluate(property.getValue(), second)) {
return true;
}
}
return false;
}
@Override
public boolean evaluate(Object first, Object second, PropertyDefinition propertyDefinition) {
return evaluate(first, second);
}
@Override
public void validate(PropertyDefinition propertyDefinition) {
if (!GeoShape.class.isAssignableFrom(propertyDefinition.getDataType())) {
throw new VertexiumNotSupportedException("GeoCompare predicates are not allowed for properties of type " + propertyDefinition.getDataType().getName());
}
}
private boolean evaluate(Object testValue, Object second) {
switch (this) {
case WITHIN:
return ((GeoShape) second).within((GeoShape) testValue);
default:
throw new IllegalArgumentException("Invalid compare: " + this);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy