ch.lambdaj.Lambda.selectFirst()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(10.3k)|赞(0)|评价(0)|浏览(328)

本文整理了Java中ch.lambdaj.Lambda.selectFirst()方法的一些代码示例,展示了Lambda.selectFirst()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Lambda.selectFirst()方法的具体详情如下:
包路径:ch.lambdaj.Lambda
类名称:Lambda
方法名:selectFirst

Lambda.selectFirst介绍

[英]Selects the first object in the given iterable that matches the given hamcrest Matcher Actually it handles also Maps, Arrays and Iterator by collecting their values. Note that this method accepts an Object in order to be used in conjunction with the Lambda#forEach(Iterable).
[中]选择给定iterable中与给定hamcrest匹配器匹配的第一个对象,该匹配器实际上还通过收集其值来处理映射、数组和迭代器。请注意,此方法接受一个对象,以便与Lambda#forEach(Iterable)一起使用。

代码示例

代码示例来源:origin: mariofusco/lambdaj

  1. /**
  2. * Returns true if the given iterable contains at least an item that matches the given hamcrest Matcher
  3. * Actually it handles also Maps, Arrays and Iterator by collecting their values.
  4. * Note that this method accepts an Object in order to be used in conjunction with the {@link Lambda#forEach(Iterable)}.
  5. * @param iterable The iterable of objects to be filtered
  6. * @param matcher The hamcrest Matcher used to filter the given iterable
  7. * @return True if the given iterable contains at least an item that matches the given hamcrest Matcher false otherwise
  8. */
  9. public static boolean exists(Object iterable, Matcher<?> matcher) {
  10. return selectFirst(iterable, matcher) != null;
  11. }

代码示例来源:origin: mariofusco/lambdaj

  1. /**
  2. * Selects the first object in this iterable that matches the given hamcrest Matcher
  3. * @param matcher The hamcrest Matcher used to retain the given iterable
  4. * @return The first object in the given iterable that matches the given hamcrest Matcher or null if there is no such object
  5. */
  6. public T first(Matcher<?> matcher) {
  7. return (T)Lambda.selectFirst(getInner(), matcher);
  8. }

代码示例来源:origin: net.flexmojos.oss/flexmojos-maven-plugin

  1. protected Artifact getDependency( Matcher<? extends Artifact>... matchers )
  2. {
  3. return selectFirst(getDependencies(), allOf(matchers));
  4. }

代码示例来源:origin: CloudSlang/cloud-slang

  1. private LanguageEventData selectByEventType(List<LanguageEventData> data, String eventType) {
  2. return selectFirst(data, having(on(LanguageEventData.class).getEventType(), equalTo(eventType)));
  3. }

代码示例来源:origin: lordofthejars/nosql-unit

  1. @Override
  2. public boolean compare(Neo4jConnectionCallback connection, InputStream dataset) throws NoSqlAssertionError,
  3. Throwable {
  4. DataParser dataParser = new DataParser();
  5. List<Object> expectedObjects = dataParser.readValues(dataset);
  6. Multimap<Class<?>, Object> expectedGroupByClass = groupByClass(expectedObjects);
  7. Set<Class<?>> expectedClasses = expectedGroupByClass.keySet();
  8. for (Class<?> expectedClass : expectedClasses) {
  9. Collection<Object> expectedObjectsByClass = expectedGroupByClass.get(expectedClass);
  10. List<Object> insertedObjects = findAndFetchAllEntitiesByClass(neo4jTemplate(connection), expectedClass);
  11. for (Object expectedObject : expectedObjectsByClass) {
  12. Object selectFirst = selectFirst(insertedObjects, equalTo(expectedObject));
  13. if(selectFirst == null) {
  14. throw new NoSqlAssertionError(String.format("Object %s is not found in graph.", expectedObject.toString()));
  15. }
  16. }
  17. }
  18. return true;
  19. }

代码示例来源:origin: CloudSlang/cloud-slang

  1. private long getCurrentId(Map<String, Long> stepReferences, Deque<Step> steps) {
  2. Long currentId;
  3. long max = Lambda.max(stepReferences);
  4. Map.Entry maxEntry = selectFirst(stepReferences.entrySet(),
  5. having(on(Map.Entry.class).getValue(), equalTo(max)));
  6. String referenceKey = (String) (maxEntry).getKey();
  7. Step step = null;
  8. for (Step stepItem : steps) {
  9. if (stepItem.getName().equals(referenceKey)) {
  10. step = stepItem;
  11. break;
  12. }
  13. }
  14. if (step == null || !step.isParallelLoop()) {
  15. // the reference is not a step or is not a parallel loop step
  16. currentId = max + NUMBER_OF_STEP_EXECUTION_STEPS;
  17. } else {
  18. //async step
  19. currentId = max + NUMBER_OF_STEP_EXECUTION_STEPS + NUMBER_OF_PARALLEL_LOOP_EXECUTION_STEPS;
  20. }
  21. return currentId;
  22. }

