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)); }
/** * 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(); } }); }
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; }
/** * 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); }
public Object get(String name) { Pair<String, Object> entry = CollectionUtils.find(paramsList, e -> e.getKey().equals(name)); return entry == null ? null : entry.getValue(); }
@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; }
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; } }
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()); }
Object existingComponent = CollectionUtils.find(registeredComponent, new Predicate<Object>() { @Override
/** * 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); }
@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())); }
@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"); }
@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); }
@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); }
@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"); }
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());
@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); } }
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());
CommandMetadata metadata = CollectionUtils.find(parser.getMetadata().getDefaultGroupCommands(), new CommandFinder("OptionsHidden")); Assert.assertNotNull(metadata); generator.usage("test", null, "OptionsHidden", metadata, null, out);
: 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();