org.apache.commons.collections4.CollectionUtils.find()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(9.9k)|赞(0)|评价(0)|浏览(170)

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

CollectionUtils.find介绍

[英]Finds the first element in the given collection which matches the given predicate.

If the input collection or predicate is null, or no element of the collection matches the predicate, null is returned.
[中]查找给定集合中与给定谓词匹配的第一个元素。
如果输入集合或谓词为null,或者集合中没有与谓词匹配的元素,则返回null。

代码示例

代码示例来源:origin: ethereum/ethereumj

private <T extends Abi.Entry> T find(Class<T> resultClass, final Abi.Entry.Type type, final Predicate<T> searchPredicate) {
  return (T) CollectionUtils.find(this, entry -> entry.type == type && searchPredicate.evaluate((T) entry));
}

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

/**
 * From the list of all Skus in the database, gets a Sku that is active
 * @return
 */
public Sku getFirstActiveSku() {
  List<Sku> skus = skuDao.readAllSkus();
  return CollectionUtils.find(skus, new Predicate<Sku>() {
    @Override
    public boolean evaluate(Sku sku) {
      return sku.isActive();
    }
  });
}

代码示例来源:origin: com.github.rvesse/airline

public static <T> T find(Iterable<T> collection, Predicate<T> predicate, T defaultValue) {
  if (collection == null)
    return defaultValue;
  T value = CollectionUtils.find(collection, predicate);
  if (value == null)
    return defaultValue;
  return value;
}

代码示例来源:origin: info.magnolia.categorization/magnolia-categorization

/**
 * Checks if this new value is already in the categories list.
 */
protected boolean isExistValue(List<Value> categories, final String identifier) {
  final Object obj = CollectionUtils.find(categories, new Predicate() {
    @Override
    public boolean evaluate(Object object) {
      try {
        return StringUtils.equals(((Value) object).getString(), identifier);
      } catch (Exception e) {
        log.error("Couldn't access string value of object [{}]", object, e);
        return false;
      }
    }
  });
  return (obj != null);
}

代码示例来源:origin: platonai/pulsar

public Object get(String name) {
  Pair<String, Object> entry = CollectionUtils.find(paramsList, e -> e.getKey().equals(name));
  return entry == null ? null : entry.getValue();
}

代码示例来源:origin: com.haulmont.reports/reports-global

@MetaProperty
public BandDefinition getRootBandDefinition() {
  if (rootBandDefinition == null && bands != null && bands.size() > 0) {
    rootBandDefinition = (BandDefinition) CollectionUtils.find(bands, new Predicate() {
      @Override
      public boolean evaluate(Object object) {
        BandDefinition band = (BandDefinition) object;
        return band.getParentBandDefinition() == null;
      }
    });
  }
  return rootBandDefinition;
}

代码示例来源:origin: opencast/opencast

private boolean hasPropertyValue(EName property, final String language) {
 if (LANGUAGE_ANY.equals(language)) {
  return getValuesAsList(property).size() > 0;
 } else {
  return CollectionUtils.find(getValuesAsList(property), new Predicate() {
   @Override
   public boolean evaluate(Object o) {
    return equalLanguage(((CatalogEntry) o).getAttribute(XML_LANG_ATTR), language);
   }
  }) != null;
 }
}

代码示例来源:origin: org.nuiton.jaxx/jaxx-runtime-swing-session

public void add(final Component c, boolean replace) {
  if (c == null) {
    return;
  }
  final String cName = getComponentName(c);
  Object existingComponent = CollectionUtils.find(registeredComponent,
                          o -> {
                            Component comp = o;
                            String compName = getComponentName(comp);
                            return c.getClass().equals(comp.getClass())
                                && cName.equals(compName);
                          });
  if (existingComponent != null) {
    if (replace) {
      if (log.isDebugEnabled()) {
        log.debug("replacing the component fir path /" + cName);
      }
      remove((Component) existingComponent);
    } else {
      log.warn(String.format(
          "Component already added %s(%s)", c.getClass(), c.getName()));
      return;
    }
  }
  registeredComponent.add(c);
  walkThrowComponent("",
            Collections.singleton(c),
            new RestoreStateAction());
}

