/** * Returns an empty immutable list * * @param <T> the type of the list element * @return the empty list */ public static <T> List<T> list() { return Nil.list(); }
/** * Returns an empty immutable list * * @param <T> the type of the list element * @return the empty list */ public static <T> List<T> list() { return Nil.list(); }
@SuppressWarnings("unused") public static <T> List<T> emptyListOf(Class<T> c) { return Nil.list(); }
static <T> C.List<T> copyOf(T[] data) { int sz = data.length; if (sz == 0) { return Nil.list(); } T[] a = Arrays.copyOf(data, sz); return new ImmutableList<T>(a); }
static <T> C.List<T> copyOf(T[] data) { int sz = data.length; if (sz == 0) { return Nil.list(); } T[] a = Arrays.copyOf(data, sz); return new ImmutableList<T>(a); }
@Override public <R> C.List<R> flatMap($.Function<? super Character, ? extends Iterable<? extends R>> mapper ) { if (isEmpty()) { return Nil.list(); } return super.flatMap(mapper); }
@Override public <R> C.List<R> flatMap($.Function<? super Character, ? extends Iterable<? extends R>> mapper ) { if (isEmpty()) { return Nil.list(); } return super.flatMap(mapper); }
/** * Create an immutable Character list of a char array. * The elements of the array is copied into the returned list * * @param elements an array of shorts * @return an immutable list contains specified elements */ public static List<Character> list(char[] elements) { if (0 == elements.length) { return Nil.list(); } Character[] a = $.asObject(elements); return ImmutableList.of(a); }
@Override public C.List<T> subList(int fromIndex, int toIndex) { if (fromIndex == toIndex) { return Nil.list(); } if (is(C.Feature.RANDOM_ACCESS)) { return new RandomAccessSubList<T>(this, fromIndex, toIndex); } else { return new SubList<T>(this, fromIndex, toIndex); } }
static <T> C.List<T> of(T[] data) { E.NPE(data); int len = data.length; if (len == 0) { return Nil.list(); } else if (len == 1) { return $.val(data[0]); } else { return new ImmutableList<>(data); } }
static <T> C.List<T> wrap(java.util.List<T> list) { if (list instanceof C.List) { C.List<T> cl = (C.List<T>)list; if (cl.is(C.Feature.IMMUTABLE) && cl.isEmpty()) { return Nil.list(); } } if (list instanceof DelegatingList) { list = ((DelegatingList<T>)list).data; } return new DelegatingList<T>(list, true); }
static <T> C.List<T> wrap(java.util.List<T> list) { if (list instanceof C.List) { C.List<T> cl = (C.List<T>)list; if (cl.is(C.Feature.IMMUTABLE) && cl.isEmpty()) { return Nil.list(); } } if (list instanceof DelegatingList) { list = ((DelegatingList<T>)list).data; } return new DelegatingList<T>(list, true); }
static <T> C.List<T> of(T[] data) { E.NPE(data); int len = data.length; if (len == 0) { return Nil.list(); } else if (len == 1) { return $.val(data[0]); } else { return new ImmutableList<>(data); } }
@Override public C.List<T> subList(int fromIndex, int toIndex) { if (fromIndex == toIndex) { return Nil.list(); } if (is(C.Feature.RANDOM_ACCESS)) { return new RandomAccessSubList<T>(this, fromIndex, toIndex); } else { return new SubList<T>(this, fromIndex, toIndex); } }
static <T> C.List<T> wrap(C.List<T> list) { if (list instanceof ReverseList) { return ((ReverseList<T>)list).data(); } if (list.size() == 0 && list.is(C.Feature.IMMUTABLE)) { return Nil.list(); } return new ReverseList<T>(list); } }
static <T> C.List<T> wrap(C.List<T> list) { if (list instanceof ReverseList) { return ((ReverseList<T>)list).data(); } if (list.size() == 0 && list.is(C.Feature.IMMUTABLE)) { return Nil.list(); } return new ReverseList<T>(list); } }
@Override public C.List<T> dropWhile($.Function<? super T, Boolean> predicate) { //TODO: handle lazy operation int sz = size(); $.Function<T, Boolean> f = $.F.negate(predicate); Cursor<T> cursor = locateFirst(f); if (!cursor.isDefined()) { return Nil.list(); } int id = cursor.index(); return subList(id, size()); }
@Override public C.List<T> dropWhile($.Function<? super T, Boolean> predicate) { //TODO: handle lazy operation int sz = size(); $.Function<T, Boolean> f = $.F.negate(predicate); Cursor<T> cursor = locateFirst(f); if (!cursor.isDefined()) { return Nil.list(); } int id = cursor.index(); return subList(id, size()); }
@Override public <R> C.List<R> map($.Function<? super Character, ? extends R> mapper) { int sz = size(); if (0 == sz) { return Nil.list(); } ListBuilder<R> lb = new ListBuilder<R>(sz); forEach($.visitor($.f1(mapper).andThen(C.F.addTo(lb)))); return lb.toList(); }
@Override public <R> C.List<R> map($.Function<? super Character, ? extends R> mapper) { int sz = size(); if (0 == sz) { return Nil.list(); } ListBuilder<R> lb = new ListBuilder<R>(sz); forEach($.visitor($.f1(mapper).andThen(C.F.addTo(lb)))); return lb.toList(); }