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

org.infinispan.stream.impl.intops.object.LimitOperation Maven / Gradle / Ivy

There is a newer version: 9.1.7.Final
Show newest version
package org.infinispan.stream.impl.intops.object;

import java.util.stream.Stream;

import org.infinispan.stream.impl.intops.IntermediateOperation;

/**
 * Performs limit operation on a regular {@link Stream}
 */
public class LimitOperation implements IntermediateOperation, S, Stream> {
   private final long limit;

   public LimitOperation(long limit) {
      if (limit <= 0) {
         throw new IllegalArgumentException("Limit must be greater than 0");
      }
      this.limit = limit;
   }

   @Override
   public Stream perform(Stream stream) {
      return stream.limit(limit);
   }

   public long getLimit() {
      return limit;
   }
}