All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.staccatocommons.collections.stream.internal.algorithms.AppendStream Maven / Gradle / Ivy

/*
 Copyright (c) 2011, The Staccato-Commons Team

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU Lesser General Public License as published by
 the Free Software Foundation; version 3 of the License.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU Lesser General Public License for more details.
 */
package net.sf.staccatocommons.collections.stream.internal.algorithms;

import net.sf.staccatocommons.collections.stream.Stream;
import net.sf.staccatocommons.defs.Evaluable;
import net.sf.staccatocommons.iterators.AppendThriterator;
import net.sf.staccatocommons.iterators.thriter.Thriterator;
import net.sf.staccatocommons.lang.predicate.Equiv;

/**
 * @author flbulgarelli
 * 
 */
public class AppendStream extends AbstractAppendStream {

  private final A element;

  /**
   * Creates a new {@link AppendStream}
   */
  public AppendStream(Stream source, A element) {
    super(source);
    this.element = element;
  }

  public Thriterator iterator() {
    return new AppendThriterator(getSource().iterator(), element);
  }

  public boolean all(Evaluable predicate) {
    return getSource().all(predicate) && predicate.eval(element);
  }

  public boolean any(Evaluable predicate) {
    return getSource().any(predicate) || predicate.eval(element);
  }

  public boolean contains(A element) {
    return getSource().contains(element) || Equiv.equalNullSafe().eval(element, this.element);
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy