package it.unimi.dsi.fastutil.shorts;
import java.util.List;
import java.util.Collection;
import java.util.Random;
import java.util.RandomAccess;
public final class ShortLists {
private ShortLists() {
}
public static ShortList shuffle(final ShortList l, final Random random) {
for (int i = l.size(); i-- != 0;) {
final int p = random.nextInt(i + 1);
final short t = l.getShort(i);
l.set(i, l.getShort(p));
l.set(p, t);
}
return l;
}
public static class EmptyList extends ShortCollections.EmptyCollection
implements
ShortList,
RandomAccess,
java.io.Serializable,
Cloneable {
private static final long serialVersionUID = -7046029254386353129L;
protected EmptyList() {
}
@Override
public short getShort(int i) {
throw new IndexOutOfBoundsException();
}
@Override
public boolean rem(short k) {
throw new UnsupportedOperationException();
}
@Override
public short removeShort(int i) {
throw new UnsupportedOperationException();
}
@Override
public void add(final int index, final short k) {
throw new UnsupportedOperationException();
}
@Override
public short set(final int index, final short k) {
throw new UnsupportedOperationException();
}
@Override
public int indexOf(short k) {
return -1;
}
@Override
public int lastIndexOf(short k) {
return -1;
}
@Override
public boolean addAll(int i, Collection<? extends Short> c) {
throw new UnsupportedOperationException();
}
@Override
public boolean addAll(ShortList c) {
throw new UnsupportedOperationException();
}
@Override
public boolean addAll(int i, ShortCollection c) {
throw new UnsupportedOperationException();
}
@Override
public boolean addAll(int i, ShortList c) {
throw new UnsupportedOperationException();
}
@SuppressWarnings("deprecation")
@Deprecated
@Override
public void add(final int index, final Short k) {
throw new UnsupportedOperationException();
}
@SuppressWarnings("deprecation")
@Deprecated
@Override
public Short get(final int index) {
throw new UnsupportedOperationException();
}
@SuppressWarnings("deprecation")
@Deprecated
@Override
public boolean add(final Short k) {
throw new UnsupportedOperationException();
}
@SuppressWarnings("deprecation")
@Deprecated
@Override
public Short set(final int index, final Short k) {
throw new UnsupportedOperationException();
}
@SuppressWarnings("deprecation")
@Deprecated
@Override
public Short remove(int k) {
throw new UnsupportedOperationException();
}
@SuppressWarnings("deprecation")
@Deprecated
@Override
public int indexOf(Object k) {
return -1;
}
@SuppressWarnings("deprecation")
@Deprecated
@Override
public int lastIndexOf(Object k) {
return -1;
}
@Override
public void sort(final ShortComparator comparator) {
}
@Override
public void unstableSort(final ShortComparator comparator) {
}
@Deprecated
@Override
public void sort(final java.util.Comparator<? super Short> comparator) {
}
@Deprecated
@Override
public void unstableSort(final java.util.Comparator<? super Short> comparator) {
}
@Override
public ShortListIterator listIterator() {
return ShortIterators.EMPTY_ITERATOR;
}
@Override
public ShortListIterator iterator() {
return ShortIterators.EMPTY_ITERATOR;
}
@Override
public ShortListIterator listIterator(int i) {
if (i == 0)
return ShortIterators.EMPTY_ITERATOR;
throw new IndexOutOfBoundsException(String.valueOf(i));
}
@Override
public ShortList subList(int from, int to) {
if (from == 0 && to == 0)
return this;
throw new IndexOutOfBoundsException();
}
@Override
public void getElements(int from, short[] a, int offset, int length) {
if (from == 0 && length == 0 && offset >= 0 && offset <= a.length)
return;
throw new IndexOutOfBoundsException();
}
@Override
public void removeElements(int from, int to) {
throw new UnsupportedOperationException();
}
@Override
public void addElements(int index, final short a[], int offset, int length) {
throw new UnsupportedOperationException();
}
@Override
public void addElements(int index, final short a[]) {
throw new UnsupportedOperationException();
}
@Override
public void setElements(final short a[]) {
throw new UnsupportedOperationException();
}
@Override
public void setElements(int index, final short a[]) {
throw new UnsupportedOperationException();
}
@Override
public void setElements(int index, final short a[], int offset, int length) {
throw new UnsupportedOperationException();
}
@Override
public void size(int s) {
throw new UnsupportedOperationException();
}
@Override
public int compareTo(final List<? extends Short> o) {
if (o == this)
return 0;
return ((List<?>) o).isEmpty() ? 0 : -1;
}
@Override
public Object clone() {
return EMPTY_LIST;
}
@Override
public int hashCode() {
return 1;
}
@Override
@SuppressWarnings("rawtypes")
public boolean equals(Object o) {
return o instanceof List && ((List) o).isEmpty();
}
@Override
public String toString() {
return "[]";
}
private Object readResolve() {
return EMPTY_LIST;
}
}
public static final EmptyList EMPTY_LIST = new EmptyList();
public static class Singleton extends AbstractShortList implements RandomAccess, java.io.Serializable, Cloneable {
private static final long serialVersionUID = -7046029254386353129L;
private final short element;
protected Singleton(final short element) {
this.element = element;
}
@Override
public short getShort(final int i) {
if (i == 0)
return element;
throw new IndexOutOfBoundsException();
}
@Override
public boolean rem(short k) {
throw new UnsupportedOperationException();
}
@Override
public short removeShort(final int i) {
throw new UnsupportedOperationException();
}
@Override
public boolean contains(final short k) {
return ((k) == (element));
}
@Override
public short[] toShortArray() {
short a[] = new short[1];
a[0] = element;
return a;
}
@Override
public ShortListIterator listIterator() {
return ShortIterators.singleton(element);
}
@Override
public ShortListIterator iterator() {
return listIterator();
}
@Override
public ShortListIterator listIterator(final int i) {
if (i > 1 || i < 0)
throw new IndexOutOfBoundsException();
final ShortListIterator l = listIterator();
if (i == 1)
l.nextShort();
return l;
}
@Override
public ShortList subList(final int from, final int to) {
ensureIndex(from);
ensureIndex(to);
if (from > to)
throw new IndexOutOfBoundsException(
"Start index (" + from + ") is greater than end index (" + to + ")");
if (from != 0 || to != 1)
return EMPTY_LIST;
return this;
}
@Override
public boolean addAll(int i, Collection<? extends Short> c) {
throw new UnsupportedOperationException();
}
@Override
public boolean addAll(final Collection<? extends Short> c) {
throw new UnsupportedOperationException();
}
@Override
public boolean removeAll(final Collection<?> c) {
throw new UnsupportedOperationException();
}
@Override
public boolean retainAll(final Collection<?> c) {
throw new UnsupportedOperationException();
}
@Override
public boolean addAll(ShortList c) {
throw new UnsupportedOperationException();
}
@Override
public boolean addAll(int i, ShortList c) {
throw new UnsupportedOperationException();
}
@Override
public boolean addAll(int i, ShortCollection c) {
throw new UnsupportedOperationException();
}
@Override
public boolean addAll(final ShortCollection c) {
throw new UnsupportedOperationException();
}
@Override
public boolean removeAll(final ShortCollection c) {
throw new UnsupportedOperationException();
}
@Override
public boolean retainAll(final ShortCollection c) {
throw new UnsupportedOperationException();
}
@Override
public void sort(final ShortComparator comparator) {
}
@Override
public void unstableSort(final ShortComparator comparator) {
}
@Deprecated
@Override
public void sort(final java.util.Comparator<? super Short> comparator) {
}
@Deprecated
@Override
public void unstableSort(final java.util.Comparator<? super Short> comparator) {
}
@Override
public void removeElements(int from, int to) {
throw new UnsupportedOperationException();
}
@Override
public void addElements(int index, short a[]) {
throw new UnsupportedOperationException();
}
@Override
public void addElements(int index, short a[], int offset, int length) {
throw new UnsupportedOperationException();
}
@Override
public void setElements(final short a[]) {
throw new UnsupportedOperationException();
}
@Override
public void setElements(int index, final short a[]) {
throw new UnsupportedOperationException();
}
@Override
public void setElements(int index, final short a[], int offset, int length) {
throw new UnsupportedOperationException();
}
@Override
public int size() {
return 1;
}
@Override
public void size(final int size) {
throw new UnsupportedOperationException();
}
@Override
public void clear() {
throw new UnsupportedOperationException();
}
@Override
public Object clone() {
return this;
}
}
public static ShortList singleton(final short element) {
return new Singleton(element);
}
public static ShortList singleton(final Object element) {
return new Singleton(((Short) (element)).shortValue());
}
public static class SynchronizedList extends ShortCollections.SynchronizedCollection
implements
ShortList,
java.io.Serializable {
private static final long serialVersionUID = -7046029254386353129L;
protected final ShortList list;
protected SynchronizedList(final ShortList l, final Object sync) {
super(l, sync);
this.list = l;
}
protected SynchronizedList(final ShortList l) {
super(l);
this.list = l;
}
@Override
public short getShort(final int i) {
synchronized (sync) {
return list.getShort(i);
}
}
@Override
public short set(final int i, final short k) {
synchronized (sync) {
return list.set(i, k);
}
}
@Override
public void add(final int i, final short k) {
synchronized (sync) {
list.add(i, k);
}
}
@Override
public short removeShort(final int i) {
synchronized (sync) {
return list.removeShort(i);
}
}
@Override
public int indexOf(final short k) {
synchronized (sync) {
return list.indexOf(k);
}
}
@Override
public int lastIndexOf(final short k) {
synchronized (sync) {
return list.lastIndexOf(k);
}
}
@Override
public boolean addAll(final int index, final Collection<? extends Short> c) {
synchronized (sync) {
return list.addAll(index, c);
}
}
@Override
public void getElements(final int from, final short a[], final int offset, final int length) {
synchronized (sync) {
list.getElements(from, a, offset, length);
}
}
@Override
public void removeElements(final int from, final int to) {
synchronized (sync) {
list.removeElements(from, to);
}
}
@Override
public void addElements(int index, final short a[], int offset, int length) {
synchronized (sync) {
list.addElements(index, a, offset, length);
}
}
@Override
public void addElements(int index, final short a[]) {
synchronized (sync) {
list.addElements(index, a);
}
}
@Override
public void setElements(final short a[]) {
synchronized (sync) {
list.setElements(a);
}
}
@Override
public void setElements(int index, final short a[]) {
synchronized (sync) {
list.setElements(index, a);
}
}
@Override
public void setElements(int index, final short a[], int offset, int length) {
synchronized (sync) {
list.setElements(index, a, offset, length);
}
}
@Override
public void size(final int size) {
synchronized (sync) {
list.size(size);
}
}
@Override
public ShortListIterator listIterator() {
return list.listIterator();
}
@Override
public ShortListIterator iterator() {
return listIterator();
}
@Override
public ShortListIterator listIterator(final int i) {
return list.listIterator(i);
}
@Override
public ShortList subList(final int from, final int to) {
synchronized (sync) {
return new SynchronizedList(list.subList(from, to), sync);
}
}
@Override
public boolean equals(final Object o) {
if (o == this)
return true;
synchronized (sync) {
return collection.equals(o);
}
}
@Override
public int hashCode() {
synchronized (sync) {
return collection.hashCode();
}
}
@Override
public int compareTo(final List<? extends Short> o) {
synchronized (sync) {
return list.compareTo(o);
}
}
@Override
public boolean addAll(final int index, final ShortCollection c) {
synchronized (sync) {
return list.addAll(index, c);
}
}
@Override
public boolean addAll(final int index, ShortList l) {
synchronized (sync) {
return list.addAll(index, l);
}
}
@Override
public boolean addAll(ShortList l) {
synchronized (sync) {
return list.addAll(l);
}
}
@Deprecated
@Override
public Short get(final int i) {
synchronized (sync) {
return list.get(i);
}
}
@Deprecated
@Override
public void add(final int i, Short k) {
synchronized (sync) {
list.add(i, k);
}
}
@Deprecated
@Override
public Short set(final int index, Short k) {
synchronized (sync) {
return list.set(index, k);
}
}
@Deprecated
@Override
public Short remove(final int i) {
synchronized (sync) {
return list.remove(i);
}
}
@Deprecated
@Override
public int indexOf(final Object o) {
synchronized (sync) {
return list.indexOf(o);
}
}
@Deprecated
@Override
public int lastIndexOf(final Object o) {
synchronized (sync) {
return list.lastIndexOf(o);
}
}
@Override
public void sort(final ShortComparator comparator) {
synchronized (sync) {
list.sort(comparator);
}
}
@Override
public void unstableSort(final ShortComparator comparator) {
synchronized (sync) {
list.unstableSort(comparator);
}
}
@Deprecated
@Override
public void sort(final java.util.Comparator<? super Short> comparator) {
synchronized (sync) {
list.sort(comparator);
}
}
@Deprecated
@Override
public void unstableSort(final java.util.Comparator<? super Short> comparator) {
synchronized (sync) {
list.unstableSort(comparator);
}
}
private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException {
synchronized (sync) {
s.defaultWriteObject();
}
}
}
public static class SynchronizedRandomAccessList extends SynchronizedList
implements
RandomAccess,
java.io.Serializable {
private static final long serialVersionUID = 0L;
protected SynchronizedRandomAccessList(final ShortList l, final Object sync) {
super(l, sync);
}
protected SynchronizedRandomAccessList(final ShortList l) {
super(l);
}
@Override
public ShortList subList(final int from, final int to) {
synchronized (sync) {
return new SynchronizedRandomAccessList(list.subList(from, to), sync);
}
}
}
public static ShortList synchronize(final ShortList l) {
return l instanceof RandomAccess ? new SynchronizedRandomAccessList(l) : new SynchronizedList(l);
}
public static ShortList synchronize(final ShortList l, final Object sync) {
return l instanceof RandomAccess ? new SynchronizedRandomAccessList(l, sync) : new SynchronizedList(l, sync);
}
public static class UnmodifiableList extends ShortCollections.UnmodifiableCollection
implements
ShortList,
java.io.Serializable {
private static final long serialVersionUID = -7046029254386353129L;
protected final ShortList list;
protected UnmodifiableList(final ShortList l) {
super(l);
this.list = l;
}
@Override
public short getShort(final int i) {
return list.getShort(i);
}
@Override
public short set(final int i, final short k) {
throw new UnsupportedOperationException();
}
@Override
public void add(final int i, final short k) {
throw new UnsupportedOperationException();
}
@Override
public short removeShort(final int i) {
throw new UnsupportedOperationException();
}
@Override
public int indexOf(final short k) {
return list.indexOf(k);
}
@Override
public int lastIndexOf(final short k) {
return list.lastIndexOf(k);
}
@Override
public boolean addAll(final int index, final Collection<? extends Short> c) {
throw new UnsupportedOperationException();
}
@Override
public void getElements(final int from, final short a[], final int offset, final int length) {
list.getElements(from, a, offset, length);
}
@Override
public void removeElements(final int from, final int to) {
throw new UnsupportedOperationException();
}
@Override
public void addElements(int index, final short a[], int offset, int length) {
throw new UnsupportedOperationException();
}
@Override
public void addElements(int index, final short a[]) {
throw new UnsupportedOperationException();
}
@Override
public void setElements(final short a[]) {
throw new UnsupportedOperationException();
}
@Override
public void setElements(int index, final short a[]) {
throw new UnsupportedOperationException();
}
@Override
public void setElements(int index, final short a[], int offset, int length) {
throw new UnsupportedOperationException();
}
@Override
public void size(final int size) {
list.size(size);
}
@Override
public ShortListIterator listIterator() {
return ShortIterators.unmodifiable(list.listIterator());
}
@Override
public ShortListIterator iterator() {
return listIterator();
}
@Override
public ShortListIterator listIterator(final int i) {
return ShortIterators.unmodifiable(list.listIterator(i));
}
@Override
public ShortList subList(final int from, final int to) {
return new UnmodifiableList(list.subList(from, to));
}
@Override
public boolean equals(final Object o) {
if (o == this)
return true;
return collection.equals(o);
}
@Override
public int hashCode() {
return collection.hashCode();
}
@Override
public int compareTo(final List<? extends Short> o) {
return list.compareTo(o);
}
@Override
public boolean addAll(final int index, final ShortCollection c) {
throw new UnsupportedOperationException();
}
@Override
public boolean addAll(final ShortList l) {
throw new UnsupportedOperationException();
}
@Override
public boolean addAll(final int index, final ShortList l) {
throw new UnsupportedOperationException();
}
@Deprecated
@Override
public Short get(final int i) {
return list.get(i);
}
@Deprecated
@Override
public void add(final int i, Short k) {
throw new UnsupportedOperationException();
}
@Deprecated
@Override
public Short set(final int index, Short k) {
throw new UnsupportedOperationException();
}
@Deprecated
@Override
public Short remove(final int i) {
throw new UnsupportedOperationException();
}
@Deprecated
@Override
public int indexOf(final Object o) {
return list.indexOf(o);
}
@Deprecated
@Override
public int lastIndexOf(final Object o) {
return list.lastIndexOf(o);
}
@Override
public void sort(final ShortComparator comparator) {
throw new UnsupportedOperationException();
}
@Override
public void unstableSort(final ShortComparator comparator) {
throw new UnsupportedOperationException();
}
@Deprecated
@Override
public void sort(final java.util.Comparator<? super Short> comparator) {
throw new UnsupportedOperationException();
}
@Deprecated
@Override
public void unstableSort(final java.util.Comparator<? super Short> comparator) {
throw new UnsupportedOperationException();
}
}
public static class UnmodifiableRandomAccessList extends UnmodifiableList
implements
RandomAccess,
java.io.Serializable {
private static final long serialVersionUID = 0L;
protected UnmodifiableRandomAccessList(final ShortList l) {
super(l);
}
@Override
public ShortList subList(final int from, final int to) {
return new UnmodifiableRandomAccessList(list.subList(from, to));
}
}
public static ShortList unmodifiable(final ShortList l) {
return l instanceof RandomAccess ? new UnmodifiableRandomAccessList(l) : new UnmodifiableList(l);
}
}