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 * https://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.Map; 18 19 /** 20 * Interface for a primitive map that uses {@code byte}s as keys. 21 * 22 * @param <V> the value type stored in the map. 23 */ 24 public interface ByteObjectMap<V> extends Map<Byte, V> { 25 26 /** 27 * A primitive entry in the map, provided by the iterator from {@link #entries()} 28 * 29 * @param <V> the value type stored in the map. 30 */ 31 interface PrimitiveEntry<V> { 32 /** 33 * Gets the key for this entry. 34 */ 35 byte 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(byte 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(byte key, V value); 64 65 /** 66 * Removes the entry with the specified key. 67 * 68 * @param key the key for the entry to be removed from this map. 69 * @return the previous value for the key, or {@code null} if there was no mapping. 70 */ 71 V remove(byte key); 72 73 /** 74 * Gets an iterable to traverse over the primitive entries contained in this map. As an optimization, 75 * the {@link PrimitiveEntry}s returned by the {@link Iterator} may change as the {@link Iterator} 76 * progresses. The caller should not rely on {@link PrimitiveEntry} key/value stability. 77 */ 78 Iterable<PrimitiveEntry<V>> entries(); 79 80 /** 81 * Indicates whether or not this map contains a value for the specified key. 82 */ 83 boolean containsKey(byte key); 84 }