当前位置: 首页>>代码示例>>Java>>正文


Java Collection.forEach方法代码示例

本文整理汇总了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;
}
 
开发者ID:oanda,项目名称:v20-java,代码行数:29,代码来源:ClientPrice.java

示例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;
}
 
开发者ID:oanda,项目名称:v20-java,代码行数:27,代码来源:AccountChanges.java

示例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()));
}
 
开发者ID:hekate-io,项目名称:hekate,代码行数:21,代码来源:DefaultFailureDetectorTest.java

示例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;
}
 
开发者ID:oanda,项目名称:v20-java,代码行数:28,代码来源:LiquidityRegenerationSchedule.java

示例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);
        }
    }

}
 
开发者ID:shlee89,项目名称:athena,代码行数:20,代码来源:IntentInstaller.java

示例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();
}
 
开发者ID:maximn,项目名称:capitalizing-on-a-great-idea,代码行数:21,代码来源:Bad.java

示例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);
}
 
开发者ID:fbiville,项目名称:hands-on-neo4j-devoxx-fr-2017,代码行数:23,代码来源:CypherSessionFallbackCommand.java

示例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;
}
 
开发者ID:hekate-io,项目名称:hekate,代码行数:22,代码来源:GossipManager.java

示例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);

  });

}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:21,代码来源:ArraySchemaMapper.java

示例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);
				});
}
 
开发者ID:xSzymo,项目名称:Spring-web-shop-project,代码行数:9,代码来源:CookiesService.java

示例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;
}
 
开发者ID:LtubSalad,项目名称:voogasalad-ltub,代码行数:12,代码来源:SkillMapSetter.java

示例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"));
    });
}
 
开发者ID:NationalSecurityAgency,项目名称:qonduit,代码行数:12,代码来源:AuthenticationServiceTest.java

示例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);
}
 
开发者ID:LIBCAS,项目名称:ARCLib,代码行数:9,代码来源:SchedulingInitializer.java

示例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));
}
 
开发者ID:LIBCAS,项目名称:ARCLib,代码行数:27,代码来源:NotificationService.java

示例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();
	}
 
开发者ID:xtf-cz,项目名称:xtf,代码行数:15,代码来源:LogCheckerUtils.java


注:本文中的java.util.Collection.forEach方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。