@SuppressWarnings("unchecked") private static <T> LinearSeq<T> toLinearSeq(Iterable<? extends T> iterable) { return (iterable instanceof LinearSeq) ? (LinearSeq<T>) iterable : List.ofAll(iterable); } }
@RequestMapping(value = "events/{circuitBreakerName}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public CircuitBreakerEventsEndpointResponse getEventsFilteredByCircuitBreakerName(@PathVariable("circuitBreakerName") String circuitBreakerName) { return new CircuitBreakerEventsEndpointResponse(eventConsumerRegistry.getEventConsumer(circuitBreakerName).getBufferedEvents() .filter(event -> event.getCircuitBreakerName().equals(circuitBreakerName)) .map(CircuitBreakerEventDTOFactory::createCircuitBreakerEventDTO).toJavaList()); }
/** * Alias for {@link List#of(Object)} * * @param <T> Component type of element. * @param element An element. * @return A new {@link List} instance containing the given element */ public static <T> Seq<T> Seq(T element) { return List.of(element); }
List<RetryEventDTO> eventsList = eventConsumerRegistry.getEventConsumer(retryName) .getBufferedEvents() .sorted(Comparator.comparing(RetryEvent::getCreationTime)) .map(RetryEventDTO::createRetryEventDTO).toJavaList(); d.success(new RetryEventsEndpointResponse(eventsList)); }).then(r -> ctx.render(Jackson.json(r))); List<RetryEventDTO> eventsList = eventConsumerRegistry.getEventConsumer(retryName) .getBufferedEvents() .sorted(Comparator.comparing(RetryEvent::getCreationTime)) .filter(event -> event.getEventType() == RetryEvent.Type.valueOf(eventType.toUpperCase())) .map(RetryEventDTO::createRetryEventDTO).toJavaList(); d.success(new RetryEventsEndpointResponse(eventsList)); }).then(r -> ctx.render(Jackson.json(r)));
@Test public void shouldPassPositiveDuration() { // Given final List<Long> positiveIntervals = List.of(10L, 99L, 981L); final List<Duration> positiveDurations = positiveIntervals.map(Duration::ofMillis); // When positiveDurations.forEach(IntervalFunction::of); positiveIntervals.forEach(IntervalFunction::of); positiveDurations.forEach(IntervalFunction::ofRandomized); positiveIntervals.forEach(IntervalFunction::ofRandomized); positiveDurations.forEach(IntervalFunction::ofExponentialBackoff); positiveIntervals.forEach(IntervalFunction::ofExponentialBackoff); positiveDurations.forEach(IntervalFunction::ofExponentialRandomBackoff); positiveIntervals.forEach(IntervalFunction::ofExponentialRandomBackoff); // Then should pass }
/** * Yields a result for elements of the cross product of the underlying List. * * @param f a function that maps an element of the cross product to a result * @param <R> type of the resulting {@code List} elements * @return an {@code List} of mapped results */ public <R> List<R> yield(Function<? super T1, ? extends R> f) { Objects.requireNonNull(f, "f is null"); return ts1.map(f); }
@SuppressWarnings("unchecked") static <T, U, R> Tree<R> zip(Node<T> node, java.util.Iterator<? extends U> that, BiFunction<? super T, ? super U, ? extends R> mapper) { if (!that.hasNext()) { return Empty.instance(); } else { final R value = mapper.apply(node.getValue(), that.next()); final io.vavr.collection.List<Node<R>> children = (io.vavr.collection.List<Node<R>>) (Object) node .getChildren() .map(child -> zip(child, that, mapper)) .filter(Tree::nonEmpty); return new Node<>(value, children); } }
@Override public final ClassFileLocatorSource classFileLocatorSource() { return new CflsExplicit( parts .map(ClassFileLocatorSource::classFileLocator) .transform(cflsl -> new ClassFileLocator.Compound(cflsl.toJavaList())) ); } }
@SuppressWarnings("unchecked") static <T, U> Tree<U> flatMap(Node<T> node, Function<? super T, ? extends Iterable<? extends U>> mapper) { final Tree<U> mapped = ofAll(mapper.apply(node.getValue())); if (mapped.isEmpty()) { return empty(); } else { final io.vavr.collection.List<Node<U>> children = (io.vavr.collection.List<Node<U>>) (Object) node .getChildren() .map(child -> flatMap(child, mapper)) .filter(Tree::nonEmpty); return of(mapped.get(), children.prependAll(mapped.getChildren())); } }
Objects.requireNonNull(futures, "futures is null"); Objects.requireNonNull(predicate, "predicate is null"); final List<Future<? extends T>> list = List.ofAll(futures); if (list.isEmpty()) { return successful(executor, Option.none()); } else { return run(executor, complete -> { final AtomicBoolean completed = new AtomicBoolean(false); final AtomicInteger count = new AtomicInteger(list.length()); list.forEach(future -> future.onComplete(result -> { synchronized (count) {
static <T> Stream<T> apply(io.vavr.collection.List<T> front, io.vavr.collection.List<T> rear, Stream<T> remaining) { if (remaining.isEmpty()) { return remaining; } else if (front.isEmpty()) { return apply(rear.reverse(), io.vavr.collection.List.empty(), remaining); } else { return Stream.cons(front.head(), () -> apply(front.tail(), rear.prepend(remaining.head()), remaining.tail())); } } }
/** * Creates a Queue that contains the elements of the given {@link java.util.stream.Stream}. * * @param javaStream A {@link java.util.stream.Stream} * @param <T> Component type of the Stream. * @return A Queue containing the given elements in the same order. */ public static <T> Queue<T> ofAll(java.util.stream.Stream<? extends T> javaStream) { Objects.requireNonNull(javaStream, "javaStream is null"); return new Queue<>(io.vavr.collection.List.ofAll(javaStream), io.vavr.collection.List.empty()); }
@Override public final StackManipulation stackManipulation() { return new StackManipulation.Compound( tokens.map(StackManipulationToken::stackManipulation).toJavaList() ); } }