private String columnDefinitions(List<DataTypeTest.Input<?>> inputs) { List<String> columnTypeDefinitions = inputs.stream() .map(DataTypeTest.Input::getInsertType) .collect(toList()); Stream<String> columnDefinitions = range(0, columnTypeDefinitions.size()) .mapToObj(i -> format("col_%d %s", i, columnTypeDefinitions.get(i))); return Joiner.on(",\n").join(columnDefinitions.iterator()); } }
public static int getConsumerAddressNum(String serviceUniqueName) { Set<ConsumerInvokerWrapper> providerInvokerWrapperSet = ProviderConsumerRegTable.getConsumerInvoker(serviceUniqueName); return providerInvokerWrapperSet.stream() .map(w -> w.getRegistryDirectory().getUrlInvokerMap()) .filter(Objects::nonNull) .mapToInt(Map::size).sum(); } }
public NodePartitionMap(List<Node> partitionToNode, ToIntFunction<Split> splitToBucket) { this.partitionToNode = ImmutableList.copyOf(requireNonNull(partitionToNode, "partitionToNode is null")); this.bucketToPartition = IntStream.range(0, partitionToNode.size()).toArray(); this.splitToBucket = requireNonNull(splitToBucket, "splitToBucket is null"); }
protected String formatInvokeError(String text, Object[] args) { String formattedArgs = IntStream.range(0, args.length) .mapToObj(i -> (args[i] != null ? "[" + i + "] [type=" + args[i].getClass().getName() + "] [value=" + args[i] + "]" : "[" + i + "] [null]")) .collect(Collectors.joining(",\n", " ", " ")); return text + "\n" + "Controller [" + getBeanType().getName() + "]\n" + "Method [" + getBridgedMethod().toGenericString() + "] " + "with argument values:\n" + formattedArgs; }
@Test public void add_counts_issue_per_component_on_leak_globally_and_per_assignee() { List<String> componentUuids = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> randomAlphabetic(3)).collect(Collectors.toList()); String assignee = randomAlphanumeric(10); componentUuids.stream() .map(componentUuid -> new DefaultIssue().setType(randomRuleTypeExceptHotspot).setComponentUuid(componentUuid).setAssigneeUuid(assignee).setNew(true)) .forEach(underTest::add); DistributedMetricStatsInt globalDistribution = underTest.globalStatistics().getDistributedMetricStats(Metric.COMPONENT); DistributedMetricStatsInt assigneeDistribution = underTest.getAssigneesStatistics().get(assignee).getDistributedMetricStats(Metric.COMPONENT); Stream.of(globalDistribution, assigneeDistribution) .forEach(distribution -> componentUuids.forEach(componentUuid -> assertStats(distribution, componentUuid, 1, 0, 1))); }
private String doHandlePropertySet(DbSession dbSession, SetRequest request, @Nullable PropertyDefinition definition, Optional<ComponentDto> component) { validatePropertySet(request, definition); int[] fieldIds = IntStream.rangeClosed(1, request.getFieldValues().size()).toArray(); String inlinedFieldKeys = IntStream.of(fieldIds).mapToObj(String::valueOf).collect(COMMA_JOINER); String key = persistedKey(request); Long componentId = component.isPresent() ? component.get().getId() : null; deleteSettings(dbSession, component, key); dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey(key).setValue(inlinedFieldKeys).setResourceId(componentId)); List<String> fieldValues = request.getFieldValues(); IntStream.of(fieldIds).boxed() .flatMap(i -> readOneFieldValues(fieldValues.get(i - 1), request.getKey()).entrySet().stream() .map(entry -> new KeyValue(key + "." + i + "." + entry.getKey(), entry.getValue()))) .forEach(keyValue -> dbClient.propertiesDao().saveProperty(dbSession, toFieldProperty(keyValue, componentId))); return inlinedFieldKeys; }
private void allSemaphoresCheckPermitCount(ConnectionSemaphore semaphore, int permitCount, int runnerCount) { List<SemaphoreRunner> runners = IntStream.range(0, runnerCount) .mapToObj(i -> new SemaphoreRunner(semaphore, PK)) .collect(Collectors.toList()); runners.forEach(SemaphoreRunner::acquire); runners.forEach(SemaphoreRunner::await); long tooManyConnectionsCount = runners.stream().map(SemaphoreRunner::getAcquireException) .filter(Objects::nonNull) .filter(e -> e instanceof IOException) .count(); long acquired = runners.stream().map(SemaphoreRunner::getAcquireException) .filter(Objects::isNull) .count(); int expectedAcquired = permitCount > 0 ? Math.min(permitCount, runnerCount) : runnerCount; assertEquals(expectedAcquired, acquired); assertEquals(runnerCount - acquired, tooManyConnectionsCount); }
@Test public void selectByKeys_throws_IAE_when_keys_contains_null() { Random random = new Random(); Set<String> keysIncludingANull = Stream.of( IntStream.range(0, random.nextInt(10)).mapToObj(i -> "b_" + i), Stream.of((String) null), IntStream.range(0, random.nextInt(10)).mapToObj(i -> "a_" + i)) .flatMap(s -> s) .collect(Collectors.toSet()); expectKeyNullOrEmptyIAE(); underTest.selectByKeys(dbSession, keysIncludingANull); }
/** * Aggregates the contents of n strings into a single list of tuples. * * @param inputs A list of strings. * @return A list of strings if none of the strings in the input is null or empty. * An empty list otherwise. */ public static List<String> zip(String... inputs) { if (inputs.length == 0) { return Collections.emptyList(); } OptionalInt min = Arrays.stream(inputs).mapToInt(str -> str == null ? 0 : str.length()).min(); if (!min.isPresent()) { return Collections.emptyList(); } return IntStream.range(0, min.getAsInt()) .mapToObj(elementIndex -> Arrays.stream(inputs) .map(input -> String.valueOf(input.charAt(elementIndex))) .collect(joining())) .collect(toList()); }
@Test public void shouldLimitListData() { //given List<List<Number>> integers = new ArrayList<>(); IntStream.range(1, 1000).forEach(x -> { List<Number> collect = IntStream.range(1, 1000).boxed().collect(Collectors.toList()); integers.add(collect); }); //when List<List<Number>> limitedData = sut.limitListData(integers); //then Assertions.assertThat(sut.totalPoints(limitedData).getAsInt()).isEqualTo(NUMBER_OF_NODES_TO_DISPLAY); } }
@Override public ScheduleResult schedule() { OptionalInt totalPartitions = OptionalInt.of(partitionToNode.size()); List<RemoteTask> newTasks = IntStream.range(0, partitionToNode.size()) .mapToObj(partition -> taskScheduler.scheduleTask(partitionToNode.get(partition), partition, totalPartitions)) .filter(Optional::isPresent) .map(Optional::get) .collect(toImmutableList()); return new ScheduleResult(true, newTasks, 0); } }
static List<Map<String, Object>> frames(final ClassLoader loader, final SourceLocator locator, final Throwable cause) { List<StackTraceElement> stacktrace = Arrays.asList(cause.getStackTrace()); int limit = IntStream.range(0, stacktrace.size()) .filter(i -> stacktrace.get(i).getClassName().equals(HANDLER)).findFirst() .orElse(stacktrace.size()); return stacktrace.stream() // trunk stack at HttpHandlerImpl (skip servers stack) .limit(limit) .map(e -> frame(loader, locator, cause, e)) .collect(Collectors.toList()); }
IntStream.range(0, ensembleSize).mapToObj( modelIdx -> getMapping( featuresVectorSize, featureSubspaceDim, environment.randomNumbersGenerator().nextLong())) .collect(Collectors.toList()) : null; List<DatasetTrainer<IgniteModel<Vector, Double>, L>> subspaceTrainers = IntStream.range(0, ensembleSize) .mapToObj(mdlIdx -> { AdaptableDatasetTrainer<Vector, Double, Vector, Double, ? extends IgniteModel, L> tr = AdaptableDatasetTrainer.of(trainers.get(mdlIdx)); .withEnvironmentBuilder(envBuilder); }) .map(CompositionUtils::unsafeCoerce) .collect(Collectors.toList()); subspaceTrainers)).afterTrainedModel(l -> aggregator.apply(l.stream().mapToDouble(Double::valueOf).toArray()));
private AttributeDataset dataset(NumericColumn<?> responseCol, AttributeType type, List<Column<?>> variableCols) { List<Column<?>> convertedVariableCols = variableCols.stream() .map(col -> col.type() == ColumnType.STRING ? col : table.nCol(col.name())) .collect(Collectors.toList()); Attribute responseAttribute = type == AttributeType.NOMINAL ? colAsNominalAttribute(responseCol) : new NumericAttribute(responseCol.name()); AttributeDataset dataset = new AttributeDataset(table.name(), convertedVariableCols.stream().map(col -> colAsAttribute(col)).toArray(Attribute[]::new), responseAttribute); for (int i = 0; i < responseCol.size(); i++) { final int r = i; double[] x = IntStream.range(0, convertedVariableCols.size()) .mapToDouble(c -> getDouble(convertedVariableCols.get(c), dataset.attributes()[c], r)) .toArray(); dataset.add(x, responseCol.getDouble(r)); } return dataset; }
.map( v -> materializeAnyResult( proxySpi, v ) ).collect( Collectors.toList() ) ) ); .collect( Collectors.toList() ) ); .collect( Collectors.toList() ) ); double[] array = ((DoubleStream) anyValue).toArray(); return Values.doubleArray( array ); return VirtualValues.fromList( ((IntStream) anyValue).mapToObj( i -> Values.booleanValue( i != 0 ) ).collect( Collectors.toList() ) );