package jetbrains.mps.internal.collections.runtime; /*Generated by MPS */ import java.util.Queue; import java.io.Serializable; import jetbrains.mps.internal.collections.runtime.impl.NullQueueSequence; import java.util.LinkedList; import java.util.Collection; import java.util.List; import java.util.Arrays; public class QueueSequence<T> extends AbstractQueueSequence<T> implements Queue<T>, IQueueSequence<T>, Serializable { private static final long serialVersionUID = 4639602987002419231L; protected QueueSequence(Queue<T> queue) { super(queue); } public static <U> IQueueSequence<U> fromQueue(Queue<U> queue) { if (Sequence.USE_NULL_SEQUENCE) { if (queue == null) { return NullQueueSequence.instance(); } } if (queue instanceof IQueueSequence) { return (IQueueSequence<U>) queue; } return new QueueSequence<U>(queue); } public static <U> IQueueSequence<U> fromIterable(Iterable<U> it) { if (Sequence.USE_NULL_SEQUENCE) { if (it == null) { return NullQueueSequence.instance(); } } if (it instanceof IQueueSequence) { return (IQueueSequence<U>) it; } Queue<U> queue = new LinkedList<U>(); if (Sequence.IGNORE_NULL_VALUES) { for (U u : it) { if (u != null) { queue.add(u); } } } else if (it instanceof Collection) { queue.addAll((Collection<? extends U>) it); } else { for (U u : it) { queue.add(u); } } return new QueueSequence<U>(queue); } public static <U> IQueueSequence<U> fromQueueAndArray(Queue<U> queue, U... array) { if (Sequence.NULL_ARRAY_IS_SINGLETON) { if (array == null) { array = (U[]) Sequence.nullSingletonArray(); } } if (Sequence.USE_NULL_SEQUENCE) { if (queue == null && array == null) { return NullQueueSequence.instance(); } else if (queue == null) { queue = new LinkedList<U>(); } else if (array == null) { if (queue instanceof IQueueSequence) { return (IQueueSequence<U>) queue; } return new QueueSequence<U>(queue); } } List<U> input = Arrays.asList(array); if (Sequence.IGNORE_NULL_VALUES) { for (U u : input) { if (u != null) { queue.add(u); } } } else { queue.addAll(input); } if (queue instanceof IQueueSequence) { return (IQueueSequence<U>) queue; } return new QueueSequence<U>(queue); } public static <U> IQueueSequence<U> fromQueueWithValues(Queue<U> queue, Iterable<? extends U> it) { Queue<U> tmp = queue; if (Sequence.USE_NULL_SEQUENCE) { if (queue == null && it == null) { return NullQueueSequence.instance(); } else if (queue == null) { tmp = new LinkedList<U>(); } else if (it == null) { return QueueSequence.fromQueue(queue); } } if (Sequence.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 IQueueSequence) { return (IQueueSequence<U>) tmp; } return new QueueSequence<U>(tmp); } }