Example usage for org.apache.commons.collections4 CollectionUtils find

List of usage examples for org.apache.commons.collections4 CollectionUtils find

Introduction

In this page you can find the example usage for org.apache.commons.collections4 CollectionUtils find.

Prototype

@Deprecated
public static <T> T find(final Iterable<T> collection, final Predicate<? super T> predicate) 

Source Link

Document

Finds the first element in the given collection which matches the given predicate.

Usage

From source file:de.tor.tribes.ui.models.REFTargetTableModel.java

public void addRow(final Village pVillage) {
    Object result = CollectionUtils.find(elements, new Predicate() {

        @Override/*from   w ww .j a v  a2  s .  c  o m*/
        public boolean evaluate(Object o) {
            return o.equals(pVillage);
        }
    });

    if (result == null) {
        elements.add(pVillage);
        fireTableDataChanged();
    }
}

From source file:com.github.rvesse.airline.restrictions.common.IsRequiredRestriction.java

@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()));
}

From source file:de.tor.tribes.ui.models.DEPSourceTableModel.java

public void addRow(final Village pVillage, int pSupports) {
    Object existing = CollectionUtils.find(elements, new Predicate() {

        @Override// ww w  . j  a  va2 s  .  c  o  m
        public boolean evaluate(Object o) {
            return ((SupportSourceElement) o).getVillage().equals(pVillage);
        }
    });
    if (existing == null) {
        elements.add(new SupportSourceElement(pVillage, pSupports));
    }
}

From source file:de.tor.tribes.ui.models.DEPFilterTableModel.java

public void addRow(final SupportSourceElement pElement, boolean pCheck) {

    Object result = CollectionUtils.find(elements, new Predicate() {

        @Override/*from  www . j a v a 2s.com*/
        public boolean evaluate(Object o) {
            return ((SupportSourceElement) o).getVillage().equals(pElement.getVillage());
        }
    });

    if (result == null) {
        elements.add(pElement);
    }
    if (pCheck) {
        fireTableDataChanged();
    }
}

From source file:de.tor.tribes.ui.models.REFSourceTableModel.java

public boolean removeRow(final Village pVillage, boolean pNotify) {

    REFSourceElement elem = (REFSourceElement) CollectionUtils.find(elements, new Predicate() {

        @Override/* ww w  . j  a  v  a2 s .c  o  m*/
        public boolean evaluate(Object o) {
            return ((REFSourceElement) o).getVillage().equals(pVillage);
        }
    });

    if (elem != null) {
        elements.remove(elem);
    }

    if (pNotify) {
        fireTableDataChanged();
    }
    return elem != null;
}

From source file:de.tor.tribes.ui.models.TAPTargetTableModel.java

public void addRow(final Village pVillage, boolean pFake, int pAmount) {
    Object result = CollectionUtils.find(elements, new Predicate() {

        @Override//from  w ww  .  ja  va  2 s  . com
        public boolean evaluate(Object o) {
            return ((TAPAttackTargetElement) o).getVillage().equals(pVillage);
        }
    });

    if (result == null) {
        elements.add(new TAPAttackTargetElement(pVillage, pFake, pAmount));
    } else {
        TAPAttackTargetElement resultElem = (TAPAttackTargetElement) result;
        resultElem.setAttacks(pAmount);
        resultElem.setFake(pFake);
    }
    fireTableDataChanged();
}

From source file:de.tor.tribes.ui.models.REDSourceTableModel.java

public void addRow(final Village pVillage, int pStash, int pWood, int pClay, int pIron, int pAvailableMerchants,
        int pMerchants, int pAvailableFarm, int pOverallFarm, VillageMerchantInfo.Direction pDirection) {
    Object result = CollectionUtils.find(elements, new Predicate() {

        @Override/*from w w w. j a  va2 s.  c o m*/
        public boolean evaluate(Object o) {
            return ((VillageMerchantInfo) o).getVillage().equals(pVillage);
        }
    });

    if (result == null) {
        VillageMerchantInfo vmi = new VillageMerchantInfo(pVillage, pStash, pWood, pClay, pIron,
                pAvailableMerchants, pMerchants, pAvailableFarm, pOverallFarm);
        vmi.setDirection(pDirection);
        elements.add(vmi);
    } else {
        VillageMerchantInfo resultElem = (VillageMerchantInfo) result;
        resultElem.setWoodStock(pWood);
        resultElem.setClayStock(pClay);
        resultElem.setIronStock(pIron);
        resultElem.setStashCapacity(pStash);
        resultElem.setAvailableMerchants(pAvailableMerchants);
        resultElem.setOverallMerchants(pMerchants);
        resultElem.setAvailableFarm(pAvailableFarm);
        resultElem.setOverallFarm(pOverallFarm);
        resultElem.setDirection(pDirection);
    }
    fireTableDataChanged();
}

From source file:com.github.rvesse.airline.help.sections.TestHelpSectionDetection.java

@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);//from   ww w .  j  av  a 2  s  . c  o  m

    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");
}

From source file:de.tor.tribes.ui.models.REDExtendedMerchantTableModel.java

public void addRow(final Village pVillage, int pStash, int pWood, int pClay, int pIron, int pAvailableMerchants,
        int pMerchants, int pAvailableFarm, int pOverallFarm, VillageMerchantInfo.Direction pDirection,
        boolean pCheck) {
    Object result = CollectionUtils.find(elements, new Predicate() {

        @Override//from ww w .ja  va 2  s .co m
        public boolean evaluate(Object o) {
            return ((VillageMerchantInfo) o).getVillage().equals(pVillage);
        }
    });

    if (result == null) {
        VillageMerchantInfo vmi = new VillageMerchantInfo(pVillage, pStash, pWood, pClay, pIron,
                pAvailableMerchants, pMerchants, pAvailableFarm, pOverallFarm);
        vmi.setDirection(pDirection);
        elements.add(vmi);
    } else {
        VillageMerchantInfo resultElem = (VillageMerchantInfo) result;
        resultElem.setWoodStock(pWood);
        resultElem.setClayStock(pClay);
        resultElem.setIronStock(pIron);
        resultElem.setStashCapacity(pStash);
        resultElem.setAvailableMerchants(pAvailableMerchants);
        resultElem.setOverallMerchants(pMerchants);
        resultElem.setAvailableFarm(pAvailableFarm);
        resultElem.setOverallFarm(pOverallFarm);
        resultElem.setDirection(pDirection);
    }
    if (pCheck) {
        fireTableDataChanged();
    }
}

From source file:de.micromata.tpsb.doc.parser.ParserResult.java

public FileInfo getFileInfoForFullQualifiedClassName(final String fullQualifiedClassName) {
    return CollectionUtils.find(this, new Predicate<FileInfo>() {
        @Override//from   w ww  .  j a  v a  2  s  . co m
        public boolean evaluate(FileInfo fInfo) {
            return StringUtils.equals(fullQualifiedClassName, fInfo.getClassName());
        }
    });
}