Java tutorial
/* * Copyright 2013 EK3 Technologies, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package ei.ne.ke.cassandra.cql3.template; import java.util.Map; import org.apache.commons.lang.StringUtils; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; /** * */ public enum Comparator { EQ("="), LT("<"), GT(">"), LT_OR_EQ("<="), GT_OR_EQ(">="), IN("IN"); private static final Map<String, Comparator> STR_LOOKUP; private final String literal; /** * @param literal */ private Comparator(String literal) { this.literal = literal; } /** * * * @param literal * @return */ public static Comparator getEnum(String literal) { String trimmedLiteral = StringUtils.trim(literal); if (!STR_LOOKUP.containsKey(trimmedLiteral)) { throw new IllegalArgumentException("Unknown comparator: " + trimmedLiteral); } return STR_LOOKUP.get(trimmedLiteral); } /** * {@inheritDoc} */ @Override public String toString() { return literal; } static { Map<String, Comparator> tmp = Maps.newHashMap(); for (Comparator comp : Comparator.values()) { tmp.put(comp.literal, comp); } STR_LOOKUP = ImmutableMap.copyOf(tmp); } }