代码示例来源:origin: io.cloudslang.lang/cloudslang-compiler

  1. private long getCurrentId(Map<String, Long> stepReferences, Deque<Step> steps) {
  2. Long currentId;
  3. long max = Lambda.max(stepReferences);
  4. Map.Entry maxEntry = selectFirst(stepReferences.entrySet(),
  5. having(on(Map.Entry.class).getValue(), equalTo(max)));
  6. String referenceKey = (String) (maxEntry).getKey();
  7. Step step = null;
  8. for (Step stepItem : steps) {
  9. if (stepItem.getName().equals(referenceKey)) {
  10. step = stepItem;
  11. break;
  12. }
  13. }
  14. if (step == null || !step.isParallelLoop()) {
  15. // the reference is not a step or is not a parallel loop step
  16. currentId = max + NUMBER_OF_STEP_EXECUTION_STEPS;
  17. } else {
  18. //async step
  19. currentId = max + NUMBER_OF_STEP_EXECUTION_STEPS + NUMBER_OF_PARALLEL_LOOP_EXECUTION_STEPS;
  20. }
  21. return currentId;
  22. }

代码示例来源:origin: com.lordofthejars/nosqlunit-neo4j

  1. @Override
  2. public boolean compare(Neo4jConnectionCallback connection, InputStream dataset) throws NoSqlAssertionError,
  3. Throwable {
  4. DataParser dataParser = new DataParser();
  5. List<Object> expectedObjects = dataParser.readValues(dataset);
  6. Multimap<Class<?>, Object> expectedGroupByClass = groupByClass(expectedObjects);
  7. Set<Class<?>> expectedClasses = expectedGroupByClass.keySet();
  8. for (Class<?> expectedClass : expectedClasses) {
  9. Collection<Object> expectedObjectsByClass = expectedGroupByClass.get(expectedClass);
  10. List<Object> insertedObjects = findAndFetchAllEntitiesByClass(neo4jTemplate(connection), expectedClass);
  11. for (Object expectedObject : expectedObjectsByClass) {
  12. Object selectFirst = selectFirst(insertedObjects, equalTo(expectedObject));
  13. if(selectFirst == null) {
  14. throw new NoSqlAssertionError(String.format("Object %s is not found in graph.", expectedObject.toString()));
  15. }
  16. }
  17. }
  18. return true;
  19. }

代码示例来源:origin: io.openscore.lang/score-lang-compiler

  1. private Map<String, Executable> fetchFlowReferences(Executable executable,
  2. Collection<Executable> availableDependencies,
  3. Map<String, Executable> resolvedDependencies) {
  4. for (String refId : executable.getDependencies()) {
  5. //if it is already in the references we do nothing
  6. if (resolvedDependencies.get(refId) == null) {
  7. Executable matchingRef = Lambda.selectFirst(availableDependencies, having(on(Executable.class).getId(), equalTo(refId)));
  8. if (matchingRef == null) {
  9. throw new RuntimeException("Reference: \'" + refId + "\' in executable: \'"
  10. + executable.getName() + "\', wasn't found in path");
  11. }
  12. //first we put the reference on the map
  13. resolvedDependencies.put(matchingRef.getId(), matchingRef);
  14. if (matchingRef.getType().equals(SlangTextualKeys.FLOW_TYPE)) {
  15. //if it is a flow we recursively
  16. resolvedDependencies.putAll(fetchFlowReferences(matchingRef, availableDependencies, resolvedDependencies));
  17. }
  18. }
  19. }
  20. return resolvedDependencies;
  21. }

代码示例来源:origin: com.lordofthejars/nosqlunit-core

  1. private SelectiveMatcher findSelectiveMatcherByConnectionIdentifier(
  2. SelectiveMatcher[] selectiveMatchers) {
  3. return selectFirst(
  4. selectiveMatchers,
  5. having(on(SelectiveMatcher.class).identifier(),
  6. equalTo(identifier)).and(
  7. having(on(SelectiveMatcher.class).location(),
  8. notNullValue())));
  9. }

代码示例来源:origin: lordofthejars/nosql-unit

  1. public ManagedMongoDbLifecycleManager getStartedServer(int port) {
  2. return selectFirst(
  3. this.servers,
  4. having(on(ManagedMongoDbLifecycleManager.class).getPort(),
  5. is(port)).and(having(on(ManagedMongoDbLifecycleManager.class).isReady(), is(true))));
  6. }

