@Test public void limit() { final Engine<DoubleGene, Double> engine = Engine .builder( gt -> gt.gene().allele(), DoubleChromosome.of(0, 1)) .build(); final AtomicLong count = new AtomicLong(); final EvolutionResult<DoubleGene, Double> result = engine.stream() .limit(new CountLimit(1000)) .limit(new CountLimit(100)) .limit(new CountLimit(10)) .limit(new CountLimit(100)) .peek(r -> count.incrementAndGet()) .collect(EvolutionResult.toBestEvolutionResult()); Assert.assertEquals(count.get(), 10L); Assert.assertEquals(result.totalGenerations(), 10L); }
@Override public EvolutionStream<G, C> limit(final Predicate<? super EvolutionResult<G, C>> proceed) { return new EvolutionStreamImpl<>( LimitSpliterator.of(_spliterator, proceed), isParallel() ); }
EvolutionStreamImpl extends StreamProxy<EvolutionResult<G, C>> implements EvolutionStream<G, C> { @Override public EvolutionStream<G, C> limit(final Predicate<? super EvolutionResult<G, C>> proceed) { return new EvolutionStreamImpl<>( LimitSpliterator.of(_spliterator, proceed), isParallel() ); } }
EvolutionStreamImpl extends StreamProxy<EvolutionResult<G, C>> implements EvolutionStream<G, C> { @Override public EvolutionStream<G, C> limit(final Predicate<? super EvolutionResult<G, C>> proceed) { return new EvolutionStreamImpl<>( LimitSpliterator.of(_spliterator, proceed), isParallel() ); } EvolutionStreamImpl(
		final Spliterator<EvolutionResult<G, C>> spliterator,
		final boolean parallel
	);  EvolutionStreamImpl(
		final Supplier<EvolutionStart<G, C>> start,
		final Evolution<G, C> evolution
	); }
EvolutionStreamImpl extends StreamProxy<EvolutionResult<G, C>> implements EvolutionStream<G, C> { @Override public EvolutionStream<G, C> limit(final Predicate<? super EvolutionResult<G, C>> proceed) { return new EvolutionStreamImpl<>( LimitSpliterator.of(_spliterator, proceed), isParallel() ); } EvolutionStreamImpl(
		final Spliterator<EvolutionResult<G, C>> spliterator,
		final boolean parallel
	);  EvolutionStreamImpl(
		final Supplier<EvolutionStart<G, C>> start,
		final Evolution<G, C> evolution
	); @Override EvolutionStream<G, C> limit(final Predicate<? super EvolutionResult<G, C>> proceed); static EvolutionStreamImpl<G, C> of(
		final Supplier<EvolutionStart<G, C>> start,
		final Function<
			? super EvolutionStart<G, C>,
			? extends Evolution<G, C>> evolution
	); }
EvolutionStreamImpl extends StreamProxy<EvolutionResult<G, C>> implements EvolutionStream<G, C> { @Override public EvolutionStream<G, C> limit(final Predicate<? super EvolutionResult<G, C>> proceed) { return new EvolutionStreamImpl<>( LimitSpliterator.of(_spliterator, proceed), isParallel() ); } EvolutionStreamImpl(
		final Spliterator<EvolutionResult<G, C>> spliterator,
		final boolean parallel
	);  EvolutionStreamImpl(
		final Supplier<EvolutionStart<G, C>> start,
		final Evolution<G, C> evolution
	); @Override EvolutionStream<G, C> limit(final Predicate<? super EvolutionResult<G, C>> proceed); static EvolutionStreamImpl<G, C> of(
		final Supplier<EvolutionStart<G, C>> start,
		final Function<
			? super EvolutionStart<G, C>,
			? extends Evolution<G, C>> evolution
	);  }