Ranides Atterwim пре 10 година
родитељ
комит
94af40cbd5

+ 2 - 2
assira.drafts/src/main/java/net/ranides/assira/generic/IntPair.java

@@ -11,13 +11,13 @@ import java.util.Map;
 import java.util.Map.Entry;
 import net.ranides.assira.collection.lookups.Lookup.LookupEntry;
 import net.ranides.assira.collection.maps.IntMap.IntEntry;
-import net.ranides.assira.generic.CompareUtils;
 
 public class IntPair implements LookupEntry<Integer>, IntEntry<Integer>, Serializable {
 
     private static final long serialVersionUID = 2L;
 
     private final int key;
+    
 	private final int value;
 
     public IntPair(int key, int value) {
@@ -33,7 +33,7 @@ public class IntPair implements LookupEntry<Integer>, IntEntry<Integer>, Seriali
     @Override
     public boolean equals(Object object) {
         if (object instanceof Entry) {
-            Map.Entry other = (Map.Entry)object;
+            Map.Entry<?,?> other = (Map.Entry<?,?>)object;
             return CompareUtils.equals(other.getKey(), key) && CompareUtils.equals(other.getValue(), value);
         }
 	    return false;

+ 3 - 45
assira.drafts/src/main/java/net/ranides/assira/generic/Pair.java

@@ -6,10 +6,8 @@
  */
 package net.ranides.assira.generic;
 
-import java.io.Serializable;
-import java.util.Map;
+import java.util.AbstractMap;
 import java.util.Map.Entry;
-import net.ranides.assira.generic.CompareUtils;
 
 /**
  * Immutable implementation of {@link Entry} interface.
@@ -17,52 +15,12 @@ import net.ranides.assira.generic.CompareUtils;
  * @param <K>
  * @param <V>
  */
-public class Pair<K,V> implements Entry<K, V>, Serializable {
+public class Pair<K,V> extends AbstractMap.SimpleImmutableEntry<K, V> {
 
     private static final long serialVersionUID = 2L;
 
-    private final K key;
-	private final V value;
-
     public Pair(K key, V value) {
-        this.key = key;
-        this.value = value;
-    }
-
-    @Override
-    public K getKey() {
-        return key;
-    }
-
-    @Override
-    public V getValue() {
-        return value;
-    }
-
-    @Override
-    public V setValue(V value) {
-        throw new UnsupportedOperationException("Immutable pair.");
+        super(key, value);
     }
 
-    @Override
-    public int hashCode() {
-         return (key   == null ? 0 : key.hashCode()) ^ (value == null ? 0 : value.hashCode());
-    }
-
-    @Override
-    public boolean equals(Object object) {
-        if (object instanceof Entry) {
-            Map.Entry other = (Map.Entry)object;
-            return CompareUtils.equals(other.getKey(), key) && CompareUtils.equals(other.getValue(), value);
-        }
-	    return false;
-    }
-
-    @Override
-    public String toString() {
-        return key + "=" + value;
-    }
-
-
-
 }

+ 0 - 79
assira.drafts/src/main/java/net/ranides/assira/generic/TElement.java

@@ -1,79 +0,0 @@
-/*
- * @author Ranides Atterwim <ranides@gmail.com>
- * @copyright Ranides Atterwim
- * @license WTFPL
- * @url http://ranides.net/projects/???
- */
-package net.ranides.assira.generic;
-
-import net.ranides.assira.collection.HashComparator;
-import net.ranides.assira.generic.IntPair;
-
-/**
- *
- * @author Ranides Atterwim <ranides@gmail.com>
- */
-public class TElement {
-    
-    private final String id;
-    
-    private final int[] hashes;
-    
-    private final int[] values;
-    
-    public TElement(String id, int[] hashes, int[] values) {
-        this.id = id;
-        this.hashes = hashes.clone();
-        this.values = values.clone();
-    }
-    
-    public TElement(String id, IntPair... versions) {
-        this.id = id;
-        this.hashes = new int[]{versions.length};
-        this.values = new int[]{versions.length};
-        for(int i=0; i<versions.length; i++) {
-            hashes[i] = versions[i].getIntKey();
-            values[i] = versions[i].getIntValue();
-        }
-    }
-    
-    @Override
-    public int hashCode() {
-        return Comparator.STD.hashCode(this);
-    }
-
-    @Override
-    public boolean equals(Object object) {
-        return (object instanceof TElement) && Comparator.STD.equals(this, (TElement)object);
-    }
-
-    @Override
-    public String toString() {
-        return id;
-    }
-
-    public static class Comparator implements HashComparator<TElement> {
-        
-        public static final HashComparator<TElement> STD = new Comparator(0);
-    
-        public static final HashComparator<TElement> ALT = new Comparator(1);
-    
-        private final int index;
-
-        public Comparator(int index) {
-            this.index = index;
-        }
-
-        @Override
-        public int hashCode(TElement object) {
-            return object.hashes[index];
-        }
-
-        @Override
-        public int compare(TElement value1, TElement value2) {
-            return value1.values[index] - value2.values[index];
-        }
-        
-    }
-
-}

+ 0 - 34
assira.drafts/src/main/java/net/ranides/assira/generic/TElements.java

@@ -1,34 +0,0 @@
-/*
- * @author Ranides Atterwim <ranides@gmail.com>
- * @copyright Ranides Atterwim
- * @license WTFPL
- * @url http://ranides.net/projects/???
- */
-package net.ranides.assira.generic;
-
-import net.ranides.assira.generic.IntPair;
-
-/**
- *
- * @author Ranides Atterwim <ranides@gmail.com>
- */
-public abstract class TElements {
-    
-    public static final TElement A = new TElement("A",
-        new int[]{3,  7, 17}, 
-        new int[]{4, 55, 44}
-    );
-    public static final TElement B = new TElement("B",
-        pair(3, 4),
-        pair(7, 55),
-        pair(17, 44)
-    );
-    public static final TElement C = new TElement("C",
-        pair(3,4), pair(7,55), pair(17,44)
-    );
-    
-    protected static IntPair pair(int h, int v) {
-        return new IntPair(h, v);
-    }
-    
-}