代码示例来源:origin: lordofthejars/nosql-unit

  1. private SelectiveMatcher findSelectiveMatcherByConnectionIdentifier(
  2. SelectiveMatcher[] selectiveMatchers) {
  3. return selectFirst(
  4. selectiveMatchers,
  5. having(on(SelectiveMatcher.class).identifier(),
  6. equalTo(identifier)).and(
  7. having(on(SelectiveMatcher.class).location(),
  8. notNullValue())));
  9. }

代码示例来源:origin: lordofthejars/nosql-unit

  1. public ManagedMongoDbLifecycleManager getStoppedServer(int port) {
  2. return selectFirst(
  3. this.servers,
  4. having(on(ManagedMongoDbLifecycleManager.class).getPort(),
  5. is(port)).and(having(on(ManagedMongoDbLifecycleManager.class).isReady(), is(false))));
  6. }

代码示例来源:origin: com.lordofthejars/nosqlunit-mongodb

  1. public ManagedMongoDbLifecycleManager getStartedServer(int port) {
  2. return selectFirst(
  3. this.servers,
  4. having(on(ManagedMongoDbLifecycleManager.class).getPort(),
  5. is(port)).and(having(on(ManagedMongoDbLifecycleManager.class).isReady(), is(true))));
  6. }

代码示例来源:origin: CloudSlang/cloud-slang

  1. private Map<String, Executable> fetchFlowReferences(Executable executable,
  2. Collection<Executable> availableDependencies,
  3. Map<String, Executable> resolvedDependencies) {
  4. for (String refId : executable.getExecutableDependencies()) {
  5. //if it is already in the references we do nothing
  6. if (resolvedDependencies.get(refId) == null) {
  7. Executable matchingRef = selectFirst(availableDependencies,
  8. having(on(Executable.class).getId(), equalTo(refId)));
  9. if (matchingRef == null) {
  10. throw new RuntimeException("Reference: \'" + refId + "\' in executable: \'" +
  11. executable.getName() + "\', wasn't found in path");
  12. }
  13. //first we put the reference on the map
  14. resolvedDependencies.put(matchingRef.getId(), matchingRef);
  15. if (matchingRef.getType().equals(SlangTextualKeys.FLOW_TYPE)) {
  16. //if it is a flow we recursively
  17. resolvedDependencies
  18. .putAll(fetchFlowReferences(matchingRef, availableDependencies, resolvedDependencies));
  19. }
  20. }
  21. }
  22. return resolvedDependencies;
  23. }

代码示例来源:origin: com.lordofthejars/nosqlunit-mongodb

  1. public ManagedMongoDbLifecycleManager getStoppedServer(int port) {
  2. return selectFirst(
  3. this.servers,
  4. having(on(ManagedMongoDbLifecycleManager.class).getPort(),
  5. is(port)).and(having(on(ManagedMongoDbLifecycleManager.class).isReady(), is(false))));
  6. }

代码示例来源:origin: lordofthejars/nosql-unit

  1. public ManagedRedisLifecycleManager getStartedServer(int port) {
  2. if(this.master.getPort() == port && this.master.isReady()) {
  3. return this.master;
  4. }
  5. return selectFirst(
  6. this.slaveServers,
  7. having(on(ManagedRedisLifecycleManager.class).getPort(),
  8. is(port)).and(having(on(ManagedRedisLifecycleManager.class).isReady(), is(true))));
  9. }

代码示例来源:origin: lordofthejars/nosql-unit

  1. public ManagedRedisLifecycleManager getStoppedServer(int port) {
  2. if(this.master.getPort() == port && !this.master.isReady()) {
  3. return this.master;
  4. }
  5. return selectFirst(
  6. this.slaveServers,
  7. having(on(ManagedRedisLifecycleManager.class).getPort(),
  8. is(port)).and(having(on(ManagedRedisLifecycleManager.class).isReady(), is(false))));
  9. }

代码示例来源:origin: com.lordofthejars/nosqlunit-redis

  1. public ManagedRedisLifecycleManager getStartedServer(int port) {
  2. if(this.master.getPort() == port && this.master.isReady()) {
  3. return this.master;
  4. }
  5. return selectFirst(
  6. this.slaveServers,
  7. having(on(ManagedRedisLifecycleManager.class).getPort(),
  8. is(port)).and(having(on(ManagedRedisLifecycleManager.class).isReady(), is(true))));
  9. }

代码示例来源:origin: com.lordofthejars/nosqlunit-redis

  1. public ManagedRedisLifecycleManager getStoppedServer(int port) {
  2. if(this.master.getPort() == port && !this.master.isReady()) {
  3. return this.master;
  4. }
  5. return selectFirst(
  6. this.slaveServers,
  7. having(on(ManagedRedisLifecycleManager.class).getPort(),
  8. is(port)).and(having(on(ManagedRedisLifecycleManager.class).isReady(), is(false))));
  9. }

相关文章