1. /*
  2. * Copyright 2003-2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  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. import java.util.Map;
  18. import org.apache.commons.collections.KeyValue;
  19. import org.apache.commons.collections.Unmodifiable;
  20. /**
  21. * A {@link java.util.Map.Entry} that throws UnsupportedOperationException
  22. * when <code>setValue</code> is called.
  23. *
  24. * @since Commons Collections 3.0
  25. * @version $Revision: 1.3 $ $Date: 2004/02/18 01:00:08 $
  26. *
  27. * @author Stephen Colebourne
  28. */
  29. public final class UnmodifiableMapEntry extends AbstractMapEntry implements Unmodifiable {
  30. /**
  31. * Constructs a new entry with the specified key and given value.
  32. *
  33. * @param key the key for the entry, may be null
  34. * @param value the value for the entry, may be null
  35. */
  36. public UnmodifiableMapEntry(final Object key, final Object value) {
  37. super(key, value);
  38. }
  39. /**
  40. * Constructs a new entry from the specified KeyValue.
  41. *
  42. * @param pair the pair to copy, must not be null
  43. * @throws NullPointerException if the entry is null
  44. */
  45. public UnmodifiableMapEntry(final KeyValue pair) {
  46. super(pair.getKey(), pair.getValue());
  47. }
  48. /**
  49. * Constructs a new entry from the specified MapEntry.
  50. *
  51. * @param entry the entry to copy, must not be null
  52. * @throws NullPointerException if the entry is null
  53. */
  54. public UnmodifiableMapEntry(final Map.Entry entry) {
  55. super(entry.getKey(), entry.getValue());
  56. }
  57. /**
  58. * Throws UnsupportedOperationException.
  59. *
  60. * @param value the new value
  61. * @return the previous value
  62. * @throws UnsupportedOperationException always
  63. */
  64. public Object setValue(Object value) {
  65. throw new UnsupportedOperationException("setValue() is not supported");
  66. }
  67. }