/** * Returns an immutable {@link C.List} from iterable * @param iterable the iterable * @param <T> the element type * @return an immutable list contains all elements from the iterable */ public static <T> C.List<T> toList(Iterable<? extends T> iterable) { if (iterable instanceof Collection) { return toList((Collection<T>) iterable); } ListBuilder<T> lb = new ListBuilder<T>(10); for (T t : iterable) { lb.add(t); } return lb.toList(); }
public ListBuilder<T> append(Collection<? extends T> col) { addAll(col); return this; }
/** * Returns an immutable {@link org.osgl.util.C.List} from an iterator * @param iterator the iterator * @param <T> the element type * @return an immutable list contains all elements from the iterator */ public static <T> C.List<T> toList(Iterator<? extends T> iterator) { ListBuilder<T> lb = new ListBuilder<T>(10); lb.append(iterator); return lb.toList(); }
public ListBuilder<T> append(T t1, T t2, T t3) { checkState(); size += 3; int sz = size; ensureCapacity(sz); Object[] data = buf; data[sz - 1] = t3; data[sz - 2] = t2; data[sz - 3] = t1; return this; }
@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; }
ListBuilder<T> lb = new ListBuilder<T>(sz + delta); if (index > 0) { lb.addAll(subList(0, index)); lb.addAll(subList); if (index < sz) { lb.addAll(subList(index, sz)); return lb.toList(); } else { C.List<T> l = C.newSizedList(sz + 1);
@Override public <R> C.List<R> flatMap($.Function<? super T, ? extends Iterable<? extends R>> mapper ) { // TODO: handle lazy operation int sz = size(); ListBuilder<R> lb = new ListBuilder<R>(sz * 3); forEach($.visitor($.f1(mapper).andThen(C.F.addAllTo(lb)))); return lb.toList(); }
public ListBuilder<T> append(T t) { add(t); return this; }
@Override public void visitEnd() { List<Router> routers = routers(); if (strings.isEmpty()) { strings.add(""); } /* * Note we need to schedule route registration after all app code scanned because we need the * parent context information be set on class meta info, which is done after controller scanning */ app().jobManager().on(SysEventId.APP_CODE_SCANNED, "WsEndpointAnnotationVisitor:registerRoute - " + registerRouteTaskCounter.getAndIncrement(), new RouteRegister(envMatches, C.list(H.Method.GET), strings, WsEndpoint.PSEUDO_METHOD, routers, classInfo, false, $.var(false))); super.visitEnd(); } };
public boolean addAll(int index, ListBuilder<? extends T> c) { checkState(); if (index < 0 || index > size) { throw new IndexOutOfBoundsException(); } if (null == c.buf) { return false; } int cSz = c.size(), oldSz = size; if (cSz == 0) { return false; } size += cSz; ensureCapacity(size); Object[] data = buf; if (index < oldSz) { System.arraycopy(data, index, data, index + cSz, oldSz - index); } ListBuilder<T> that = (ListBuilder<T>) c; Object[] newData = that.buf; System.arraycopy(newData, 0, data, index, cSz); return true; }
public ListBuilder<T> append(Iterator<? extends T> iterator) { checkState(); while (iterator.hasNext()) { append(iterator.next()); } return this; }
/** * Create an empty ListBuilder instance * * @param <T> the type of the element in the builder * @return a list builder */ public static <T> ListBuilder<T> create() { return new ListBuilder<T>(); }
@Override public int size() { checkState(); return size; }
/** * Returns an immutable {@link org.osgl.util.C.List} from an iterator * @param iterator the iterator * @param <T> the element type * @return an immutable list contains all elements from the iterator */ public static <T> C.List<T> toList(Iterator<? extends T> iterator) { ListBuilder<T> lb = new ListBuilder<T>(10); lb.append(iterator); return lb.toList(); }
@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; }