01: /*
02: * Copyright 2003-2006 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.apache.commons.collections.keyvalue;
17:
18: import java.util.Map;
19:
20: import org.apache.commons.collections.KeyValue;
21: import org.apache.commons.collections.Unmodifiable;
22:
23: /**
24: * A {@link java.util.Map.Entry Map.Entry} that throws
25: * UnsupportedOperationException when <code>setValue</code> is called.
26: *
27: * @since Commons Collections 3.0
28: * @version $Revision: 405927 $ $Date: 2006-05-12 23:57:03 +0100 (Fri, 12 May 2006) $
29: *
30: * @author Stephen Colebourne
31: */
32: public final class UnmodifiableMapEntry extends AbstractMapEntry
33: implements Unmodifiable {
34:
35: /**
36: * Constructs a new entry with the specified key and given value.
37: *
38: * @param key the key for the entry, may be null
39: * @param value the value for the entry, may be null
40: */
41: public UnmodifiableMapEntry(final Object key, final Object value) {
42: super (key, value);
43: }
44:
45: /**
46: * Constructs a new entry from the specified <code>KeyValue</code>.
47: *
48: * @param pair the pair to copy, must not be null
49: * @throws NullPointerException if the entry is null
50: */
51: public UnmodifiableMapEntry(final KeyValue pair) {
52: super (pair.getKey(), pair.getValue());
53: }
54:
55: /**
56: * Constructs a new entry from the specified <code>Map.Entry</code>.
57: *
58: * @param entry the entry to copy, must not be null
59: * @throws NullPointerException if the entry is null
60: */
61: public UnmodifiableMapEntry(final Map.Entry entry) {
62: super (entry.getKey(), entry.getValue());
63: }
64:
65: /**
66: * Throws UnsupportedOperationException.
67: *
68: * @param value the new value
69: * @return the previous value
70: * @throws UnsupportedOperationException always
71: */
72: public Object setValue(Object value) {
73: throw new UnsupportedOperationException(
74: "setValue() is not supported");
75: }
76:
77: }
|