|
|
@@ -1,137 +0,0 @@
|
|
|
-/*
|
|
|
- * @author Ranides Atterwim <ranides@gmail.com>
|
|
|
- * @copyright Ranides Atterwim
|
|
|
- * @license WTFPL
|
|
|
- * @url http://ranides.net/projects/assira
|
|
|
- */
|
|
|
-package net.ranides.assira.collection.utils;
|
|
|
-
|
|
|
-import java.util.NoSuchElementException;
|
|
|
-import net.ranides.assira.collection.arrays.ArrayAllocator;
|
|
|
-import net.ranides.assira.collection.iterators.IntListIterator;
|
|
|
-import net.ranides.assira.collection.lists.IntArrayList;
|
|
|
-import net.ranides.assira.collection.lists.IntList;
|
|
|
-
|
|
|
-/**
|
|
|
- *
|
|
|
- * @author Ranides Atterwim <ranides@gmail.com>
|
|
|
- */
|
|
|
-public final class SingleCollections {
|
|
|
-
|
|
|
- private SingleCollections() {
|
|
|
- // utility class
|
|
|
- }
|
|
|
-
|
|
|
- public static IntList list(int value) {
|
|
|
- return new SIntList(value);
|
|
|
- }
|
|
|
-
|
|
|
- public static IntListIterator iterator(int value) {
|
|
|
- return new SIntListIterator(value);
|
|
|
- }
|
|
|
-
|
|
|
- private static final class SIntList extends IntArrayList {
|
|
|
-
|
|
|
- private final int value;
|
|
|
-
|
|
|
- public SIntList(int value) {
|
|
|
- this.value = value;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public IntListIterator iterator() {
|
|
|
- return new SIntListIterator(value);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public int size() {
|
|
|
- return 1;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean isEmpty() {
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean contains(int k) {
|
|
|
- return value == k;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public int[] toIntArray(int[] target) {
|
|
|
- int[] result = target;
|
|
|
- if (result == null || result.length < 1) {
|
|
|
- result = new int[1];
|
|
|
- }
|
|
|
- result[0] = value;
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public int[] toIntArray() {
|
|
|
- return new int[]{value};
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public IntList subList(int fromIndex, int toIndex) {
|
|
|
- ArrayAllocator.ensureFromTo(1, fromIndex, toIndex);
|
|
|
- return this;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- private static final class SIntListIterator implements IntListIterator {
|
|
|
-
|
|
|
- private final int value;
|
|
|
- private boolean ready;
|
|
|
-
|
|
|
- public SIntListIterator(int value) {
|
|
|
- this.value = value;
|
|
|
- this.ready = true;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean hasNext() {
|
|
|
- return ready;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean hasPrevious() {
|
|
|
- return !ready;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public int nextInt() {
|
|
|
- if(!ready) {
|
|
|
- throw new NoSuchElementException();
|
|
|
- }
|
|
|
- ready = false;
|
|
|
- return value;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public int previousInt() {
|
|
|
- if(ready) {
|
|
|
- throw new NoSuchElementException();
|
|
|
- }
|
|
|
- ready = true;
|
|
|
- return value;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- @Override
|
|
|
- public int nextIndex() {
|
|
|
- return ready ? 0 : -1;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public int previousIndex() {
|
|
|
- return ready ? -1 : 0;
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-}
|