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
18 package org.apache.commons.collections4;
19
20 import java.util.Collection;
21 import java.util.Map;
22 import java.util.Set;
23
24 /**
25 * The "read" subset of the {@link Map} interface.
26 *
27 * @param <K> The type of the keys in this map
28 * @param <V> The type of the values in this map
29 * @since 4.0
30 * @see Put
31 */
32 public interface Get<K, V> {
33
34 /**
35 * Tests for presence of a given key.
36 *
37 * @param key key whose presence in this map is to be tested.
38 * @return {@code true} if this map contains a mapping for the specified key.
39 * @see Map#containsKey(Object)
40 */
41 boolean containsKey(Object key);
42
43 /**
44 * Tests for presence of a given value.
45 *
46 * @param value value whose presence in this map is to be tested.
47 * @return {@code true} if this map maps one or more keys to the specified value.
48 * @see Map#containsValue(Object)
49 */
50 boolean containsValue(Object value);
51
52 /**
53 * Gets a set view of the mappings contained in this map.
54 *
55 * @return A set view of the mappings contained in this map.
56 * @see Map#entrySet()
57 */
58 Set<Map.Entry<K, V>> entrySet();
59
60 /**
61 * Gets a value at a given key.
62 *
63 * @param key The key whose associated value is to be returned.
64 * @return The value to which the specified key is mapped, or {@code null} if this map contains no mapping for the key.
65 * @see Map#get(Object)
66 */
67 V get(Object key);
68
69 /**
70 * Tests whether this instance contains any key-value mappings.
71 *
72 * @return {@code true} if this map contains no key-value mappings.
73 * @see Map#isEmpty()
74 */
75 boolean isEmpty();
76
77 /**
78 * Gets a view of the keys contained in this map.
79 *
80 * @return A set view of the keys contained in this map.
81 * @see Map#keySet()
82 */
83 Set<K> keySet();
84
85 /**
86 * Remove a key-value mappings.
87 *
88 * @param key key whose mapping is to be removed from the map.
89 * @return The previous value associated with {@code key}, or {@code null} if there was no mapping for {@code key}.
90 * @see Map#remove(Object)
91 */
92 V remove(Object key);
93
94 /**
95 * Gets the number of key-value mappings in this map.
96 *
97 * @return The number of key-value mappings in this map.
98 * @see Map#size()
99 */
100 int size();
101
102 /**
103 * Gets a a collection view of the values contained in this map.
104 *
105 * @return A collection view of the values contained in this map.
106 * @see Map#values()
107 */
108 Collection<V> values();
109 }