All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.lithium.ldn.starql.models.QlConstraintOperator Maven / Gradle / Ivy
package com.lithium.ldn.starql.models;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
/**
* StarQL Search Query Operators. Used in {@link QlConstraint}.
*
* @author David Esposito
*/
public enum QlConstraintOperator {
// Constraint
@SuppressWarnings("unchecked")
EQUALS("=", getSet(QlConstraintValueString.class, QlConstraintValueNumber.class)),
@SuppressWarnings("unchecked")
NOT_EQUALS("!=", getSet(QlConstraintValueString.class, QlConstraintValueNumber.class)),
@SuppressWarnings("unchecked")
GREATER_THAN(">", getSet(QlConstraintValueString.class, QlConstraintValueNumber.class)),
@SuppressWarnings("unchecked")
LESS_THAN("<", getSet(QlConstraintValueString.class, QlConstraintValueNumber.class)),
@SuppressWarnings("unchecked")
GREATER_THAN_EQUAL(">=", getSet(QlConstraintValueString.class, QlConstraintValueNumber.class)),
@SuppressWarnings("unchecked")
LESS_THAN_EQUAL("<=", getSet(QlConstraintValueString.class,QlConstraintValueNumber.class)),
@SuppressWarnings("unchecked")
IN("IN", getSet(QlConstraintValueCollection.class)),
@SuppressWarnings("unchecked")
MATCHES("MATCHES", getSet(QlConstraintValueString.class)),
@SuppressWarnings("unchecked")
LIKE("LIKE", getSet(QlConstraintValueString.class, QlConstraintValueCollection.class)),
@SuppressWarnings("unchecked")
UNKNOWN("UNKNOWN", getSet());
public static final QlConstraintOperator STATIC_ACCESS = UNKNOWN;
private static final Map map;
static {
Map temp = Maps.newHashMap();
temp.put(EQUALS.getName(), EQUALS);
temp.put(NOT_EQUALS.getName(), NOT_EQUALS);
temp.put(GREATER_THAN.getName(), GREATER_THAN);
temp.put(LESS_THAN.getName(), LESS_THAN);
temp.put(GREATER_THAN_EQUAL.getName(), GREATER_THAN_EQUAL);
temp.put(LESS_THAN_EQUAL.getName(), LESS_THAN_EQUAL);
temp.put(IN.getName(), IN);
temp.put(MATCHES.getName(), MATCHES);
temp.put(LIKE.getName(), LIKE);
map = Collections.unmodifiableMap(temp);
}
private static final Set> getSet(Class extends QlConstraintValue> ... classes) {
return Collections.unmodifiableSet(Sets.newHashSet(classes));
}
private final String name;
private final Set> expectedValueTypes;
private QlConstraintOperator(String name, Set> expectedValueTypes) {
this.name = name;
this.expectedValueTypes = expectedValueTypes;
}
public String getName() {
return name;
}
public Set> getExpectedValueTypes() {
return expectedValueTypes;
}
/**
* Look up an operator enum by name.
* @param lookupName Name of desired operator enum.
* @return Desired enum if exists, {@code UNKNOWN} otherwise.
*/
public static QlConstraintOperator get(String lookupName) {
lookupName = lookupName.toUpperCase();
QlConstraintOperator result = map.get(lookupName);
return result == null ? UNKNOWN : result;
}
}