package org.mongodb.morphia.query;

import java.util.Arrays;
import java.util.List;

import static java.lang.String.format;

Author:Scott Hernandez
/** * @author Scott Hernandez */
public enum FilterOperator { WITHIN_CIRCLE("$center"), WITHIN_CIRCLE_SPHERE("$centerSphere"), WITHIN_BOX("$box"), EQUAL("$eq", "=", "=="), NOT_EQUAL("$ne", "!=", "<>"), GREATER_THAN("$gt", ">"), GREATER_THAN_OR_EQUAL("$gte", ">="), LESS_THAN("$lt", "<"), LESS_THAN_OR_EQUAL("$lte", "<="), EXISTS("$exists", "exists"), TYPE("$type", "type"), NOT("$not"), MOD("$mod", "mod"), SIZE("$size", "size"), IN("$in", "in"), NOT_IN("$nin", "nin"), ALL("$all", "all"), ELEMENT_MATCH("$elemMatch", "elem", "elemMatch"), WHERE("$where"), // GEO NEAR("$near", "near"), NEAR_SPHERE("$nearSphere"),
Deprecated:New in server version 2.4: $geoWithin replaces $within which is deprecated.
/** * @deprecated New in server version 2.4: $geoWithin replaces $within which is deprecated. */
@Deprecated WITHIN("$within", "within"), GEO_NEAR("$geoNear", "geoNear"), GEO_WITHIN("$geoWithin", "geoWithin"), INTERSECTS("$geoIntersects", "geoIntersects"); private final String value; private final List<String> filters; FilterOperator(final String val, final String... filterValues) { value = val; filters = Arrays.asList(filterValues); }
Creates a FilterOperator from a String
Params:
  • operator – the String to convert
Returns:the FilterOperator
/** * Creates a FilterOperator from a String * * @param operator the String to convert * @return the FilterOperator */
public static FilterOperator fromString(final String operator) { final String filter = operator.trim().toLowerCase(); for (FilterOperator filterOperator : FilterOperator.values()) { if (filterOperator.matches(filter)) { return filterOperator; } } throw new IllegalArgumentException(format("Unknown operator '%s'", operator)); }
Returns true if the given filter matches the filters on this FilterOperator
Params:
  • filter – the filter to check
Returns:true if the given filter matches the filters on this FilterOperator
/** * Returns true if the given filter matches the filters on this FilterOperator * @param filter the filter to check * @return true if the given filter matches the filters on this FilterOperator */
public boolean matches(final String filter) { return filter != null && filters.contains(filter.trim().toLowerCase()); }
Returns:the value of this FilterOperator
/** * @return the value of this FilterOperator */
public String val() { return value; } }