DefaultMapEntry.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *      http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.apache.commons.collections4.keyvalue;

  18. import java.util.Map;

  19. import org.apache.commons.collections4.KeyValue;

  20. /**
  21.  * A restricted implementation of {@link java.util.Map.Entry Map.Entry} that prevents
  22.  * the {@link java.util.Map.Entry Map.Entry} contract from being broken.
  23.  *
  24.  * @param <K> the type of keys
  25.  * @param <V> the type of mapped values
  26.  * @since 3.0
  27.  */
  28. public final class DefaultMapEntry<K, V> extends AbstractMapEntry<K, V> {

  29.     /**
  30.      * Constructs a new entry with the specified key and given value.
  31.      *
  32.      * @param key  the key for the entry, may be null
  33.      * @param value  the value for the entry, may be null
  34.      */
  35.     public DefaultMapEntry(final K key, final V value) {
  36.         super(key, value);
  37.     }

  38.     /**
  39.      * Constructs a new entry from the specified {@code KeyValue}.
  40.      *
  41.      * @param pair  the pair to copy, must not be null
  42.      * @throws NullPointerException if the entry is null
  43.      */
  44.     public DefaultMapEntry(final KeyValue<? extends K, ? extends V> pair) {
  45.         super(pair.getKey(), pair.getValue());
  46.     }

  47.     /**
  48.      * Constructs a new entry from the specified {@code Map.Entry}.
  49.      *
  50.      * @param entry  the entry to copy, must not be null
  51.      * @throws NullPointerException if the entry is null
  52.      */
  53.     public DefaultMapEntry(final Map.Entry<? extends K, ? extends V> entry) {
  54.         super(entry.getKey(), entry.getValue());
  55.     }

  56. }