All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.tiles.request.collection.MapEntry Maven / Gradle / Ivy

There is a newer version: 1.0.7
Show newest version
/*
 * $Id: MapEntry.java 1049711 2010-12-15 21:12:00Z apetrelli $
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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 org.apache.tiles.request.collection;


import java.util.Map;


/**
 * 

Map.Entry implementation that can be constructed to either be read-only * or not.

* * @version $Rev: 1049711 $ $Date: 2010-12-15 22:12:00 +0100 (Wed, 15 Dec 2010) $ * @param The key type. * @param The value type. */ public class MapEntry implements Map.Entry { /** *

The entry key.

*/ private K key; /** *

The entry value.

*/ private V value; /** *

Whether the entry can be modified.

*/ private boolean modifiable = false; /** *

Creates a map entry that can either allow modifications or not.

* * @param key The entry key * @param value The entry value * @param modifiable Whether the entry should allow modification or not */ public MapEntry(K key, V value, boolean modifiable) { this.key = key; this.value = value; this.modifiable = modifiable; } /** *

Gets the entry key.

* * @return The entry key */ public K getKey() { return key; } /** *

Gets the entry value.

* * @return The entry key */ public V getValue() { return value; } /** *

Sets the entry value if the entry can be modified.

* * @param val The new value * @return The old entry value * @throws UnsupportedOperationException If the entry cannot be modified */ public V setValue(V val) { if (modifiable) { V oldVal = this.value; this.value = val; return oldVal; } throw new UnsupportedOperationException("The map entry is not modifiable"); } /** *

Determines if this entry is equal to the passed object.

* * @param o The object to test * @return True if equal, else false */ @Override @SuppressWarnings("unchecked") public boolean equals(Object o) { if (o != null && o instanceof Map.Entry) { Map.Entry entry = (Map.Entry) o; return (this.getKey() == null ? entry.getKey() == null : this .getKey().equals(entry.getKey())) && (this.getValue() == null ? entry.getValue() == null : this.getValue().equals(entry.getValue())); } return false; } /** *

Returns the hashcode for this entry.

* * @return The and'ed hashcode of the key and value */ @Override public int hashCode() { return (this.getKey() == null ? 0 : this.getKey().hashCode()) ^ (this.getValue() == null ? 0 : this.getValue().hashCode()); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy