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

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

本文整理了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

/**
 * Returns true if the given iterable contains at least an item 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 {@link Lambda#forEach(Iterable)}.
 * @param iterable The iterable of objects to be filtered
 * @param matcher The hamcrest Matcher used to filter the given iterable
 * @return True if the given iterable contains at least an item that matches the given hamcrest Matcher false otherwise
 */
public static boolean exists(Object iterable, Matcher<?> matcher) {
  return selectFirst(iterable, matcher) != null;
}

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

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

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

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

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

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

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

@Override
public boolean compare(Neo4jConnectionCallback connection, InputStream dataset) throws NoSqlAssertionError,
    Throwable {
  DataParser dataParser = new DataParser();
  List<Object> expectedObjects = dataParser.readValues(dataset);
  Multimap<Class<?>, Object> expectedGroupByClass = groupByClass(expectedObjects);
  Set<Class<?>> expectedClasses = expectedGroupByClass.keySet();
  for (Class<?> expectedClass : expectedClasses) {
    Collection<Object> expectedObjectsByClass = expectedGroupByClass.get(expectedClass);
    List<Object> insertedObjects = findAndFetchAllEntitiesByClass(neo4jTemplate(connection), expectedClass);
    for (Object expectedObject : expectedObjectsByClass) {
      
      Object selectFirst = selectFirst(insertedObjects, equalTo(expectedObject));
      
      if(selectFirst == null) {
        throw new NoSqlAssertionError(String.format("Object %s is not found in graph.", expectedObject.toString()));
      }
      
    }
    
  }
  return true;
}

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

private long getCurrentId(Map<String, Long> stepReferences, Deque<Step> steps) {
  Long currentId;
  long max = Lambda.max(stepReferences);
  Map.Entry maxEntry = selectFirst(stepReferences.entrySet(),
      having(on(Map.Entry.class).getValue(), equalTo(max)));
  String referenceKey = (String) (maxEntry).getKey();
  Step step = null;
  for (Step stepItem : steps) {
    if (stepItem.getName().equals(referenceKey)) {
      step = stepItem;
      break;
    }
  }
  if (step == null || !step.isParallelLoop()) {
    // the reference is not a step or is not a parallel loop step
    currentId = max + NUMBER_OF_STEP_EXECUTION_STEPS;
  } else {
    //async step
    currentId = max + NUMBER_OF_STEP_EXECUTION_STEPS + NUMBER_OF_PARALLEL_LOOP_EXECUTION_STEPS;
  }
  return currentId;
}

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

private long getCurrentId(Map<String, Long> stepReferences, Deque<Step> steps) {
  Long currentId;
  long max = Lambda.max(stepReferences);
  Map.Entry maxEntry = selectFirst(stepReferences.entrySet(),
      having(on(Map.Entry.class).getValue(), equalTo(max)));
  String referenceKey = (String) (maxEntry).getKey();
  Step step = null;
  for (Step stepItem : steps) {
    if (stepItem.getName().equals(referenceKey)) {
      step = stepItem;
      break;
    }
  }
  if (step == null || !step.isParallelLoop()) {
    // the reference is not a step or is not a parallel loop step
    currentId = max + NUMBER_OF_STEP_EXECUTION_STEPS;
  } else {
    //async step
    currentId = max + NUMBER_OF_STEP_EXECUTION_STEPS + NUMBER_OF_PARALLEL_LOOP_EXECUTION_STEPS;
  }
  return currentId;
}

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

@Override
public boolean compare(Neo4jConnectionCallback connection, InputStream dataset) throws NoSqlAssertionError,
    Throwable {
  DataParser dataParser = new DataParser();
  List<Object> expectedObjects = dataParser.readValues(dataset);
  Multimap<Class<?>, Object> expectedGroupByClass = groupByClass(expectedObjects);
  Set<Class<?>> expectedClasses = expectedGroupByClass.keySet();
  for (Class<?> expectedClass : expectedClasses) {
    Collection<Object> expectedObjectsByClass = expectedGroupByClass.get(expectedClass);
    List<Object> insertedObjects = findAndFetchAllEntitiesByClass(neo4jTemplate(connection), expectedClass);
    for (Object expectedObject : expectedObjectsByClass) {
      
      Object selectFirst = selectFirst(insertedObjects, equalTo(expectedObject));
      
      if(selectFirst == null) {
        throw new NoSqlAssertionError(String.format("Object %s is not found in graph.", expectedObject.toString()));
      }
      
    }
    
  }
  return true;
}

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

