@Override public C.List<T> forEach($.Visitor<? super T> visitor) { return accept(visitor); }
public boolean addAll(Iterable<? extends T> iterable) { boolean modified = false; Iterator<? extends T> e = iterable.iterator(); while (e.hasNext()) { if (add(e.next())) { modified = true; } } sorted = !modified; if (!sorted) { unsetFeature(SORTED); } return modified; }
@Override public boolean noneMatch($.Function<? super T, Boolean> predicate) { return !anyMatch(predicate); }
@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 C.List<T> sorted(Comparator<? super T> comparator) { C.List<T> l = copy(); Collections.sort(l, comparator); ((ListBase)l).setFeature(SORTED); return l; }
@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); } return unLazyAppend(seq); }
@Override public C.List<T> append(T t) { if (isMutable()) { add(t); return this; } // Immutable if (isImmutable()) { ListBuilder<T> lb = new ListBuilder<T>(size() + 1); lb.addAll(this); lb.add(t); return lb.toList(); } // mutable but readonly C.List<T> l = C.newSizedList(size() + 1); l.addAll(this); l.add(t); return l; }
return this; int sz = size(); if (sz < Math.abs(index)) { throw new IndexOutOfBoundsException(); index = sz + index; if (isMutable()) { addAll(index, subList); return this; if (isImmutable()) { int delta = subList.size(); ListBuilder<T> lb = new ListBuilder<T>(sz + delta); if (index > 0) { lb.addAll(subList(0, index)); lb.addAll(subList(index, sz)); C.List<T> l = C.newSizedList(sz + 1); if (index > 0) { l.addAll(subList(0, index)); l.addAll(subList(index, sz));
private C.List<T> unLazyPrepend(Enumeration<? extends T> enumeration) { if (isMutable()) { int pos = 0; while (enumeration.hasMoreElements()) { add(pos++, enumeration.nextElement()); } return this; } ListBuilder<T> lb = new ListBuilder<T>(size() * 2); lb.append(enumeration).append(this); return lb.toList(); }
@Override @SuppressWarnings("unchecked") public C.Sequence<T> append(Iterable<? extends T> iterable) { if (iterable instanceof C.List) { return appendList((C.List<T>) iterable); } else if (iterable instanceof C.Sequence) { return append((C.Sequence<T>) iterable); } else if (iterable instanceof Collection) { return append((Collection<? extends T>) iterable); } else if (isLazy()) { return CompositeSeq.of(this, IterableSeq.of(iterable)); } else { return unLazyAppend(iterable); } }
@Override public C.List<T> sorted() { if (size() == 0) return C.newList(); T t = get(0); C.List<T> l = copy(); if (!(t instanceof Comparable)) { return l; } Object[] a = l.toArray(); Arrays.sort(a); ListIterator<T> i = l.listIterator(); for (int j=0; j<a.length; j++) { i.next(); i.set((T)a[j]); } ((ListBase)l).setFeature(SORTED); sorted = true; return l; }
@Override public Lang.T2<C.List<T>, C.List<T>> split(final Lang.Function<? super T, Boolean> predicate) { final C.List<T> left = C.newList(); final C.List<T> right = C.newList(); accept(new $.Visitor<T>() { @Override public void visit(T t) throws Lang.Break { if (predicate.apply(t)) { left.add(t); } else { right.add(t); } } }); if (isImmutable() || isReadOnly()) { return $.T2(C.list(left), C.list(right)); } return $.T2(left, right); }
public boolean addAll(int index, Collection<? extends E> c) { if (index < 0 || index > size) throw new IndexOutOfBoundsException( "Index: " + index + ", Size: " + size); int cSize = c.size(); if (cSize == 0) return false; checkForComodification(); l.addAll(offset + index, c); expectedModCount = l.modCount(); size += cSize; modCount++; return true; }
public C.ReversibleSequence<T> append(C.ReversibleSequence<T> seq) { return appendReversibleSeq(seq); }
@Override public C.Sequence<T> append(Iterable<? extends T> iterable) { return super.append(iterable); }
@Override public T acceptLeft($.Visitor<? super Character> visitor) { super.acceptLeft(visitor); return me(); }
@Override public T acceptRight($.Visitor<? super Character> visitor) { super.acceptRight(visitor); return me(); }
@Override public C.List<T> append(C.List<T> list) { return appendList(list); }
private C.List<T> unLazyPrepend(Iterable<? extends T> iterable) { if (isMutable()) { int pos = 0; for (T t : iterable) { add(pos++, t); } return this; } // immutable if (isImmutable()) { ListBuilder<T> lb = new ListBuilder<T>(size() * 2); lb.append(iterable).append(this); return lb.toList(); } // mutable but read only C.List<T> l = C.newSizedList(size() * 2); l.addAll(iterable); l.addAll(this); return l; }