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 org.apache.commons.lang.builder.HashCodeBuilder; import org.springframework.util.ObjectUtils; import com.google.common.base.Preconditions; /** * */ public class Option { private final Identifier name; private final Identifier value; /** * * * @param name * @param value */ public Option(Identifier name, Identifier value) { this.name = Preconditions.checkNotNull(name); this.value = Preconditions.checkNotNull(value); } /** * * * @param timestamp */ public static Option timestamp(long timestamp) { return new Option(new Identifier("TIMESTAMP"), new Identifier(Long.toString(timestamp))); } /** * * * @param ttl */ public static Option ttl(long ttl) { return new Option(new Identifier("TTL"), new Identifier(Long.toString(ttl))); } /** * {@inheritDoc} */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(name); sb.append(" "); sb.append(value); return sb.toString(); } /** * {@inheritDoc} */ @Override public boolean equals(Object rhs) { if (this == rhs) { return true; } else if (!(rhs instanceof Option)) { return false; } else { Option that = (Option) rhs; return ObjectUtils.nullSafeEquals(this.name, that.name) && ObjectUtils.nullSafeEquals(this.value, that.value); } } /** * {@inheritDoc} */ @Override public int hashCode() { return HashCodeBuilder.reflectionHashCode(this); } /** * @return the name */ public Identifier getName() { return name; } /** * @return the value */ public Identifier getValue() { return value; } }