package com.playmoweb.store2store.utils;

import java.util.WeakHashMap;

/**
 * A filter is a map of keys with a filter type and a value
 */
public class Filter extends WeakHashMap<String, Filter.KeyValuePair> {
    // TODO optimize access with a copy in an weak list

    public Filter(String key, String value) {
        super();
        add(key, FilterType.EQUAL, value);
    }

    public Filter(String key, FilterType type, String value) {
        super();
        add(key, type, value);
    }

    public Filter(String key, int value) {
        super();
        add(key, FilterType.EQUAL, String.valueOf(value));
    }

    public Filter add(String key, FilterType type, String value) {
        this.put(key, new KeyValuePair(type, value));
        return this;
    }

    /**
     * Optimized immutable KeyValuePair class
     */
    public static class KeyValuePair {
        public final FilterType filterType;
        public final String value;

        public KeyValuePair(FilterType ft, String v){
            value = v;
            filterType = ft;
        }
    }
}

@@ -264,32 +264,36 @@
 list%0A%0A    public
+ %3CT%3E
  Filter(String k
@@ -296,22 +296,17 @@
 ng key, 
-String
+T
  value) 
@@ -376,32 +376,36 @@
    %7D%0A%0A    public
+ %3CT%3E
  Filter(String k
@@ -417,38 +417,33 @@
 ilterType type, 
-String
+T
  value) %7B%0A      
@@ -506,133 +506,11 @@
 lic 
-Filter(String key, int value) %7B%0A        super();%0A        add(key, FilterType.EQUAL, String.valueOf(value));%0A    %7D%0A%0A    public
+%3CT%3E
  Fil
@@ -546,22 +546,17 @@
 e type, 
-String
+T
  value) 
@@ -595,16 +595,18 @@
 aluePair
+%3C%3E
 (type, v
@@ -660,19 +660,9 @@
   * 
-Optimized i
+I
 mmut
@@ -729,16 +729,19 @@
 aluePair
+%3CT%3E
  %7B%0A     
@@ -800,22 +800,17 @@
 c final 
-String
+T
  value;%0A
@@ -853,22 +853,17 @@
 ype ft, 
-String
+T
  v)%7B%0A   

Improve filter with generics