代码示例来源:origin: org.nuiton.jaxx/jaxx-runtime

Object existingComponent = CollectionUtils.find(registeredComponent,
                        new Predicate<Object>() {
                          @Override

代码示例来源:origin: com.github.rvesse/airline

/**
 * Make sure that if there are args with multiple names (e.g. "-log" and
 * "-verbose"), the usage will only display it once.
 */
@Test
public void repeatedArgs() {
  SingleCommand<Args1> parser = singleCommand(Args1.class);
  CommandMetadata command = CollectionUtils.find(Collections.singletonList(parser.getCommandMetadata()),
      new CommandFinder("Args1"));
  assertEquals(command.getAllOptions().size(), 8);
}

代码示例来源:origin: com.github.rvesse/airline

@Override
public <T> void finalValidate(ParseState<T> state, OptionMetadata option) {
  if (CollectionUtils.find(state.getParsedOptions(), new ParsedOptionFinder(option)) == null)
    throw new ParseOptionMissingException(AirlineUtils.first(option.getOptions()));
}

代码示例来源:origin: com.github.rvesse/airline

@Test
public void help_section_cli_01() {
  Cli<Object> cli = new Cli<>(CliWithSections.class);
  CommandFinder finder = new CommandFinder("Args1");
  CommandMetadata cmd = CollectionUtils.find(cli.getMetadata().getDefaultGroupCommands(), finder);
  Assert.assertNotNull(cmd);
  
  Assert.assertEquals(cmd.getHelpSections().size(), 1);
  HelpSection section = CollectionUtils.find(cmd.getHelpSections(), new HelpSectionFinder("Discussion"));
  Assert.assertTrue(section instanceof DiscussionSection);
  DiscussionSection discussion = (DiscussionSection) section;
  String[] paragraphs = discussion.getContentBlock(0);
  Assert.assertEquals(paragraphs.length, 2);
  Assert.assertEquals(paragraphs[0], "Foo");
  Assert.assertEquals(paragraphs[1], "Bar");
}

代码示例来源:origin: com.github.rvesse/airline

@Test
public void test_metadata() {
  Cli<GalaxyCommand> cli = createParser();
  
  GlobalMetadata<GalaxyCommand> global = cli.getMetadata();
  Assert.assertEquals(global.getOptions().size(), 2);
  
  CommandMetadata show = CollectionUtils.find(global.getDefaultGroupCommands(), new CommandFinder("show"));
  Assert.assertNotNull(show);
  Assert.assertEquals(show.getCommandOptions().size(), 6);
  Assert.assertEquals(show.getAllOptions().size(), 8);
}

代码示例来源:origin: com.github.rvesse/airline

@Test
public void help_section_cli_02() {
  Cli<Object> cli = new Cli<>(CliWithSections.class);
  CommandFinder finder = new CommandFinder("remove");
  CommandMetadata cmd = CollectionUtils.find(cli.getMetadata().getDefaultGroupCommands(), finder);
  Assert.assertNotNull(cmd);
  
  Assert.assertEquals(cmd.getHelpSections().size(), 2);
  HelpSection section = CollectionUtils.find(cmd.getHelpSections(), new HelpSectionFinder("Discussion"));
  Assert.assertTrue(section instanceof DiscussionSection);
  DiscussionSection discussion = (DiscussionSection) section;
  String[] paragraphs = discussion.getContentBlock(0);
  Assert.assertEquals(paragraphs.length, 1);
}

代码示例来源:origin: com.github.rvesse/airline

@Test
public void help_section_cli_builder_01() {
  //@formatter:off
  Cli<Object> cli = new CliBuilder<>("test")
      .withHelpSection(new DiscussionSection(new String[] { "A", "B" }))
      .withCommand(Args1.class)
      .build();
  //@formatter:on
  CommandFinder finder = new CommandFinder("Args1");
  CommandMetadata cmd = CollectionUtils.find(cli.getMetadata().getDefaultGroupCommands(), finder);
  Assert.assertNotNull(cmd);
  
  Assert.assertEquals(cmd.getHelpSections().size(), 1);
  HelpSection section = CollectionUtils.find(cmd.getHelpSections(), new HelpSectionFinder("Discussion"));
  Assert.assertTrue(section instanceof DiscussionSection);
  DiscussionSection discussion = (DiscussionSection) section;
  String[] paragraphs = discussion.getContentBlock(0);
  Assert.assertEquals(paragraphs.length, 2);
  Assert.assertEquals(paragraphs[0], "A");
  Assert.assertEquals(paragraphs[1], "B");
}

代码示例来源:origin: com.github.rvesse/airline

Assert.assertEquals(parentGroup.getSubGroups().size(), 2);
CommandGroupMetadata subGroup = CollectionUtils.find(parentGroup.getSubGroups(), new GroupFinder("bar"));
Assert.assertNotNull(subGroup);
Assert.assertEquals(parentGroup, subGroup.getParent());
Assert.assertEquals(subGroup.getDefaultCommand().getType(), Help.class);
subGroup = CollectionUtils.find(parentGroup.getSubGroups(), new GroupFinder("baz"));
Assert.assertNotNull(subGroup);
Assert.assertEquals(parentGroup, subGroup.getParent());

代码示例来源:origin: com.github.rvesse/airline

@Test
  public void help_section_cli_builder_02() {
    //@formatter:off
    Cli<Object> cli = new CliBuilder<>("test")
        .withHelpSection(new DiscussionSection(new String[] { "A", "B" }))
        .withCommand(Args1HidesDiscussion.class)
        .build();
    //@formatter:on
    CommandFinder finder = new CommandFinder("Args1");
    CommandMetadata cmd = CollectionUtils.find(cli.getMetadata().getDefaultGroupCommands(), finder);
    Assert.assertNotNull(cmd);
    Assert.assertEquals(cmd.getHelpSections().size(), 1);
    HelpSection section = CollectionUtils.find(cmd.getHelpSections(), new HelpSectionFinder("Discussion"));
    Assert.assertTrue(section instanceof BasicSection);
    BasicSection basic = (BasicSection) section;
    Assert.assertEquals(basic.getTitle(), "Discussion");
    Assert.assertEquals(basic.getFormat(), HelpFormat.NONE_PRINTABLE);
  }
}

代码示例来源:origin: com.github.rvesse/airline

Assert.assertEquals(parentGroup.getSubGroups().size(), 2);
CommandGroupMetadata subGroup = CollectionUtils.find(parentGroup.getSubGroups(), new GroupFinder("bar"));
Assert.assertNotNull(subGroup);
Assert.assertEquals(parentGroup, subGroup.getParent());
Assert.assertEquals(subGroup.getDefaultCommand().getType(), Help.class);
subGroup = CollectionUtils.find(parentGroup.getSubGroups(), new GroupFinder("baz"));
Assert.assertNotNull(subGroup);
Assert.assertEquals(parentGroup, subGroup.getParent());

代码示例来源:origin: com.github.rvesse/airline

CommandMetadata metadata = CollectionUtils.find(parser.getMetadata().getDefaultGroupCommands(), new CommandFinder("OptionsHidden"));
Assert.assertNotNull(metadata);
generator.usage("test", null, "OptionsHidden", metadata, null, out);

代码示例来源:origin: com.github.rvesse/airline

: new GroupFinder(tokens.peek());
CommandGroupMetadata group = CollectionUtils.find(state.getGlobal().getCommandGroups(), findGroupPredicate);
if (group != null) {
  tokens.next();
               : new GroupFinder(tokens.peek());
    group = CollectionUtils.find(state.getGroup().getSubGroups(), findGroupPredicate);
    if (group != null) {
      tokens.next();

相关文章