@RequestMapping(value = "events", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public CircuitBreakerEventsEndpointResponse getAllCircuitBreakerEvents() { return new CircuitBreakerEventsEndpointResponse(eventConsumerRegistry.getAllEventConsumer() .flatMap(CircularEventConsumer::getBufferedEvents) .sorted(Comparator.comparing(CircuitBreakerEvent::getCreationTime)) .map(CircuitBreakerEventDTOFactory::createCircuitBreakerEventDTO).toJavaList()); }
@RequestMapping(value = "stream/events/{circuitBreakerName}", produces = MEDIA_TYPE_TEXT_EVENT_STREAM) public SseEmitter getEventsStreamFilteredByCircuitBreakerName(@PathVariable("circuitBreakerName") String circuitBreakerName) { CircuitBreaker circuitBreaker = circuitBreakerRegistry.getAllCircuitBreakers() .find(cb -> cb.getName().equals(circuitBreakerName)) .getOrElseThrow(() -> new IllegalArgumentException(String.format("circuit breaker with name %s not found", circuitBreakerName))); return CircuitBreakerEventEmitter.createSseEmitter(toFlux(circuitBreaker.getEventPublisher())); }
/** * fun insert (x, ts as t1 :: t2 :: rest) = * * if rank t1 = rank t2 then skewLink(Node(x,0,[]),t1,t2) :: rest * * else Node (x,0,[]) :: ts * * | insert (x, ts) = Node (x,0,[]) :: ts **/ static <T> Seq<Node<T>> insert(Comparator<? super T> comparator, T element, Seq<Node<T>> forest) { final Node<T> tree = Node.of(element, 0, io.vavr.collection.List.empty()); if (forest.size() >= 2) { final Seq<Node<T>> tail = forest.tail(); final Node<T> t1 = forest.head(), t2 = tail.head(); if (t1.rank == t2.rank) { return tree.skewLink(comparator, t1, t2).appendTo(tail.tail()); } } return tree.appendTo(forest); }
static <T, U extends Seq<T>, V extends Seq<U>> V transpose(V matrix, Function<Iterable<U>, V> rowFactory, Function<T[], U> columnFactory) { Objects.requireNonNull(matrix, "matrix is null"); if (matrix.isEmpty() || (matrix.length() == 1 && matrix.head().length() <= 1)) { return matrix; } else { return transposeNonEmptyMatrix(matrix, rowFactory, columnFactory); } }
static <T, S extends Seq<T>> S shuffle(S source, Function<? super Iterable<T>, S> ofAll) { if (source.length() <= 1) { return source; } final java.util.List<T> list = source.toJavaList(); java.util.Collections.shuffle(list); return ofAll.apply(list); }
@Override public Object invoke() { List<String> names = rateLimiterRegistry.getAllRateLimiters() .map(RateLimiter::getName).sorted().toJavaList(); return ResponseEntity.ok(new RateLimiterEndpointResponse(names)); } }
/** * Traverses this tree values in a specific order. * Syntactic sugar for {@code traverse(order).map(Node::getValue)}. * * @param order the tree traversal order * @return A sequence of the tree values. * @throws java.lang.NullPointerException if order is null */ default Seq<T> values(Order order) { return traverse(order).map(Node::getValue); }
@Nonnull @Override public Object convert(Object source) { if (source instanceof io.vavr.collection.Seq) { return ((io.vavr.collection.Seq<?>) source).toJavaList(); } if (source instanceof io.vavr.collection.Map) { return ((io.vavr.collection.Map<?, ?>) source).toJavaMap(); } if (source instanceof io.vavr.collection.Set) { return ((io.vavr.collection.Set<?>) source).toJavaSet(); } throw new IllegalArgumentException("Unsupported Javaslang collection " + source.getClass()); } }
@SuppressWarnings("unchecked") static <T, S extends Seq<T>> Iterator<S> crossProduct(S empty, S seq, int power) { if (power < 0) { return Iterator.empty(); } else { return Iterator.range(0, power) .foldLeft(Iterator.of(empty), (product, ignored) -> product.flatMap(el -> seq.map(t -> (S) el.append(t)))); } }
@SuppressWarnings("unchecked") static <T, C extends Seq<T>> C rotateLeft(C source, int n) { if (source.isEmpty() || n == 0) { return source; } else if (n < 0) { return rotateRight(source, -n); } else { int len = source.length(); int m = n % len; if (m == 0) { return source; } else { return (C) source.drop(m).appendAll(source.take(m)); } } }
@SuppressWarnings("unchecked") static <T, C extends Seq<T>> C rotateRight(C source, int n) { if (source.isEmpty() || n == 0) { return source; } else if (n < 0) { return rotateLeft(source, -n); } else { int len = source.length(); int m = n % len; if (m == 0) { return source; } else { return (C) source.takeRight(m).appendAll(source.dropRight(m)); } } }
@Override public Map<String, ?> unapply(Map<String, ?> config, String keyPrefix) { Map<String, ?> tableTypeMap = config.filterKeys(key -> key.startsWith("table.type.")); java.util.List<String> tableTypes = tableTypeMap.values().map(Object::toString).toSet().toJavaList(); Map<String, Object> remappedConfig = ((Map<String, Object>) config).removeAll(tableTypeMap.keySet()).put("table.types", tableTypes); return remappedConfig; } }
/** * Validates that all the columns specified in the collection of items * to sort are actually contained and identifiable in the DataTable. * * @param table The table to sort. * @param sortItems The collection of sort items. * @return Returns validation as a Try. */ private static Try<Seq<IDataColumn>> validateSortColumnIdentity(DataTable table, Seq<SortItem> sortItems) { // Validate we can get the column for all sort items. Seq<Try<IDataColumn>> checkCols = sortItems.map(item -> item.getColumn(table)); // Any failures, return error else return columns. return checkCols.find(Try::isFailure).isEmpty() ? Try.success(checkCols.map(Try::get)) : DataTableException.tryError("Column for Sort Item not found."); }
public static <T> String serializeToPropertiesString(T object) { ConfigRenderOptions configRenderOptions = ConfigRenderOptions.defaults().setJson(false).setOriginComments(false).setFormatted(false); return serialize(object).map( keyValueTuple -> keyValueTuple._1 + "=" + ConfigValueFactory.fromAnyRef(keyValueTuple._2) .render(configRenderOptions)).sorted().mkString("\n"); }
private static <T, U extends Seq<T>, V extends Seq<U>> V transposeNonEmptyMatrix(V matrix, Function<Iterable<U>, V> rowFactory, Function<T[], U> columnFactory) { final int newHeight = matrix.head().size(), newWidth = matrix.size(); @SuppressWarnings("unchecked") final T[][] results = (T[][]) new Object[newHeight][newWidth]; if (matrix.exists(r -> r.size() != newHeight)) { throw new IllegalArgumentException("the parameter `matrix` is invalid!"); } int rowIndex = 0; for (U row : matrix) { int columnIndex = 0; for (T element : row) { results[columnIndex][rowIndex] = element; columnIndex++; } rowIndex++; } return rowFactory.apply(Iterator.of(results).map(columnFactory)); }
@SuppressWarnings("unchecked") static <V> boolean equals(Seq<V> source, Object object) { if (object == source) { return true; } else if (source != null && object instanceof Seq) { final Seq<V> seq = (Seq<V>) object; return seq.size() == source.size() && areEqual(source, seq); } else { return false; } }
@SuppressWarnings("unchecked") @Override public void sort(Comparator<? super T> comparator) { Objects.requireNonNull(comparator, "comparator is null"); if (isEmpty()) { return; } setDelegate(() -> (C) getDelegate().sorted(comparator)); }
@Test public void testMultimapValuesAddAnotherDataSetShouldHave2ValuesForEachKey() { final int offset = 10; for (Integer i : expected) { dbRule.getSharedHandle().execute("insert into something(name, intValue) values (?, ?)", Integer.toString(i + offset) + "asString", i); } Multimap<Integer, String> result = dbRule.getSharedHandle().createQuery("select intValue, name from something") .collectInto(new GenericType<Multimap<Integer, String>>() {}); assertThat(result).hasSize(expected.size() * 2); expected.forEach(i -> assertThat(result.apply(i)) .containsOnlyElementsOf(List.of(i + "asString", (i + 10) + "asString"))); } }