Java tutorial
/******************************************************************************* * Copyright 2012 Eric McIntyre * * 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 com.riversoforion.acheron.patterns; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; /** * Generic name-value pair. * * @author Eric McIntyre (<a href="mailto:mac@riversoforion.com">Mac</a>) * @param <N> * The type of the {@code name} property * @param <V> * The type of the {@code value} property */ public class NameValuePair<N, V> { private N name; private V value; public NameValuePair() { } public NameValuePair(N name, V value) { this.name = name; this.value = value; } public void setName(N name) { this.name = name; } public N getName() { return this.name; } public void setValue(V value) { this.value = value; } public V getValue() { return this.value; } @Override public boolean equals(Object obj) { if (obj == null) { return false; } if (obj == this) { return true; } if (obj.getClass() != getClass()) { return false; } NameValuePair<?, ?> other = (NameValuePair<?, ?>) obj; return new EqualsBuilder().append(this.name, other.name).append(this.value, other.value).isEquals(); } @Override public int hashCode() { return new HashCodeBuilder().append(this.name).append(this.value).toHashCode(); } @Override public String toString() { return String.format("{%s = %s}", this.name, this.value); } }