private Map<String, Executable> fetchFlowReferences(Executable executable,
                              Collection<Executable> availableDependencies,
                              Map<String, Executable> resolvedDependencies) {
  for (String refId : executable.getDependencies()) {
    //if it is already in the references we do nothing
    if (resolvedDependencies.get(refId) == null) {
      Executable matchingRef = Lambda.selectFirst(availableDependencies, having(on(Executable.class).getId(), equalTo(refId)));
      if (matchingRef == null) {
        throw new RuntimeException("Reference: \'" + refId + "\' in executable: \'"
            + executable.getName() + "\', wasn't found in path");
      }
      //first we put the reference on the map
      resolvedDependencies.put(matchingRef.getId(), matchingRef);
      if (matchingRef.getType().equals(SlangTextualKeys.FLOW_TYPE)) {
        //if it is a flow  we recursively
        resolvedDependencies.putAll(fetchFlowReferences(matchingRef, availableDependencies, resolvedDependencies));
      }
    }
  }
  return resolvedDependencies;
}

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

private SelectiveMatcher findSelectiveMatcherByConnectionIdentifier(
    SelectiveMatcher[] selectiveMatchers) {
  return selectFirst(
      selectiveMatchers,
      having(on(SelectiveMatcher.class).identifier(),
          equalTo(identifier)).and(
          having(on(SelectiveMatcher.class).location(),
              notNullValue())));
}

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

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

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

private SelectiveMatcher findSelectiveMatcherByConnectionIdentifier(
    SelectiveMatcher[] selectiveMatchers) {
  return selectFirst(
      selectiveMatchers,
      having(on(SelectiveMatcher.class).identifier(),
          equalTo(identifier)).and(
          having(on(SelectiveMatcher.class).location(),
              notNullValue())));
}

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

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

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

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

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

private Map<String, Executable> fetchFlowReferences(Executable executable,
                          Collection<Executable> availableDependencies,
                          Map<String, Executable> resolvedDependencies) {
  for (String refId : executable.getExecutableDependencies()) {
    //if it is already in the references we do nothing
    if (resolvedDependencies.get(refId) == null) {
      Executable matchingRef = selectFirst(availableDependencies,
          having(on(Executable.class).getId(), equalTo(refId)));
      if (matchingRef == null) {
        throw new RuntimeException("Reference: \'" + refId + "\' in executable: \'" +
            executable.getName() + "\', wasn't found in path");
      }
      //first we put the reference on the map
      resolvedDependencies.put(matchingRef.getId(), matchingRef);
      if (matchingRef.getType().equals(SlangTextualKeys.FLOW_TYPE)) {
        //if it is a flow  we recursively
        resolvedDependencies
            .putAll(fetchFlowReferences(matchingRef, availableDependencies, resolvedDependencies));
      }
    }
  }
  return resolvedDependencies;
}

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

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

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

public ManagedRedisLifecycleManager getStartedServer(int port) {
  
  if(this.master.getPort() == port && this.master.isReady()) {
    return this.master;
  }
  
  
  return selectFirst(
      this.slaveServers,
      having(on(ManagedRedisLifecycleManager.class).getPort(),
          is(port)).and(having(on(ManagedRedisLifecycleManager.class).isReady(), is(true))));
}

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

public ManagedRedisLifecycleManager getStoppedServer(int port) {
  
  if(this.master.getPort() == port && !this.master.isReady()) {
    return this.master;
  }
  
  return selectFirst(
      this.slaveServers,
      having(on(ManagedRedisLifecycleManager.class).getPort(),
          is(port)).and(having(on(ManagedRedisLifecycleManager.class).isReady(), is(false))));
}

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

public ManagedRedisLifecycleManager getStartedServer(int port) {
  
  if(this.master.getPort() == port && this.master.isReady()) {
    return this.master;
  }
  
  
  return selectFirst(
      this.slaveServers,
      having(on(ManagedRedisLifecycleManager.class).getPort(),
          is(port)).and(having(on(ManagedRedisLifecycleManager.class).isReady(), is(true))));
}

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

public ManagedRedisLifecycleManager getStoppedServer(int port) {
  
  if(this.master.getPort() == port && !this.master.isReady()) {
    return this.master;
  }
  
  return selectFirst(
      this.slaveServers,
      having(on(ManagedRedisLifecycleManager.class).getPort(),
          is(port)).and(having(on(ManagedRedisLifecycleManager.class).isReady(), is(false))));
}

相关文章