001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      https://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.collections4.keyvalue;
018
019import java.util.Map;
020import java.util.Map.Entry;
021
022import org.apache.commons.collections4.KeyValue;
023
024/**
025 * A restricted implementation of {@link Entry Map.Entry} that prevents
026 * the {@link Entry Map.Entry} contract from being broken.
027 *
028 * @param <K> The type of keys
029 * @param <V> The type of mapped values
030 * @since 3.0
031 */
032public final class DefaultMapEntry<K, V> extends AbstractMapEntry<K, V> {
033
034    /**
035     * Constructs a new entry with the specified key and given value.
036     *
037     * @param key  The key for the entry, may be null
038     * @param value  The value for the entry, may be null
039     */
040    public DefaultMapEntry(final K key, final V value) {
041        super(key, value);
042    }
043
044    /**
045     * Constructs a new entry from the specified {@code KeyValue}.
046     *
047     * @param pair  The pair to copy, must not be null
048     * @throws NullPointerException if the entry is null
049     */
050    public DefaultMapEntry(final KeyValue<? extends K, ? extends V> pair) {
051        super(pair.getKey(), pair.getValue());
052    }
053
054    /**
055     * Constructs a new entry from the specified {@code Map.Entry}.
056     *
057     * @param entry  The entry to copy, must not be null
058     * @throws NullPointerException if the entry is null
059     */
060    public DefaultMapEntry(final Map.Entry<? extends K, ? extends V> entry) {
061        super(entry.getKey(), entry.getValue());
062    }
063
064}