View Javadoc
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    *      https://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  
19  import java.util.Map;
20  import java.util.Map.Entry;
21  
22  import org.apache.commons.collections4.KeyValue;
23  
24  /**
25   * A restricted implementation of {@link Entry Map.Entry} that prevents
26   * the {@link Entry Map.Entry} contract from being broken.
27   *
28   * @param <K> The type of keys
29   * @param <V> The type of mapped values
30   * @since 3.0
31   */
32  public final class DefaultMapEntry<K, V> extends AbstractMapEntry<K, V> {
33  
34      /**
35       * Constructs a new entry with the specified key and given value.
36       *
37       * @param key  The key for the entry, may be null
38       * @param value  The value for the entry, may be null
39       */
40      public DefaultMapEntry(final K key, final V value) {
41          super(key, value);
42      }
43  
44      /**
45       * Constructs a new entry from the specified {@code KeyValue}.
46       *
47       * @param pair  The pair to copy, must not be null
48       * @throws NullPointerException if the entry is null
49       */
50      public DefaultMapEntry(final KeyValue<? extends K, ? extends V> pair) {
51          super(pair.getKey(), pair.getValue());
52      }
53  
54      /**
55       * Constructs a new entry from the specified {@code Map.Entry}.
56       *
57       * @param entry  The entry to copy, must not be null
58       * @throws NullPointerException if the entry is null
59       */
60      public DefaultMapEntry(final Map.Entry<? extends K, ? extends V> entry) {
61          super(entry.getKey(), entry.getValue());
62      }
63  
64  }