package redis.clients.util;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class JedisByteHashMap implements Map<byte[], byte[]>, Cloneable,
        Serializable {
    private static final long serialVersionUID = -6971431362627219416L;
    private Map<ByteArrayWrapper, byte[]> internalMap = new HashMap<ByteArrayWrapper, byte[]>();

    public void clear() {
        internalMap.clear();
    }

    public boolean containsKey(Object key) {
        if (key instanceof byte[])
            return internalMap.containsKey(new ByteArrayWrapper((byte[]) key));
        return internalMap.containsKey(key);
    }

    public boolean containsValue(Object value) {
        return internalMap.containsValue(value);
    }

    public Set<java.util.Map.Entry<byte[], byte[]>> entrySet() {
        Iterator<java.util.Map.Entry<ByteArrayWrapper, byte[]>> iterator = internalMap
                .entrySet().iterator();
        HashSet<Entry<byte[], byte[]>> hashSet = new HashSet<java.util.Map.Entry<byte[], byte[]>>();
        while (iterator.hasNext()) {
            Entry<ByteArrayWrapper, byte[]> entry = iterator.next();
            hashSet.add(new JedisByteEntry(entry.getKey().data, entry
                    .getValue()));
        }
        return hashSet;
    }

    @Override
    public byte[] get(Object key) {
        if (key instanceof byte[])
            return internalMap.get(new ByteArrayWrapper((byte[]) key));
        return internalMap.get(key);
    }

    @Override
    public boolean isEmpty() {
        return internalMap.isEmpty();
    }

    @Override
    public Set<byte[]> keySet() {
        Set<byte[]> keySet = new HashSet<byte[]>();
        Iterator<ByteArrayWrapper> iterator = internalMap.keySet().iterator();
        while (iterator.hasNext()) {
            keySet.add(iterator.next().data);
        }
        return keySet;
    }

    @Override
    public byte[] put(byte[] key, byte[] value) {
        return internalMap.put(new ByteArrayWrapper(key), value);
    }

    @SuppressWarnings("unchecked")
    @Override
    public void putAll(Map<? extends byte[], ? extends byte[]> m) {
        Iterator<?> iterator = m.entrySet().iterator();
        while (iterator.hasNext()) {
            Entry<? extends byte[], ? extends byte[]> next = (Entry<? extends byte[], ? extends byte[]>) iterator
                    .next();
            internalMap.put(new ByteArrayWrapper(next.getKey()), next
                    .getValue());
        }
    }

    @Override
    public byte[] remove(Object key) {
        if (key instanceof byte[])
            return internalMap.remove(new ByteArrayWrapper((byte[]) key));
        return internalMap.remove(key);
    }

    @Override
    public int size() {
        return internalMap.size();
    }

    @Override
    public Collection<byte[]> values() {
        return internalMap.values();
    }

    private final class ByteArrayWrapper {
        private final byte[] data;

        public ByteArrayWrapper(byte[] data) {
            if (data == null) {
                throw new NullPointerException();
            }
            this.data = data;
        }

        @Override
        public boolean equals(Object other) {
            if (!(other instanceof ByteArrayWrapper)) {
                return false;
            }
            return Arrays.equals(data, ((ByteArrayWrapper) other).data);
        }

        @Override
        public int hashCode() {
            return Arrays.hashCode(data);
        }
    }

    private final class JedisByteEntry implements Entry<byte[], byte[]> {
        private byte[] value;
        private byte[] key;

        public JedisByteEntry(byte[] key, byte[] value) {
            this.key = key;
            this.value = value;
        }

        public byte[] getKey() {
            return this.key;
        }

        @Override
        public byte[] getValue() {
            return this.value;
        }

        @Override
        public byte[] setValue(byte[] value) {
            this.value = value;
            return value;
        }

    }
}
@@ -1415,38 +1415,24 @@
 Set;%0A    %7D%0A%0A
-    @Override%0A
     public b
@@ -1447,32 +1447,32 @@
 t(Object key) %7B%0A
+
         if (key 
@@ -1602,38 +1602,24 @@
 ey);%0A    %7D%0A%0A
-    @Override%0A
     public b
@@ -1678,38 +1678,24 @@
 y();%0A    %7D%0A%0A
-    @Override%0A
     public S
@@ -1966,38 +1966,24 @@
 Set;%0A    %7D%0A%0A
-    @Override%0A
     public b
@@ -2128,30 +2128,16 @@
 ecked%22)%0A
-    @Override%0A
     publ
@@ -2549,38 +2549,24 @@
    %7D%0A    %7D%0A%0A
-    @Override%0A
     public b
@@ -2745,38 +2745,24 @@
 ey);%0A    %7D%0A%0A
-    @Override%0A
     public i
@@ -2815,30 +2815,16 @@
 %0A    %7D%0A%0A
-    @Override%0A
     publ
@@ -3163,34 +3163,16 @@
      %7D%0A%0A
-        @Override%0A
         
@@ -3393,34 +3393,16 @@
      %7D%0A%0A
-        @Override%0A
         
@@ -3819,34 +3819,16 @@
      %7D%0A%0A
-        @Override%0A
         
@@ -3900,26 +3900,8 @@
  %7D%0A%0A
-        @Override%0A
     

Remove @override to make it java 1.5 compliant