protected C.List<T> appendList(C.List<T> l) { if (isLazy()) { return CompositeList.of(this, l); } if (l instanceof ImmutableList) { return appendImmutableList((ImmutableList<T>) l); } return unLazyAppend(l); }
@Override @SuppressWarnings("unchecked") public C.List<T> append(Collection<? extends T> collection) { if (collection instanceof C.List) { return appendList((C.List<T>) collection); } else { return unLazyAppend(collection); } }
@Override public boolean containsAll(Collection<?> c) { for (Object o : c) { if (!contains(c)) { return false; } } return true; }
/** * Creates an immutable list of an array of elements. * <p>Note the array will not be copied, instead it will * be used directly as the backing data for the list. * To create an list with a copy of the array specified. * Use the {@link #newListOf(Object[])} method</p> * * @param ta an array of elements * @param <T> the element type * @return an immutable list backed by the specified array */ public static <T> List<T> listOf(T... ta) { return ImmutableList.of(ta); }
@Override public C.Sequence<T> append(C.Sequence<? extends T> seq) { if (seq instanceof C.List) { return appendList((C.List<T>) seq); } if (isLazy()) { return CompositeSeq.of(this, seq); } ListBuilder<T> lb = new ListBuilder<T>(size() * 2); lb.append(this).append(seq); return lb.toList(); }
@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()); }
public C.List<T> prepend(ImmutableList<T> l) { if (isLazy()) { return CompositeList.of(l, this); } int szA = size(); int szB = l.size(); T[] myData = data_; T[] data = $.newArray(myData, szA + szB); System.arraycopy(l.data_, 0, data, 0, szB); System.arraycopy(myData, 0, data, szB, szA); return of(data); }
@Override public C.Sequence<T> prepend(C.Sequence<? extends T> seq) { if (seq instanceof C.List) { return prependList((C.List<T>) seq); } if (isLazy()) { return CompositeSeq.of(seq, this); } ListBuilder<T> lb = new ListBuilder<T>(size() * 2); lb.append(seq).append(this); return lb.toList(); }
public C.List<T> prepend(C.List<T> l) { if (isLazy()) { return CompositeList.of(l, this); } if (l instanceof ImmutableList) { return prependList((ImmutableList<T>) l); } return unLazyPrepend(l); }
public C.List<T> append(C.List<T> l) { return appendList(l); }
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 boolean contains(Object o) { return indexOf(o) > -1; }
@Override public Cursor<T> locate($.Function<T, Boolean> predicate) { return locateFirst(predicate); }
public C.List<T> append(ImmutableList<T> l) { return appendImmutableList(l); }