View Javadoc
1   /*
2    * Copyright 2014 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License, version 2.0 (the
5    * "License"); you may not use this file except in compliance with the License. You may obtain a
6    * 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 distributed under the License
11   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing permissions and limitations under
13   * the License.
14   */
15  package io.netty.util.collection;
16  
17  import java.util.Collection;
18  
19  /**
20   * Interface for a primitive map that uses {@code int}s as keys.
21   *
22   * @param <V> the value type stored in the map.
23   */
24  public interface IntObjectMap<V> {
25  
26      /**
27       * An Entry in the map.
28       *
29       * @param <V> the value type stored in the map.
30       */
31      interface Entry<V> {
32          /**
33           * Gets the key for this entry.
34           */
35          int key();
36  
37          /**
38           * Gets the value for this entry.
39           */
40          V value();
41  
42          /**
43           * Sets the value for this entry.
44           */
45          void setValue(V value);
46      }
47  
48      /**
49       * Gets the value in the map with the specified key.
50       *
51       * @param key the key whose associated value is to be returned.
52       * @return the value or {@code null} if the key was not found in the map.
53       */
54      V get(int key);
55  
56      /**
57       * Puts the given entry into the map.
58       *
59       * @param key the key of the entry.
60       * @param value the value of the entry.
61       * @return the previous value for this key or {@code null} if there was no previous mapping.
62       */
63      V put(int key, V value);
64  
65      /**
66       * Puts all of the entries from the given map into this map.
67       */
68      void putAll(IntObjectMap<V> sourceMap);
69  
70      /**
71       * Removes the entry with the specified key.
72       *
73       * @param key the key for the entry to be removed from this map.
74       * @return the previous value for the key, or {@code null} if there was no mapping.
75       */
76      V remove(int key);
77  
78      /**
79       * Returns the number of entries contained in this map.
80       */
81      int size();
82  
83      /**
84       * Indicates whether or not this map is empty (i.e {@link #size()} == {@code 0]).
85  
86       */
87      boolean isEmpty();
88  
89      /**
90       * Clears all entries from this map.
91       */
92      void clear();
93  
94      /**
95       * Indicates whether or not this map contains a value for the specified key.
96       */
97      boolean containsKey(int key);
98  
99      /**
100      * Indicates whether or not the map contains the specified value.
101      */
102     boolean containsValue(V value);
103 
104     /**
105      * Gets an iterable collection of the entries contained in this map.
106      */
107     Iterable<Entry<V>> entries();
108 
109     /**
110      * Gets the keys contained in this map.
111      */
112     int[] keys();
113 
114     /**
115      * Gets the values contained in this map.
116      */
117     V[] values(Class<V> clazz);
118 
119     /**
120      * Gets the values contatins in this map as a {@link Collection}.
121      */
122     Collection<V> values();
123 }