Example usage for org.apache.commons.collections4 Predicate Predicate

List of usage examples for org.apache.commons.collections4 Predicate Predicate

Introduction

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

Prototype

Predicate

Source Link

Usage

From source file:de.tor.tribes.util.TribeUtils.java

public static List<Tribe> filterTribes(List<Tribe> input, final String pFilter, Comparator<Tribe> pComparator) {
    if (pFilter == null) {
        return new ArrayList<>();
    }// w w w. j a  v a 2 s.c o m
    final String filter = pFilter.toLowerCase();

    if (filter.length() > 0) {
        CollectionUtils.filter(input, new Predicate() {
            @Override
            public boolean evaluate(Object o) {
                return ((Tribe) o).getName().toLowerCase().contains(filter);
            }
        });
    }

    if (pComparator != null) {
        Collections.sort(input, pComparator);
    }
    return input;
}

From source file:de.tor.tribes.util.AllyUtils.java

public static Ally[] getAlliesByFilter(final String pFilter, Comparator<Ally> pComparator) {
    if (pFilter == null) {
        return new Ally[0];
    }/*from   w  w  w . j  a v  a  2s.  co m*/
    final String filter = pFilter.toLowerCase();

    List<Ally> allies = new LinkedList<>();
    CollectionUtils.addAll(allies, DataHolder.getSingleton().getAllies().values());

    if (filter.length() > 0) {
        CollectionUtils.filter(allies, new Predicate() {

            @Override
            public boolean evaluate(Object o) {
                return pFilter.length() == 0 || ((Ally) o).getName().toLowerCase().contains(filter)
                        || ((Ally) o).getTag().toLowerCase().contains(filter);
            }
        });
    }

    if (pComparator != null) {
        Collections.sort(allies, pComparator);
    }
    allies.add(0, NoAlly.getSingleton());
    //result = (Ally[]) ArrayUtils.add(result, 0, NoAlly.getSingleton());
    return allies.toArray(new Ally[allies.size()]);
}

From source file:it.infn.ct.futuregateway.apiserver.inframanager.Utilities.java

/**
 * Retrieves the parameter value from a list.
 * If the parameter has multiple definition, and so multiple values, the
 * first occurrence is returned./* ww w  . j  av  a  2  s  . c  o m*/
 *
 * @param params The parameter list
 * @param name Parameter name
 * @return Parameter value or null is not present
 */
public static String getParamterValue(final List<Params> params, final String name) {
    Params tmpParam = IterableUtils.find(params, new Predicate<Params>() {
        @Override
        public boolean evaluate(final Params t) {
            return t.getName().equals(name);
        }
    });
    if (tmpParam != null) {
        return tmpParam.getValue();
    }
    return null;
}

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 www.  ja va2s . c o  m*/
        public boolean evaluate(Object o) {
            return o.equals(pVillage);
        }
    });

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

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/*from www  . 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  w  w  w .  j av  a2  s  .c  om*/
        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 av a2  s  .  co 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:it.infn.ct.futuregateway.apiserver.inframanager.Utilities.java

/**
 * Retrieves the parameter value from a list.
 * If the parameter has multiple definition, and so multiple values, the
 * first occurrence is returned./*from ww  w. j  av  a2s . c  om*/
 *
 * @param params The parameter list
 * @param name Parameter name
 * @param defaultValue Default value if the parameter is not defined
 * @return Parameter value or null is not present
 */
public static String getParamterValue(final List<Params> params, final String name, final String defaultValue) {
    Params tmpParam = IterableUtils.find(params, new Predicate<Params>() {
        @Override
        public boolean evaluate(final Params t) {
            return t.getName().equals(name);
        }
    });
    if (tmpParam != null) {
        return tmpParam.getValue();
    }
    return defaultValue;
}

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//w w  w .ja v  a2  s  .  c  om
        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 v a2  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);
    }
    fireTableDataChanged();
}