001package edu.wpi.first.wpilibj.networktables2.util;
002
003/**
004 * An unsynchronized map which maps bytes to objects. This map is backed by a array and will only perform well the values are consecutive starting at 0
005 * 
006 * @author Mitchell
007 *
008 */
009public class ByteArrayMap extends ResizeableArrayObject{
010        /**
011         * Put a value with the given key
012         * @param key
013         * @param value
014         */
015        public void put(final byte key, final Object value){
016                int offsetKey = key+128;
017                ensureSize(offsetKey+1);
018                array[offsetKey] = value;
019        }
020        
021        /**
022         * @param key
023         * @return the value associated with the given key or null if there is no value
024         */
025        public Object get(final byte key){
026                int offsetKey = key+128;
027                if(offsetKey>=array.length)
028                        return null;
029                return array[offsetKey];
030        }
031
032        /**
033         * clear all values
034         */
035        public void clear() {
036                for(int i = 0; i<array.length; ++i)
037                        array[i] = null;
038        }
039
040        /**
041         * Remove the value for the given key
042         * @param key
043         */
044        public void remove(final char key) {
045                int offsetKey = key+128;
046                if(offsetKey>=array.length)
047                        return;
048                array[offsetKey] = null;
049        }
050}