001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2004-2006, Geotools Project Managment Committee (PMC)
005: * (C) 2004, Institut de Recherche pour le Développement
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: */
017: package org.geotools.util;
018:
019: // J2SE dependencies
020: import java.io.Serializable;
021: import java.util.Map;
022:
023: // Geotools dependencies
024: import org.geotools.resources.Utilities;
025:
026: /**
027: * A default implementation of {@link java.util.Map.Entry} which map an arbitrary
028: * key-value pairs. This entry is immutable by default.
029: *
030: * @since 2.1
031: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/metadata/src/main/java/org/geotools/util/MapEntry.java $
032: * @version $Id: MapEntry.java 22443 2006-10-27 20:47:22Z desruisseaux $
033: * @author Martin Desruisseaux
034: *
035: * @todo This class will be removed when we will be allowed to compile for JSE 1.6, since a
036: * default map entry implementation is provided there.
037: */
038: public class MapEntry implements Map.Entry, Serializable {
039: /**
040: * The key.
041: */
042: private final Object key;
043:
044: /**
045: * The value.
046: */
047: private final Object value;
048:
049: /**
050: * Creates a new map entry with the specified key-value pair.
051: */
052: public MapEntry(final Object key, final Object value) {
053: this .key = key;
054: this .value = value;
055: }
056:
057: /**
058: * Returns the key corresponding to this entry.
059: */
060: public Object getKey() {
061: return key;
062: }
063:
064: /**
065: * Returns the value corresponding to this entry.
066: */
067: public Object getValue() {
068: return value;
069: }
070:
071: /**
072: * Replaces the value corresponding to this entry with the specified
073: * value (optional operation). The default implementation throws an
074: * {@link UnsupportedOperationException}.
075: */
076: public Object setValue(final Object value) {
077: throw new UnsupportedOperationException();
078: }
079:
080: /**
081: * Compares the specified object with this entry for equality.
082: */
083: public boolean equals(final Object object) {
084: if (object instanceof Map.Entry) {
085: final Map.Entry that = (Map.Entry) object;
086: return Utilities.equals(this .getKey(), that.getKey())
087: && Utilities.equals(this .getValue(), that
088: .getValue());
089: }
090: return false;
091: }
092:
093: /**
094: * Returns the hash code value for this map entry
095: */
096: public int hashCode() {
097: int code = 0;
098: if (key != null)
099: code = key.hashCode();
100: if (value != null)
101: code ^= value.hashCode();
102: return code;
103: }
104:
105: /**
106: * Returns a string representation of this entry.
107: */
108: public String toString() {
109: return Utilities.getShortClassName(this ) + "[key=" + key
110: + ", value=" + value + ']';
111: }
112: }
|