com.tinkerpop.blueprints.Contains Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of blueprints-core Show documentation
Show all versions of blueprints-core Show documentation
Core interfaces and utilities for Blueprints
The newest version!
package com.tinkerpop.blueprints;
import java.util.Collection;
/**
* Contains is a predicate that evaluates whether the first object is contained within (or not within) the second collection object.
* For example:
*
* gremlin IN [gremlin, blueprints, furnace] == true
* gremlin NOT_IN [gremlin, rexster] == false
* rexster NOT_IN [gremlin, blueprints, furnace] == true
*
* @author Pierre De Wilde
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
public enum Contains implements Predicate {
IN, NOT_IN;
public boolean evaluate(final Object first, final Object second) {
if (second instanceof Collection) {
return this.equals(IN) ? ((Collection) second).contains(first) : !((Collection) second).contains(first);
} else {
throw new IllegalArgumentException("The second argument must be a collection");
}
}
public Contains opposite() {
return this.equals(IN) ? NOT_IN : IN;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy