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

net.sf.staccatocommons.collections.stream.internal.ListStream 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;

import java.util.List;

import net.sf.staccatocommons.collections.stream.Stream;
import net.sf.staccatocommons.restrictions.check.NonNull;
import net.sf.staccatocommons.restrictions.check.NotNegative;
import net.sf.staccatocommons.restrictions.processing.EnforceRestrictions;
import net.sf.staccatocommons.restrictions.processing.IgnoreRestrictions;

/**
 * 
 * @author flbulgarelli
 * 
 * @param 
 */
@EnforceRestrictions
public class ListStream extends CollectionStream {

  /**
   * Creates a new {@link ListStream}
   * 
   * @param iterable
   *          the list to wrap
   */
  @IgnoreRestrictions
  public ListStream(@NonNull List iterable) {
    super(iterable);
  }

  @Override
  public final A get(int n) {
    return getList().get(n);
  }

  @Override
  public final int indexOf(A element) {
    return getList().indexOf(element);
  }

  protected List getList() {
    return (List) getCollection();
  }

  @Override
  public A last() {
    return get(size() - 1);
  }

  
  public Stream take(@NotNegative int amountOfElements) {
    return new ListStream(getList().subList(0, atMost(amountOfElements)));
  }

  public Stream drop(@NotNegative int amountOfElements) {
    return new ListStream(getList().subList(atMost(amountOfElements), size()));
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy