public static <U> ICollectionSequence<U> fromCollection(final Collection<U> coll) { if (AbstractSequence.USE_NULL_SEQUENCE) { if (coll == null) { return NullCollectionSequence.instance(); } } if (coll instanceof ICollectionSequence<?>) { return (ICollectionSequence<U>) coll; } return new CollectionSequence<U>() { @Override protected Collection<U> getCollection() { return coll; } }; }
public static <U> ICollectionSequence<U> fromCollectionAndArray(Collection<U> coll, U... array) { if (AbstractSequence.NULL_ARRAY_IS_SINGLETON) { if (array == null) { array = (U[]) Sequence.nullSingletonArray(); } } if (AbstractSequence.USE_NULL_SEQUENCE) { if (coll == null && array == null) { return NullCollectionSequence.instance(); } else if (coll == null) { coll = new ArrayList<U>(); } else if (array == null) { if (coll instanceof ICollectionSequence<?>) { return (ICollectionSequence<U>) coll; } final Collection<U> myColl = coll; return new CollectionSequence<U>() { @Override protected Collection<U> getCollection() { return myColl; } }; } } List<U> input = Arrays.asList(array); if (AbstractSequence.IGNORE_NULL_VALUES) { for (U u : input) { if (u != null) { coll.add(u); } } } else { coll.addAll(input); } if (coll instanceof ICollectionSequence<?>) { return (ICollectionSequence<U>) coll; } final Collection<U> myColl = coll; return new CollectionSequence<U>() { @Override protected Collection<U> getCollection() { return myColl; } }; }
public static <U> ICollectionSequence<U> fromCollectionWithValues( Collection<U> coll, Iterable<? extends U> it) { Collection<U> tmp = coll; if (AbstractSequence.USE_NULL_SEQUENCE) { if (coll == null && it == null) { return NullCollectionSequence.instance(); } else if (coll == null) { tmp = new ArrayList<U>(); } else if (it == null) { return CollectionSequence.fromCollection(coll); } } if (AbstractSequence.IGNORE_NULL_VALUES) { for (U u : it) { if (u != null) { tmp.add(u); } } } else if (it instanceof Collection<?>) { tmp.addAll((Collection<? extends U>) it); } else { for (U u : it) { tmp.add(u); } } if (tmp instanceof ICollectionSequence<?>) { return (ICollectionSequence<U>) tmp; } final Collection<U> myColl = tmp; return new CollectionSequence<U>() { @Override protected Collection<U> getCollection() { return myColl; } }; }