ソースを参照

new: IntIteratorUtils.empty
new: IntSetUtils.empty
new: NumberPair.first,second

Ranides Atterwim 5 ヶ月 前
コミット
61e3b8dfab

+ 16 - 0
assira.core/src/main/java/net/ranides/assira/collection/iterators/IntIteratorUtils.java

@@ -26,11 +26,27 @@ import net.ranides.assira.functional.special.IntBiPredicate;
  * @author Ranides Atterwim {@literal <ranides@gmail.com>}
  */
 public final class IntIteratorUtils {
+
+    private static final IntIterator EMPTY = new IntIterator() {
+        @Override
+        public int nextInt() {
+            throw new NoSuchElementException();
+        }
+
+        @Override
+        public boolean hasNext() {
+            return false;
+        }
+    };
     
     private IntIteratorUtils() {
         /* utility class */
     }
 
+    public static IntIterator empty() {
+        return EMPTY;
+    }
+
     /**
      * Returns first element for iterator, or throws if iterator is empty.
      *

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

@@ -6,14 +6,15 @@
  */
 package net.ranides.assira.collection.sets;
 
-import java.io.Serializable;
-import java.util.Set;
-import java.util.function.IntUnaryOperator;
 import lombok.experimental.UtilityClass;
 import net.ranides.assira.collection.iterators.IntIterator;
 import net.ranides.assira.collection.iterators.IntIteratorUtils;
 import net.ranides.assira.functional.covariant.IntProjectionFunction;
 
+import java.io.Serializable;
+import java.util.Set;
+import java.util.function.IntUnaryOperator;
+
 /**
  * Static methods working with Sets
  *
@@ -22,6 +23,22 @@ import net.ranides.assira.functional.covariant.IntProjectionFunction;
 @UtilityClass
 public final class IntSetUtils {
 
+    private static final IntSet EMPTY = new AIntSet() {
+        @Override
+        public IntIterator iterator() {
+            return IntIteratorUtils.empty();
+        }
+
+        @Override
+        public int size() {
+            return 0;
+        }
+    };
+
+    public static IntSet empty() {
+        return EMPTY;
+    }
+
     /**
      * Creates view which transforms values stored inside source set.
      * Returned view does not support modifications.

+ 2 - 2
assira.core/src/main/java/net/ranides/assira/generic/Ref.java

@@ -19,9 +19,9 @@ import java.util.stream.Stream;
 
 /**
  * It is equivalent to {@link Optional}, but implements {@link java.util.Set} interface, which means
- * it can be used as collection with zero ore one element.
+ * it can be used as collection with zero or one element.
  *
- * It would be great to extend Optional, but unfortunatelly it is final
+ * It would be great to extend Optional, but unfortunately it is final
  *
  * @param <V> V
  */

+ 8 - 0
assira.core/src/main/java/net/ranides/assira/math/NumberPair.java

@@ -32,6 +32,14 @@ public class NumberPair {
         this.b = b;
     }
 
+    public Number first() {
+        return a;
+    }
+
+    public Number second() {
+        return b;
+    }
+
     public static NumberPair of(Number a, Number b) {
         return new NumberPair(a,b);
     }