소스 검색

review (27)

Ranides Atterwim 11 년 전
부모
커밋
53ed982900

+ 1 - 1
assira/src/main/java/net/ranides/assira/collection/lookups/Lookup.java

@@ -39,7 +39,7 @@ import net.ranides.assira.collection.iterators.IntIterator;
  * inner class that implements a type-specific version of
  * {@link java.util.Map.Entry}; it is particularly useful for those classes that
  * do not implement their own entries (e.g., most immutable maps).
- * @todo (assira # 6) review
+ * @todo (assira # 5) review
  */
 public abstract class Lookup<K> implements Map<K, Integer>, java.io.Serializable {
 

+ 1 - 1
assira/src/main/java/net/ranides/assira/collection/lookups/SortedLookup.java

@@ -29,7 +29,7 @@ import net.ranides.assira.collection.iterators.IntIterator;
 /**
  * An abstract class providing basic methods for sorted maps implementing a
  * type-specific interface.
- * @todo (assira # 6) review
+ * @todo (assira # 5) review
  */
 public abstract class SortedLookup<K> extends Lookup<K> implements SortedMap<K, Integer> {
 

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

@@ -39,7 +39,7 @@ import net.ranides.assira.collection.sets.ASet;
  * inner class that implements a type-specific version of
  * {@link java.util.Map.Entry}; it is particularly useful for those classes that
  * do not implement their own entries (e.g., most immutable maps).
- * @todo (assira # 6) review
+ * @todo (assira # 5) review
  */
 public abstract class AMap<K, V> implements Map<K, V>, java.io.Serializable {
 

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

@@ -29,7 +29,7 @@ import net.ranides.assira.collection.sets.ASortedSet;
 /**
  * An abstract class providing basic methods for sorted maps implementing a
  * type-specific interface.
- * @todo (assira # 6) review
+ * @todo (assira # 5) review
  */
 public abstract class ASortedMap<K, V> extends AMap<K, V> implements SortedMap<K, V> {
 

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

@@ -40,7 +40,7 @@ import net.ranides.assira.collection.iterators.IntIterator;
  * inner class that implements a type-specific version of
  * {@link java.util.Map.Entry}; it is particularly useful for those classes that
  * do not implement their own entries (e.g., most immutable maps).
- * @todo (assira # 6) review
+ * @todo (assira # 5) review
  */
 public abstract class IntMap<V> implements Map<Integer, V>, java.io.Serializable {
 

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

@@ -31,7 +31,7 @@ import net.ranides.assira.collection.iterators.IntIterator;
 /**
  * An abstract class providing basic methods for sorted maps implementing a
  * type-specific interface.
- * @todo (assira # 6) review
+ * @todo (assira # 5) review
  */
 public abstract class IntSortedMap<V> extends IntMap<V> implements SortedMap<Integer, V> {
 

+ 16 - 67
assira/src/main/java/net/ranides/assira/collection/sets/ASortedSet.java

@@ -1,21 +1,9 @@
 /*
- * @author Paolo Boldi
- * @author Sebastiano Vigna
- * @author Ranides Atterwim <contact@ranides.net>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ *  @author Ranides Atterwim <ranides@gmail.com>
+ *  @copyright Ranides Atterwim
+ *  @license WTFPL
+ *  @url http://ranides.net/projects/assira
  */
-
 package net.ranides.assira.collection.sets;
 
 import java.util.Iterator;
@@ -23,9 +11,7 @@ import java.util.Set;
 import java.util.SortedSet;
 
 /**
- * An abstract class providing basic methods for sorted sets implementing a
- * type-specific interface.
- * @todo (assira # 6) review
+ * An abstract class providing basic methods for sorted sets .
  */
 public abstract class ASortedSet<K> extends ASet<K> implements Set<K>, SortedSet<K> {
 
@@ -36,76 +22,39 @@ public abstract class ASortedSet<K> extends ASet<K> implements Set<K>, SortedSet
     public abstract Iterator<K> iterator();
 
     /**
-     * Returns a type-specific
-     * {@link it.unimi.dsi.fastutil.BidirectionalIterator} on the elements in
-     * this set, starting from a given element of the domain (optional
-     * operation).
-     *
-     * <P>This method returns a type-specific bidirectional iterator with given
+     * <P>This method returns a iterator with given
      * starting point. The starting point is any element comparable to the
      * elements of this set (even if it does not actually belong to the set).
      * The next element of the returned iterator is the least element of the set
      * that is greater than the starting point (if there are no elements greater
-     * than the starting point, {@link
-     * it.unimi.dsi.fastutil.BidirectionalIterator#hasNext() hasNext()} will
-     * return
-     * <code>false</code>). The previous element of the returned iterator is the
-     * greatest element of the set that is smaller than or equal to the starting
-     * point (if there are no elements smaller than or equal to the starting
-     * point, {@link it.unimi.dsi.fastutil.BidirectionalIterator#hasPrevious()
-     * hasPrevious()} will return
-     * <code>false</code>).
-     *
-     * <P>Note that passing the last element of the set as starting point and
-     * calling
-     * {@link it.unimi.dsi.fastutil.BidirectionalIterator#previous() previous()}
-     * you can traverse the entire set in reverse order.
+     * than the starting point, {@link IntIterator#hasNext() hasNext()} will
+     * return <code>false</code>). 
      *
-     * @param fromElement an element to start from.
-     * @return a bidirectional iterator on the element in this set, starting at
+     * @param begin an element to start from.
+     * @return an iterator on the element in this set, starting at
      * the given element.
      * @throws UnsupportedOperationException if this set does not support
      * iterators with a starting point.
      */
-    public abstract Iterator<K> iterator(K fromElement);
+    public abstract Iterator<K> iterator(K begin);
 
     /**
-     * Returns a view of the portion of this sorted set whose elements range
-     * from
-     * <code>fromElement</code>, inclusive, to
-     * <code>toElement</code>, exclusive.
-     *
-     * <P>Note that this specification strengthens the one given in
-     * {@link SortedSet#subSet(Object,Object)}.
-     *
+     * 
      * @see SortedSet#subSet(Object,Object)
      */
     @Override
-    public abstract ASortedSet<K> subSet(K fromElement, K toElement);
+    public abstract ASortedSet<K> subSet(K begin, K end);
 
     /**
-     * Returns a view of the portion of this sorted set whose elements are
-     * strictly less than
-     * <code>toElement</code>.
-     *
-     * <P>Note that this specification strengthens the one given in
-     * {@link SortedSet#headSet(Object)}.
-     *
+     * 
      * @see SortedSet#headSet(Object)
      */
     @Override
-    public abstract ASortedSet<K> headSet(K toElement);
+    public abstract ASortedSet<K> headSet(K begin);
 
     /**
-     * Returns a view of the portion of this sorted set whose elements are
-     * greater than or equal to
-     * <code>fromElement</code>.
-     *
-     * <P>Note that this specification strengthens the one given in
-     * {@link SortedSet#tailSet(Object)}.
-     *
      * @see SortedSet#tailSet(Object)
      */
     @Override
-    public abstract ASortedSet<K> tailSet(K fromElement);
+    public abstract ASortedSet<K> tailSet(K begin);
 }

+ 11 - 32
assira/src/main/java/net/ranides/assira/collection/sets/IntSet.java

@@ -1,21 +1,9 @@
 /*
- * @author Paolo Boldi
- * @author Sebastiano Vigna
- * @author Ranides Atterwim <contact@ranides.net>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ *  @author Ranides Atterwim <ranides@gmail.com>
+ *  @copyright Ranides Atterwim
+ *  @license WTFPL
+ *  @url http://ranides.net/projects/assira
  */
-
 package net.ranides.assira.collection.sets;
 
 import java.util.Set;
@@ -23,13 +11,13 @@ import net.ranides.assira.collection.IntCollection;
 import net.ranides.assira.collection.iterators.IntIterator;
 
 /**
- * An abstract class providing basic methods for sets implementing a
- * type-specific interface.
- * @todo (assira # 6) review
+ * An abstract base class for sets of primitive int values. 
+ * Designed to avoid autoboxing.
  */
 public abstract class IntSet extends IntCollection implements Set<Integer> {
 
     protected IntSet() {
+        // do nothing
     }
     
     @Override
@@ -47,6 +35,9 @@ public abstract class IntSet extends IntCollection implements Set<Integer> {
         if (oset.size() != size()) {
             return false;
         }
+        if(other instanceof IntCollection) {
+            return containsAll((IntCollection)other);
+        }
         return containsAll(oset);
     }
 
@@ -62,10 +53,8 @@ public abstract class IntSet extends IntCollection implements Set<Integer> {
     public int hashCode() {
         int h = 0, n = size();
         IntIterator itr = iterator();
-        int k;
         while (n-- != 0) {
-            k = itr.nextInt(); // We need k because KEY2JAVAHASH() is a macro with repeated evaluation.
-            h += k;
+            h += itr.nextInt();
         }
         return h;
     }
@@ -74,21 +63,11 @@ public abstract class IntSet extends IntCollection implements Set<Integer> {
         throw new UnsupportedOperationException();
     }
 
-    /**
-     * Delegates to
-     * <code>remove()</code>.
-     *
-     * @param k the element to be removed.
-     * @return true if the set was modified.
-     */
     @Override
     public boolean rem(int k) {
         return remove(k);
     }
 
-    /**
-     * Delegates to the corresponding type-specific method.
-     */
     @Override
     public boolean remove(Object value) {
         return remove(((Integer) value).intValue());

+ 16 - 60
assira/src/main/java/net/ranides/assira/collection/sets/IntSortedSet.java

@@ -1,21 +1,9 @@
 /*
- * @author Paolo Boldi
- * @author Sebastiano Vigna
- * @author Ranides Atterwim <contact@ranides.net>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ *  @author Ranides Atterwim <ranides@gmail.com>
+ *  @copyright Ranides Atterwim
+ *  @license WTFPL
+ *  @url http://ranides.net/projects/assira
  */
-
 package net.ranides.assira.collection.sets;
 
 import java.util.SortedSet;
@@ -23,50 +11,35 @@ import net.ranides.assira.collection.IntComparator;
 import net.ranides.assira.collection.iterators.IntIterator;
 
 /**
- * An abstract class providing basic methods for sorted sets implementing a
- * type-specific interface.
- * @todo (assira # 6) review
+ * An abstract base class for sorted sets of primitive int values. 
+ * Designed to avoid autoboxing.
  */
 public abstract class IntSortedSet extends IntSet implements SortedSet<Integer> {
 
     protected IntSortedSet() {
+        // do nothing
     }
     
-    /**
-     * Delegates to the corresponding type-specific method.
-     */
     @Override
     public IntSortedSet headSet(Integer toKey) {
         return headSet(toKey.intValue());
     }
 
-    /**
-     * Delegates to the corresponding type-specific method.
-     */
     @Override
     public IntSortedSet tailSet(Integer fromKey) {
         return tailSet(fromKey.intValue());
     }
 
-    /**
-     * Delegates to the corresponding type-specific method.
-     */
     @Override
     public IntSortedSet subSet(Integer fromKey, Integer toKey) {
         return subSet(fromKey.intValue(), toKey.intValue());
     }
 
-    /**
-     * Delegates to the corresponding type-specific method.
-     */
     @Override
     public Integer first() {
         return firstInt();
     }
 
-    /**
-     * Delegates to the corresponding type-specific method.
-     */
     @Override
     public Integer last() {
         return lastInt();
@@ -76,38 +49,21 @@ public abstract class IntSortedSet extends IntSet implements SortedSet<Integer>
     public abstract IntIterator iterator();
 
     /**
-     * Returns a type-specific
-     * {@link it.unimi.dsi.fastutil.BidirectionalIterator} on the elements in
-     * this set, starting from a given element of the domain (optional
-     * operation).
-     *
-     * <P>This method returns a type-specific bidirectional iterator with given
+     * <P>This method returns a iterator with given
      * starting point. The starting point is any element comparable to the
      * elements of this set (even if it does not actually belong to the set).
      * The next element of the returned iterator is the least element of the set
      * that is greater than the starting point (if there are no elements greater
-     * than the starting point, {@link
-     * it.unimi.dsi.fastutil.BidirectionalIterator#hasNext() hasNext()} will
-     * return
-     * <code>false</code>). The previous element of the returned iterator is the
-     * greatest element of the set that is smaller than or equal to the starting
-     * point (if there are no elements smaller than or equal to the starting
-     * point, {@link it.unimi.dsi.fastutil.BidirectionalIterator#hasPrevious()
-     * hasPrevious()} will return
-     * <code>false</code>).
-     *
-     * <P>Note that passing the last element of the set as starting point and
-     * calling
-     * {@link it.unimi.dsi.fastutil.BidirectionalIterator#previous() previous()}
-     * you can traverse the entire set in reverse order.
+     * than the starting point, {@link IntIterator#hasNext() hasNext()} will
+     * return <code>false</code>). 
      *
-     * @param fromElement an element to start from.
-     * @return a bidirectional iterator on the element in this set, starting at
+     * @param begin an element to start from.
+     * @return an iterator on the element in this set, starting at
      * the given element.
      * @throws UnsupportedOperationException if this set does not support
      * iterators with a starting point.
      */
-    public abstract IntIterator iterator(int fromElement);
+    public abstract IntIterator iterator(int begin);
 
     /**
      * Returns the comparator associated with this sorted set, or null if it
@@ -124,17 +80,17 @@ public abstract class IntSortedSet extends IntSet implements SortedSet<Integer>
     /**
      * @see SortedSet#subSet(Object,Object)
      */
-    public abstract IntSortedSet subSet(int fromElement, int toElement);
+    public abstract IntSortedSet subSet(int begin, int end);
 
     /**
      * @see SortedSet#headSet(Object)
      */
-    public abstract IntSortedSet headSet(int toElement);
+    public abstract IntSortedSet headSet(int begin);
 
     /**
      * @see SortedSet#tailSet(Object)
      */
-    public abstract IntSortedSet tailSet(int fromElement);
+    public abstract IntSortedSet tailSet(int begin);
 
     /**
      * @see SortedSet#first()