下面列出了java.util.List#forEach ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@DeleteMapping
public void deleteByIds(@RequestParam(name = "ids") final String notificationIdsListStr)
{
userSession.assertLoggedIn();
final UserId adUserId = userSession.getLoggedUserId();
final List<String> notificationIds = Splitter.on(",")
.trimResults()
.omitEmptyStrings()
.splitToList(notificationIdsListStr);
if (notificationIds.isEmpty())
{
throw new AdempiereException("No IDs provided");
}
notificationIds.forEach(notificationId -> userNotificationsService.deleteNotification(adUserId, notificationId));
}
private void accept() throws IOException {
List<Future<?>> futures = new ArrayList<>(2);
while (!this.serverSocket.isClosed()) {
final Socket conn = this.serverSocket.accept();
log.info("client connected");
conn.setKeepAlive(true);
final Future<?> future = acceptConnection(conn);
futures.add(future);
}
futures.forEach(
(future) -> {
try {
future.get();
} catch (InterruptedException | ExecutionException e) {
log.catching(e);
}
});
}
@Test
public void testMixed(@DockerBrowser(type = CHROME) RemoteWebDriver chrome,
@DockerBrowser(type = CHROME, size = NUM_BROWSERS) List<RemoteWebDriver> driverList,
@DockerBrowser(type = FIREFOX) RemoteWebDriver firefox)
throws InterruptedException {
ExecutorService executorService = newFixedThreadPool(NUM_BROWSERS + 2);
CountDownLatch latch = new CountDownLatch(NUM_BROWSERS + 2);
driverList.forEach((driver) -> {
exercise(executorService, latch, driver);
});
exercise(executorService, latch, chrome);
exercise(executorService, latch, firefox);
latch.await(50, SECONDS);
// Thread.sleep(30000);
executorService.shutdown();
}
private static void check(List<String> dataSourceNames, List<String> bpNames) {
// 1. dataSourceNames 不能重复
for (int i = 0; i < dataSourceNames.size(); i++) {
if (Collections.frequency(dataSourceNames, dataSourceNames.get(i)) > 1) {
throw new RepositoryException("fastquery.json 配置文件中 \"dataSourceName\"=\"" + dataSourceNames.get(i) + "\" 不能重复出现.");
}
}
// 2. bpNames 不能重复
for (int j = 0; j < bpNames.size(); j++) {
if (Collections.frequency(bpNames, bpNames.get(j)) > 1) {
throw new RepositoryException("fastquery.json 配置文件中, basePackages中的元素\"" + bpNames.get(j) + "\"不能重复出现.");
}
}
// 3. 不能出现诸如: org.fastquery.db(包地址) 又配置了它的子类org.fastquery.db.AA
bpNames.forEach(b1 -> bpNames.forEach(b2 -> {
if (b2.startsWith(b1 + '.')) {
throw new RepositoryException("basePackages配置错误: " + b1 + " 已经包含了" + b2 + " 两者只能选一");
}
}));
}
@Test
public void testPreCompilationOfWherePredicate() {
final List<Traversal.Admin<?, ?>> traversals = Arrays.asList(
__.match(as("a").out().as("b"), as("c").where(P.neq("d"))).asAdmin(),
__.match(as("a").out().as("b"), where("c", P.neq("d"))).asAdmin());
assertEquals(1, new HashSet<>(traversals).size()); // the two patterns should pre-compile to the same traversal
traversals.forEach(traversal -> {
final MatchStep<?, ?> matchStep = (MatchStep<?, ?>) traversal.getStartStep();
//assertFalse(matchStep.getStartLabel().isPresent());
assertEquals(2, matchStep.getGlobalChildren().size());
Traversal.Admin<Object, Object> pattern = matchStep.getGlobalChildren().get(0);
assertEquals("a", ((MatchStep.MatchStartStep) pattern.getStartStep()).getSelectKey().get());
assertEquals(VertexStep.class, pattern.getStartStep().getNextStep().getClass());
assertEquals("b", ((MatchStep.MatchEndStep) pattern.getEndStep()).getMatchKey().get());
//
pattern = matchStep.getGlobalChildren().get(1);
assertEquals(MatchStep.MatchStartStep.class, pattern.getStartStep().getClass());
assertEquals("c", ((MatchStep.MatchStartStep) pattern.getStartStep()).getSelectKey().get());
assertEquals(WherePredicateStep.class, pattern.getStartStep().getNextStep().getClass());
assertEquals(MatchStep.MatchEndStep.class, pattern.getStartStep().getNextStep().getNextStep().getClass());
assertFalse(((WherePredicateStep<?>) pattern.getStartStep().getNextStep()).getStartKey().isPresent());
assertEquals("d", ((WherePredicateStep<?>) pattern.getStartStep().getNextStep()).getPredicate().get().getOriginalValue());
});
}
public Mono<BulkResponse> update(List<UpdatedRepresentation> updatedDocumentParts, RoutingKey routingKey) {
Preconditions.checkNotNull(updatedDocumentParts);
Preconditions.checkNotNull(routingKey);
BulkRequest request = new BulkRequest();
updatedDocumentParts.forEach(updatedDocumentPart -> request.add(
new UpdateRequest(aliasName.getValue(),
NodeMappingFactory.DEFAULT_MAPPING_NAME,
updatedDocumentPart.getId().asString())
.doc(updatedDocumentPart.getUpdatedDocumentPart(), XContentType.JSON)
.routing(routingKey.asString())));
return client.bulk(request, RequestOptions.DEFAULT)
.onErrorResume(ValidationException.class, exception -> {
LOGGER.warn("Error while updating index", exception);
return Mono.empty();
});
}
/**
* Deletes a list of tasks associated with deletion requests from the async delete queue using a
* retrier.
*/
private void deleteStaleTasksWithRetry(final List<DeletionRequest> deletionRequests) {
if (deletionRequests.isEmpty()) {
return;
}
final List<TaskHandle> tasks =
deletionRequests.stream().map(DeletionRequest::task).collect(toImmutableList());
retrier.callWithRetry(() -> queue.deleteTask(tasks), TransientFailureException.class);
deletionRequests.forEach(
deletionRequest ->
asyncTaskMetrics.recordAsyncFlowResult(
deletionRequest.getMetricOperationType(),
OperationResult.STALE,
deletionRequest.requestedTime()));
}
@ParameterizedTest
@EnumSource(RepositoryType.class)
void getMosaicsFromAccount(RepositoryType type) {
List<MosaicInfo> mosaicInfos = get(getMosaicRepository(type)
.search(new MosaicSearchCriteria().ownerAddress(testAccount.getAddress()))).getData();
Assertions.assertTrue(mosaicInfos.size() > 0);
mosaicInfos.forEach(this::assertMosaic);
Assertions.assertTrue(
mosaicInfos.stream().anyMatch(mosaicInfo -> mosaicInfo.getMosaicId().equals(mosaicId)));
}
@Override
public Boolean batchRemove(final List<String> ids, final String applicationName) {
if (CollectionUtils.isEmpty(ids) || StringUtils.isBlank(applicationName)) {
return Boolean.FALSE;
}
final String mongoTableName = RepositoryPathUtils.buildMongoTableName(applicationName);
ids.forEach(id -> {
Query query = new Query();
query.addCriteria(new Criteria("transId").is(id));
mongoTemplate.remove(query, mongoTableName);
});
return Boolean.TRUE;
}
public void setParams(List<ParameterConfig> params) {
this.params = params;
if (params != null) {
params.forEach(param -> {
if (param != null
&& io.joyrpc.util.StringUtils.isNotEmpty(param.getKey())
&& io.joyrpc.util.StringUtils.isNotEmpty(param.getValue())) {
String key = param.isHide() && !param.getKey().startsWith(".") ? "." + param.getKey() : param.getKey();
setParameter(key, param.getValue());
}
});
}
}
public static void resetReboot(SessionDataI sessionData) {
log.debug("The reboot parameter is reset to 0 and the reboot will be executed");
Unittype unittype = sessionData.getUnittype();
UnittypeParameter utp = unittype.getUnittypeParameters().getByName(SystemParameters.RESTART);
List<UnitParameter> unitParameters = new ArrayList<>();
UnitParameter up = new UnitParameter(utp, sessionData.getUnitId(), "0", sessionData.getProfile());
unitParameters.add(up);
unitParameters.forEach(sessionData.getUnit()::toWriteQueue);
}
public static List<String> getServiceNames(List<DescriptorProtos.FileDescriptorSet> fileDescriptorSets) {
List<String> serviceNames = new ArrayList<>();
fileDescriptorSets.forEach(fileDescriptorSet -> {
ServiceResolver serviceResolver = ServiceResolver.fromFileDescriptorSet(fileDescriptorSet);
serviceResolver.listServices().forEach(serviceDescriptor -> {
String serviceName = serviceDescriptor.getFullName();
if (blockServiceSet.contains(serviceName.toLowerCase())) {
return;
}
serviceNames.add(serviceName);
});
});
return serviceNames;
}
@Test
public void testBulkOps() throws Exception {
List<Cache<Long, String>> caches = new ArrayList<>();
caches.add(cacheOne);
caches.add(cacheTwo);
Map<Long, String> entriesMap = new HashMap<>();
entriesMap.put(1L, "one");
entriesMap.put(2L, "two");
entriesMap.put(3L, "three");
entriesMap.put(4L, "four");
entriesMap.put(5L, "five");
entriesMap.put(6L, "six");
caches.forEach(cache -> cache.putAll(entriesMap));
CLUSTER.getClusterControl().waitForRunningPassivesInStandby();
CLUSTER.getClusterControl().terminateActive();
Set<Long> keySet = entriesMap.keySet();
caches.forEach(cache -> {
Map<Long, String> all = cache.getAll(keySet);
assertThat(all.get(1L), is("one"));
assertThat(all.get(2L), is("two"));
assertThat(all.get(3L), is("three"));
assertThat(all.get(4L), is("four"));
assertThat(all.get(5L), is("five"));
assertThat(all.get(6L), is("six"));
});
}
/**
* Creates a variable active-limited strategy that applies an upper bound to all results.
*
* @param maxActiveGroups List of Maximum group sizes. Each group size represents a step.
* {@link #getNextGroup(Set, Set)}.
*/
public VariableBatchStrategy(
Ordering<T> ordering,
List<Integer> maxActiveGroups,
boolean rollingForward) {
this.ordering = Objects.requireNonNull(ordering);
this.rollingForward = rollingForward;
maxActiveGroups.forEach(x -> Preconditions.checkArgument(x > 0));
this.groupSizes = ImmutableList.copyOf(maxActiveGroups);
this.totalModInstanceCount = Optional.empty();
}
public List<Long> sortedValues(Comparator<String> keyComparator) {
final List<String> collect = data.keySet().stream().sorted(keyComparator).collect(Collectors.toList());
List<Long> values = new ArrayList<>(collect.size());
collect.forEach(key -> values.add(data.get(key)));
return values;
}
List<String> autocompleteFromObject(List<String> parts) {
List<String> lowPriorityCompletions = Arrays.asList("class","metaClass");
List<String> filteredCompletions = Arrays.asList("empty");
List<String> iterableOnlyCompletions = Arrays.asList("join(");
ArrayList<String> result = new ArrayList<String>();
try {
String bindingReference = parts.get(0);
Matcher m = indexedAccessPattern.matcher(bindingReference);
Object value;
if(m.matches()) {
List collValue = (List)binding.getVariable(m.group(1));
value = collValue.get(Integer.parseInt(m.group(2)));
}
else
value = binding.getVariable(bindingReference);
int i = 1;
for(; i<parts.size()-1; ++i) {
String partExpr = parts.get(i);
Matcher m2 = indexedAccessPattern.matcher(partExpr);
if(m2.matches()) {
value = PropertyUtils.getIndexedProperty(value, partExpr);
}
else {
value = PropertyUtils.getSimpleProperty(value, partExpr);
}
if(value == null) {
// We can't complete anything on it
// TODO: we could complete on the static type one day
return result;
}
}
String completionToken = parts.size() > 1 ? parts.get(parts.size()-1) : "";
List<String> properties = getObjectPropertyNames(value);
List<String> lowPri = new ArrayList<String>();
properties.forEach((String key) -> {
if(key.startsWith(completionToken)) {
if(lowPriorityCompletions.contains(key)) {
lowPri.add(key);
}
else {
result.add(key);
}
}
});
if(value instanceof Map) {
Map<String,?> mapValue = (Map<String,?>)value;
mapValue.keySet().stream()
.filter(k -> k.startsWith(completionToken))
.forEach(k -> result.add(k));
}
if(value instanceof Iterable || value instanceof Map) {
result.addAll(SUPPLEMENTARY_COLLECTION_COMPLETIONS);
result.addAll(iterableOnlyCompletions);
}
if(value instanceof String) {
result.addAll(STRING_COMPLETIONS);
}
// result.addAll(lowPri);
result.removeIf(v -> !v.startsWith(completionToken));
result.removeAll(filteredCompletions);
// Finally, add method names
result.addAll(getObjectMethodCompletions(value, completionToken));
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
e.printStackTrace();
}
return result;
}
private void addOutputs(ExtentTest node, List<String> outputs) {
outputs.forEach(output -> log(node, output));
}
@Override
protected List<S> replacement(List<S> population, List<S> offspringPopulation) {
// population and archive are always in sync
offspringPopulation.forEach(s -> archive.add(s));
return archive.getSolutionList();
}
protected void onPutMessage(String topic, String app, int partitionGroup, long startTime, List<WriteRequest> writeRequests) {
long now = SystemClock.now();
writeRequests.forEach(writeRequest -> {
brokerMonitor.onPutMessage(topic, app, partitionGroup, writeRequest.getPartition(), writeRequest.getBatchSize(), writeRequest.getBuffer().limit(), now - startTime);
});
}
public void addProtoPartList(List<PartInfo> partInfos) {
partInfos.forEach(partInfo -> partInfoList.add(new OmPartInfo(
partInfo.getPartNumber(), partInfo.getPartName(),
partInfo.getModificationTime(), partInfo.getSize())));
}