Просмотр исходного кода

new: IntRange.begin,end
remove: IntSet.remove(int)

Ranides Atterwim 5 месяцев назад
Родитель
Сommit
8f430134bb

+ 1 - 1
assira.commons/src/main/java/net/ranides/assira/collection/maps/AIntMap.java

@@ -152,7 +152,7 @@ public abstract class AIntMap<V> implements IntMap<V>, Serializable {
             }
 
             @Override
-            public boolean remove(int key) {
+            public boolean rem(int key) {
                 int prev = AIntMap.this.size();
                 AIntMap.this.remove(key);
                 return prev != AIntMap.this.size();

+ 1 - 1
assira.commons/src/main/java/net/ranides/assira/collection/maps/AIntOpenMap.java

@@ -746,7 +746,7 @@ public abstract class AIntOpenMap<V> extends AIntMap<V> implements BlockMap<Inte
         }
 
         @Override
-        public boolean remove(int k) {
+        public boolean rem(int k) {
             final int oldSize = size;
             AIntOpenMap.this.remove(k);
             return size != oldSize;

+ 1 - 1
assira.commons/src/main/java/net/ranides/assira/collection/maps/AIntSortedMap.java

@@ -331,7 +331,7 @@ public abstract class AIntSortedMap<V> extends AIntMap<V> implements IntSortedMa
         }
         
         @Override
-        public boolean remove(int k) {
+        public boolean rem(int k) {
             int prev = AIntSortedMap.this.size();
             AIntSortedMap.this.remove(k);
             return prev != AIntSortedMap.this.size();

+ 1 - 1
assira.commons/src/main/java/net/ranides/assira/collection/maps/IntArrayMap.java

@@ -196,7 +196,7 @@ public class IntArrayMap<V> extends AIntMap<V> implements BlockMap<Integer, V> {
             }
 
             @Override
-            public boolean remove(Object o) {
+            public boolean rem(int o) {
                 int prev = size;
                 IntArrayMap.this.remove(o);
                 return prev != size;

+ 1 - 1
assira.commons/src/main/java/net/ranides/assira/collection/sets/AIntAVLTreeSet.java

@@ -333,7 +333,7 @@ public class AIntAVLTreeSet extends AIntSortedSet implements java.io.Serializabl
 
     @SuppressWarnings("PMD")
     @Override
-    public boolean remove(int value) {
+    public boolean rem(int value) {
         if (tree == null) {
             return false;
         }

+ 1 - 1
assira.commons/src/main/java/net/ranides/assira/collection/sets/AIntRBTreeSet.java

@@ -265,7 +265,7 @@ public class AIntRBTreeSet extends AIntSortedSet implements java.io.Serializable
 
     @SuppressWarnings("PMD")
     @Override
-    public boolean remove(int key) {
+    public boolean rem(int key) {
         if (tree == null) {
             return false;
         }

+ 3 - 6
assira.commons/src/main/java/net/ranides/assira/collection/sets/AIntSortedSet.java

@@ -211,14 +211,11 @@ public abstract class AIntSortedSet extends AIntSet implements IntSortedSet, jav
         }
 
         @Override
-        public final boolean remove(Object key) {
-			if(!(key instanceof Integer)) {
-				return false;
-			}
-            if (!inside((Integer) key)) {
+        public final boolean rem(int key) {
+            if (!inside(key)) {
                 return false;
             }
-            return AIntSortedSet.this.remove(key);
+            return AIntSortedSet.this.rem(key);
         }
 
         @Override

+ 2 - 2
assira.core/src/main/java/net/ranides/assira/collection/AIntCollection.java

@@ -118,7 +118,7 @@ public abstract class AIntCollection extends ACollection<Integer> implements Int
     }
     
     @Override
-    public boolean rem(Object value) {
+    public final boolean rem(Object value) {
         if(!(value instanceof Integer)) {
             return false;
         }
@@ -126,7 +126,7 @@ public abstract class AIntCollection extends ACollection<Integer> implements Int
     }
     
     @Override
-    public boolean remove(Object value) {
+    public final boolean remove(Object value) {
         if(!(value instanceof Integer)) {
             return false;
         }

+ 0 - 8
assira.core/src/main/java/net/ranides/assira/collection/lists/AIntList.java

@@ -225,14 +225,6 @@ public abstract class AIntList extends AIntCollection implements IntList, Compar
         return getInt(index);
     }
 
-    @Override
-    public boolean remove(Object value) {
-        if(!(value instanceof Integer)) {
-            return false;
-        }
-        return rem(((Integer) value).intValue());
-    }
-
     @Override
     public boolean addAll(IntCollection values) {
         return addAll(size(), values);

+ 10 - 1
assira.core/src/main/java/net/ranides/assira/collection/lists/IntRange.java

@@ -12,6 +12,7 @@ import java.util.Spliterator;
 
 import net.ranides.assira.collection.iterators.IntListIterator;
 import net.ranides.assira.collection.iterators.RandomAccessSpliterator;
+import net.ranides.assira.collection.sets.IntSet;
 
 /**
  * Virtual list providing numbers from specified range.
@@ -19,7 +20,7 @@ import net.ranides.assira.collection.iterators.RandomAccessSpliterator;
  *
  * @author Ranides Atterwim {@literal <ranides@gmail.com>}
  */
-public class IntRange extends AIntList implements RandomAccess {
+public class IntRange extends AIntList implements IntSet, RandomAccess {
     
     private static final String E_IMMUTABLE = "Immutable.";
     
@@ -89,6 +90,14 @@ public class IntRange extends AIntList implements RandomAccess {
         throw new UnsupportedOperationException(E_IMMUTABLE);
     }
 
+    public int begin() {
+        return begin;
+    }
+
+    public int end() {
+        return end;
+    }
+
     private class IntRangeIterator implements IntListIterator {
         
         private int current;

+ 1 - 11
assira.core/src/main/java/net/ranides/assira/collection/sets/AIntSet.java

@@ -60,21 +60,11 @@ public abstract class AIntSet extends AIntCollection implements IntSet, java.io.
         return h;
     }
 
-    @Override
-    public boolean remove(int k) {
-        throw new UnsupportedOperationException();
-    }
-
     @Override
     public boolean rem(int k) {
-        return remove(k);
+        throw new UnsupportedOperationException();
     }
 
-    @Override
-    public boolean remove(Object value) {
-        return value instanceof Integer && remove(((Integer) value).intValue());
-    }
-    
     @Override
     public String toString() {
         IntIterator itr = iterator();

+ 1 - 1
assira.core/src/main/java/net/ranides/assira/collection/sets/IntOpenSet.java

@@ -243,7 +243,7 @@ public final class IntOpenSet extends AIntSet implements java.io.Serializable, B
     }
 
     @Override
-    public boolean remove(int value) {
+    public boolean rem(int value) {
         int pos = ifind(value);
         return used[pos] && ishift(pos);
     }

+ 1 - 15
assira.core/src/main/java/net/ranides/assira/collection/sets/IntSet.java

@@ -12,24 +12,10 @@ import net.ranides.assira.collection.iterators.IntIterator;
 
 /**
  * Specialization of Set for integer types.
- * Avoids unecessary boxing and unboxing operations.
+ * Avoids unnecessary boxing and unboxing operations.
  *
  * @author Ranides Atterwim {@literal <ranides@gmail.com>}
  */
 public interface IntSet extends IntCollection, Set<Integer> {
 
-    @Override
-    IntIterator iterator();
-
-    @Override
-    boolean rem(int k);
-
-    /**
-     * non-generic version of {@link #remove(Object)}
-     *
-     * @param k k
-     * @return bool
-     */
-    boolean remove(int k);
-    
 }

+ 3 - 7
assira.core/src/main/java/net/ranides/assira/collection/sets/IntSetUtils.java

@@ -87,13 +87,9 @@ public final class IntSetUtils {
         }
 
         @Override
-        public boolean remove(Object value) {
-            if(value instanceof Integer) {
-                Object v = function.invert((Integer) value);
-                return data.remove(v);
-            } else {
-                return false;
-            }
+        public boolean rem(int value) {
+            Object v = function.invert(value);
+            return data.remove(v);
         }
 
         @Override

+ 1 - 1
assira.core/src/test/java/net/ranides/assira/collection/sets/AIntSetTest.java

@@ -62,7 +62,7 @@ public class AIntSetTest {
         }
         
         @Override
-        public boolean remove(int key) {
+        public boolean rem(int key) {
             return data.remove(key);
         }