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.Collection; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.builder.HashCodeBuilder; import org.springframework.util.ObjectUtils; import com.google.common.collect.Lists; /** * CQL3 IN relation. */ public class In extends Relation { private final Collection<Term> terms; /** * Creates a new IN clause with the given identifier and terms. * @param identifier the identifier. * @param terms the terms. */ public In(Identifier identifier, Term... terms) { super(identifier, Comparator.IN); this.terms = Lists.newArrayList(terms); } /** * Creates a new IN clause with the given identifier and terms. * @param identifier the identifier. * @param terms the terms. */ public In(Identifier identifier, Collection<Term> terms) { super(identifier, Comparator.IN); this.terms = Lists.newArrayListWithExpectedSize(terms.size()); this.terms.addAll(terms); } /** * {@inheritDoc} */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(identifier); sb.append(" "); sb.append("IN("); sb.append(StringUtils.join(terms, ", ")); sb.append(")"); return sb.toString(); } /** * {@inheritDoc} */ @Override public boolean equals(Object rhs) { if (this == rhs) { return true; } else if (!(rhs instanceof In)) { return false; } else { In that = (In) rhs; return super.equals(rhs) && ObjectUtils.nullSafeEquals(this.terms, that.terms); } } /** * {@inheritDoc} */ @Override public int hashCode() { return HashCodeBuilder.reflectionHashCode(this); } }