本文整理汇总了Java中java.util.Collection.forEach方法的典型用法代码示例。如果您正苦于以下问题:Java Collection.forEach方法的具体用法?Java Collection.forEach怎么用?Java Collection.forEach使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Collection
的用法示例。
在下文中一共展示了Collection.forEach方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setBids
import java.util.Collection; //导入方法依赖的package包/类
/**
* Set the Bids
* <p>
* The list of prices and liquidity available on the Instrument's bid side.
* It is possible for this list to be empty if there is no bid liquidity
* currently available for the Instrument in the Account.
* <p>
* @param bids the Bids
* @return {@link ClientPrice ClientPrice}
* @see PriceBucket
*/
public ClientPrice setBids(Collection<?> bids) {
ArrayList<PriceBucket> newBids = new ArrayList<PriceBucket>(bids.size());
bids.forEach((item) -> {
if (item instanceof PriceBucket)
{
newBids.add((PriceBucket) item);
}
else
{
throw new IllegalArgumentException(
item.getClass().getName() + " cannot be converted to a PriceBucket"
);
}
});
this.bids = newBids;
return this;
}
示例2: setTradesClosed
import java.util.Collection; //导入方法依赖的package包/类
/**
* Set the Trades Closed
* <p>
* The Trades closed.
* <p>
* @param tradesClosed the Trades Closed
* @return {@link AccountChanges AccountChanges}
* @see TradeSummary
*/
public AccountChanges setTradesClosed(Collection<?> tradesClosed) {
ArrayList<TradeSummary> newTradesClosed = new ArrayList<TradeSummary>(tradesClosed.size());
tradesClosed.forEach((item) -> {
if (item instanceof TradeSummary)
{
newTradesClosed.add((TradeSummary) item);
}
else
{
throw new IllegalArgumentException(
item.getClass().getName() + " cannot be converted to a TradeSummary"
);
}
});
this.tradesClosed = newTradesClosed;
return this;
}
示例3: testIsAliveWithAllAlive
import java.util.Collection; //导入方法依赖的package包/类
@Test
public void testIsAliveWithAllAlive() throws Exception {
Collection<ClusterAddress> heartbeats = mgr.heartbeatTick();
assertTrue(mgr.isAlive(n1));
assertTrue(mgr.isAlive(n2));
assertTrue(mgr.isAlive(n3));
assertTrue(mgr.isAlive(n4));
assertTrue(mgr.isAlive(newNode(100).address()));
heartbeats.forEach(mgr::onHeartbeatReply);
mgr.heartbeatTick();
assertTrue(mgr.isAlive(n1));
assertTrue(mgr.isAlive(n2));
assertTrue(mgr.isAlive(n3));
assertTrue(mgr.isAlive(n4));
assertTrue(mgr.isAlive(newNode(100).address()));
}
示例4: setSteps
import java.util.Collection; //导入方法依赖的package包/类
/**
* Set the Steps
* <p>
* The steps in the Liquidity Regeneration Schedule
* <p>
* @param steps the Steps
* @return {@link LiquidityRegenerationSchedule
* LiquidityRegenerationSchedule}
* @see LiquidityRegenerationScheduleStep
*/
public LiquidityRegenerationSchedule setSteps(Collection<?> steps) {
ArrayList<LiquidityRegenerationScheduleStep> newSteps = new ArrayList<LiquidityRegenerationScheduleStep>(steps.size());
steps.forEach((item) -> {
if (item instanceof LiquidityRegenerationScheduleStep)
{
newSteps.add((LiquidityRegenerationScheduleStep) item);
}
else
{
throw new IllegalArgumentException(
item.getClass().getName() + " cannot be converted to a LiquidityRegenerationScheduleStep"
);
}
});
this.steps = newSteps;
return this;
}
示例5: prepareIntents
import java.util.Collection; //导入方法依赖的package包/类
@Override
public void prepareIntents(List<Intent> intentsToApply, Direction direction) {
// FIXME do FlowRuleIntents have stages??? Can we do uninstall work in parallel? I think so.
builder.newStage();
List<Collection<FlowRule>> stages = intentsToApply.stream()
.map(x -> (FlowRuleIntent) x)
.map(FlowRuleIntent::flowRules)
.collect(Collectors.toList());
for (Collection<FlowRule> rules : stages) {
if (direction == Direction.ADD) {
rules.forEach(builder::add);
} else {
rules.forEach(builder::remove);
}
}
}
示例6: someMethod
import java.util.Collection; //导入方法依赖的package包/类
private void someMethod(Collection<String> collection) {
if (collection.isEmpty()) {
boolean res = collection.contains("ew");
System.out.println(res);
}
collection.forEach(new Consumer<String>() {
@Override
public void accept(String s) {
System.out.println(s);
}
});
List<Integer> arr = Arrays.asList(1, 2, 3);
boolean b = arr.stream().count() == 0;
boolean present = arr.stream().filter(i -> i > 2).findFirst().isPresent();
}
示例7: accept
import java.util.Collection; //导入方法依赖的package包/类
@Override
public void accept(TraineeSession session, String statement) {
Collection<CypherError> errors = statementValidator.validate(statement);
if (!errors.isEmpty()) {
logger.error("An error occurred with your query. See details below:");
errors.forEach(err -> logger.error(err.toString()));
return;
}
ExerciseValidation validation = validate(session, statement);
if (!validation.isSuccessful()) {
logger.error(validation.getReport());
return;
}
if (session.isCompleted()) {
logger.log("Congrats, you're done!!!", AttributedStyle.BOLD.background(AttributedStyle.GREEN));
return;
}
logger.log(validation.getReport());
logger.log("Now moving on to next exercise! See instructions below...");
session.getCurrentExercise().accept(logger);
}
示例8: batchGossip
import java.util.Collection; //导入方法依赖的package包/类
public Collection<UpdateBase> batchGossip(GossipPolicy policy) {
int batchSize;
if (localGossip.seen().size() < localGossip.members().size()) {
batchSize = GOSSIP_FANOUT_SIZE;
} else {
batchSize = 1;
}
Collection<UpdateBase> msgs = tryCoordinateAndGossip(batchSize, policy);
if (DEBUG) {
if (msgs.isEmpty()) {
log.trace("No nodes to gossip.");
} else {
msgs.forEach(msg -> log.debug("Will gossip [gossip={}]", msg));
}
}
return msgs;
}
示例9: queryAndValidate
import java.util.Collection; //导入方法依赖的package包/类
private void queryAndValidate(ArrayProperty property, GraphEntityContext graphEntityContext,
ValueContext valueContext, SchemaMapperAdapter schemaMapperAdapter,
ImmutableList.Builder<Object> builder) {
LdPathExecutor ldPathExecutor = graphEntityContext.getLdPathExecutor();
Collection<Value> queryResult = ldPathExecutor.ldPathQuery(valueContext.getValue(),
(String) property.getVendorExtensions().get(OpenApiSpecificationExtensions.LDPATH));
validateMinItems(property, queryResult);
validateMaxItems(property, queryResult);
queryResult.forEach(valueNext -> {
ValueContext newValueContext = valueContext.toBuilder().value(valueNext).build();
Optional innerPropertySolved =
Optional.fromNullable(schemaMapperAdapter.mapGraphValue(property.getItems(),
graphEntityContext, newValueContext, schemaMapperAdapter));
builder.add(innerPropertySolved);
});
}
示例10: save
import java.util.Collection; //导入方法依赖的package包/类
public void save(Collection<Cookies> cookie) {
if (cookie.size() > 0)
cookie.forEach(
x -> {
if (x != null)
save(x);
});
}
示例11: skillsToSelectors
import java.util.Collection; //导入方法依赖的package包/类
public List<SkillSetter<? extends Skill>> skillsToSelectors(Collection<Class<? extends Skill>> classes){
List<SkillSetter<? extends Skill>> selectors=new ArrayList<>();
classes.forEach((clazz)->{
try {
selectors.add(new SkillSetter(clazz, data));
} catch (UnsupportedTypeException e) {
AlertHandler.showError("Skill could not be set");
}
});
return selectors;
}
示例12: testX509AuthenticationLoginFailed
import java.util.Collection; //导入方法依赖的package包/类
@Test(expected = UsernameNotFoundException.class)
public void testX509AuthenticationLoginFailed() {
PreAuthenticatedAuthenticationToken token = new PreAuthenticatedAuthenticationToken("bad.example.com",
"doesn't matter what I put here");
Authentication auth = AuthenticationService.getAuthenticationManager().authenticate(token);
Collection<? extends GrantedAuthority> authorizations = auth.getAuthorities();
authorizations.forEach(a -> {
Assert.assertTrue(a.getAuthority().equals("D") || a.getAuthority().equals("E")
|| a.getAuthority().equals("F"));
});
}
示例13: onApplicationEvent
import java.util.Collection; //导入方法依赖的package包/类
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
Collection<Job> jobs = service.findAll();
log.info("Starting jobs...");
jobs.forEach(service::updateJobSchedule);
}
示例14: createMultiNotification
import java.util.Collection; //导入方法依赖的package包/类
/**
* Creates notification for users with specified role.
*
* This implementation is dependent on the use of internal role system !
*
* @param title Title of the notification
* @param description Body of the notification
* @param roleId Role the users needs to be in
* @param flash Is this flash notification
* @param emailing Is this email notification
*
* @deprecated Use createMultiNotificationWithPermission instead
*/
@Transactional
public void createMultiNotification(String title, String description, String roleId, boolean flash, boolean emailing) {
if (roleStore == null || assignedRoleService == null) {
throw new UnsupportedOperationException("Multi notification can be used only if internal role system is used");
}
Role role = roleStore.find(roleId);
notNull(role, () -> new MissingObject(Role.class, roleId));
Collection<String> userIds = assignedRoleService.getUsersWithRole(role);
userIds.forEach(userId -> createNotification(title, description, userId, flash, emailing));
}
示例15: findPatternsInLogs
import java.util.Collection; //导入方法依赖的package包/类
public static boolean[] findPatternsInLogs(Collection<Pod> pods, Pattern... patterns) throws IOException {
AtomicReference<boolean[]> foundRef = new AtomicReference<>(null);
pods.forEach(pod -> {
try {
foundRef.set(vectorOr(foundRef.get(), findPatternsInLogs(pod, patterns)));
} catch (Exception x) {
LOGGER.error("Failed to get logs for pod {}", pod.getMetadata().getLabels().get("name"), x);
}
});
return foundRef.get();
}