Java Code Examples for org.apache.commons.collections4.CollectionUtils#find()

The following examples show how to use org.apache.commons.collections4.CollectionUtils#find() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TAPTargetTableModel.java    From dsworkbench with Apache License 2.0 6 votes vote down vote up
public void addRow(final Village pVillage, boolean pFake, int pAmount) {
    Object result = CollectionUtils.find(elements, new Predicate() {

        @Override
        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();
}
 
Example 2
Source File: REFSourceTableModel.java    From dsworkbench with Apache License 2.0 6 votes vote down vote up
public boolean removeRow(final Village pVillage, boolean pNotify) {

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

            @Override
            public boolean evaluate(Object o) {
                return ((REFSourceElement) o).getVillage().equals(pVillage);
            }
        });

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

        if (pNotify) {
            fireTableDataChanged();
        }
        return elem != null;
    }
 
Example 3
Source File: DEPFilterTableModel.java    From dsworkbench with Apache License 2.0 6 votes vote down vote up
public void addRow(final SupportSourceElement pElement, boolean pCheck) {

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

            @Override
            public boolean evaluate(Object o) {
                return ((SupportSourceElement) o).getVillage().equals(pElement.getVillage());
            }
        });

        if (result == null) {
            elements.add(pElement);
        }
        if (pCheck) {
            fireTableDataChanged();
        }
    }
 
Example 4
Source File: DefenseToolModel.java    From dsworkbench with Apache License 2.0 5 votes vote down vote up
public DefenseInformation findElement(final Village pTarget) {
    return (DefenseInformation) CollectionUtils.find(entries, new Predicate() {

        @Override
        public boolean evaluate(Object o) {
            return ((DefenseInformation) o).getTarget().equals(pTarget);
        }
    });
}
 
Example 5
Source File: CollectionSearchTests.java    From java_in_examples with Apache License 2.0 5 votes vote down vote up
private static void testSearch() {
    Collection<String> collection = Lists.newArrayList("2", "14", "3", "13", "43");
    MutableList<String> mutableList = FastList.newListWith("2", "14", "3", "13", "43");
    Iterable<String> iterable = collection;

    // найти элемент в неотсортированной коллекции
    String jdk = collection.stream().filter("13"::equals).findFirst().get();
    String guava = Iterables.find(iterable, "13"::equals);
    String apache = CollectionUtils.find(iterable, "13"::equals);
    String gs = mutableList.select("13"::equals).get(0);

    System.out.println("find = " + jdk + ":" + guava + ":" + apache + ":" + gs); // напечатает find = 13:13:13:13
}
 
Example 6
Source File: TestUtils.java    From codenjoy with GNU General Public License v3.0 5 votes vote down vote up
public static void assertContainsPlot(final int x, final int y, final Elements color, List<Plot> plots) {
    Object foundPlot = CollectionUtils.find(plots, (Predicate) object -> {
        Plot plot = (Plot) object;
        return plot.getColor() == color && plot.getX() == x && plot.getY() == y;
    });
    assertNotNull("Plot with coordinates (" + x + "," + y + ") color: " + color + " not found", foundPlot);
}
 
Example 7
Source File: SOSManager.java    From dsworkbench with Apache License 2.0 5 votes vote down vote up
public SOSRequest getRequest(final Tribe pTribe) {
  if (pTribe == null) {
    return null;
  }

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

    @Override
    public boolean evaluate(Object o) {
      return ((SOSRequest) o).getDefender().equals(pTribe);
    }
  });

  return (SOSRequest) result;
}
 
Example 8
Source File: StandardAttackManager.java    From dsworkbench with Apache License 2.0 5 votes vote down vote up
public boolean containsElementByIcon(final int pIcon) {
    Object result = CollectionUtils.find(getAllElements(), new Predicate() {

        @Override
        public boolean evaluate(Object o) {
            return ((StandardAttack) o).getIcon() == pIcon;
        }
    });

    return result != null;
}
 
Example 9
Source File: StandardAttackManager.java    From dsworkbench with Apache License 2.0 5 votes vote down vote up
public boolean containsElementByName(final String pName) {
    Object result = CollectionUtils.find(getAllElements(), new Predicate() {

        @Override
        public boolean evaluate(Object o) {
            return ((StandardAttack) o).getName().equals(pName);
        }
    });

    return result != null;
}
 
Example 10
Source File: StandardAttackManager.java    From dsworkbench with Apache License 2.0 5 votes vote down vote up
public StandardAttack getElementByIcon(final int pIcon) {
    Object result = CollectionUtils.find(getAllElements(), new Predicate() {

        @Override
        public boolean evaluate(Object o) {
            return ((StandardAttack) o).getIcon() == pIcon;
        }
    });

    return (StandardAttack) result;
}
 
Example 11
Source File: StandardAttackManager.java    From dsworkbench with Apache License 2.0 5 votes vote down vote up
public StandardAttack getElementByName(final String pName) {
    Object result = CollectionUtils.find(getAllElements(), new Predicate() {

        @Override
        public boolean evaluate(Object o) {
            return ((StandardAttack) o).getName().equals(pName);
        }
    });

    return (StandardAttack) result;
}
 
Example 12
Source File: REDSourceTableModel.java    From dsworkbench with Apache License 2.0 5 votes vote down vote up
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
        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();
}
 
Example 13
Source File: REDExtendedMerchantTableModel.java    From dsworkbench with Apache License 2.0 5 votes vote down vote up
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
        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();
    }
}
 
Example 14
Source File: DEPSourceTableModel.java    From dsworkbench with Apache License 2.0 5 votes vote down vote up
public void addRow(final Village pVillage, int pSupports) {
    Object existing = CollectionUtils.find(elements, new Predicate() {

        @Override
        public boolean evaluate(Object o) {
            return ((SupportSourceElement) o).getVillage().equals(pVillage);
        }
    });
    if (existing == null) {
        elements.add(new SupportSourceElement(pVillage, pSupports));
    }
}
 
Example 15
Source File: TAPTargetTableModel.java    From dsworkbench with Apache License 2.0 5 votes vote down vote up
public void decreaseRowCount(final Village pVillage) {
    Object result = CollectionUtils.find(elements, new Predicate() {

        @Override
        public boolean evaluate(Object o) {
            return ((TAPAttackTargetElement) o).getVillage().equals(pVillage);
        }
    });

    if (result != null) {
        TAPAttackTargetElement resultElem = (TAPAttackTargetElement) result;
        resultElem.removeAttack();
        fireTableDataChanged();
    }
}
 
Example 16
Source File: TAPTargetTableModel.java    From dsworkbench with Apache License 2.0 5 votes vote down vote up
public void increaseRowCount(final Village pVillage) {
    Object result = CollectionUtils.find(elements, new Predicate() {

        @Override
        public boolean evaluate(Object o) {
            return ((TAPAttackTargetElement) o).getVillage().equals(pVillage);
        }
    });

    if (result != null) {
        TAPAttackTargetElement resultElem = (TAPAttackTargetElement) result;
        resultElem.addAttack();
        fireTableDataChanged();
    }
}
 
Example 17
Source File: TestUtils.java    From codenjoy with GNU General Public License v3.0 5 votes vote down vote up
public static void assertContainsPlot(final int x, final int y,  List<Plot> plots) {
    Object foundPlot = CollectionUtils.find(plots, (Predicate) object -> {
        Plot plot = (Plot) object;
        return plot.getX() == x && plot.getY() == y;
    });
    assertNotNull("Plot with coordinates (" + x + "," + y + ") not found", foundPlot);
}
 
Example 18
Source File: DefenseInformation.java    From dsworkbench with Apache License 2.0 5 votes vote down vote up
public boolean addSupport(final Village pSource, UnitHolder pUnit, boolean pPrimary, boolean pMultiUse) {
    long runtime = DSCalculator.calculateMoveTimeInMillis(pSource, target, pUnit.getSpeed());
    boolean allowed = false;
    if (getFirstAttack().getTime() - runtime > System.currentTimeMillis() + DateUtils.MILLIS_PER_MINUTE) {
        //high priority
        allowed = true;
    } else if (getLastAttack().getTime() - runtime > System.currentTimeMillis() + DateUtils.MILLIS_PER_MINUTE) {
        //low priority
        allowed = !pPrimary;
    } else {// if (getLastAttack().getTime() - runtime < System.currentTimeMillis() - DateUtils.MILLIS_PER_MINUTE) {
        //impossible
    }
    if (allowed) {
        Object result = CollectionUtils.find(defenses, new Predicate() {

            @Override
            public boolean evaluate(Object o) {
                return ((Defense) o).getSupporter().equals(pSource);
            }
        });
        if (result == null || pMultiUse) {
            defenses.add(new Defense(this, pSource, pUnit));
            return true;
        }
    }
    return false;
}
 
Example 19
Source File: TargetInformation.java    From dsworkbench with Apache License 2.0 5 votes vote down vote up
public boolean addAttack(final Village pSource, final Date pArrive, UnitHolder pUnit, boolean fake, boolean snob) {
    List<TimedAttack> attacksFromSource = timedAttacks.get(pSource);
    if (attacksFromSource == null) {
        attacksFromSource = new LinkedList<>();
        timedAttacks.put(pSource, attacksFromSource);
    }
    
    Object result = CollectionUtils.find(attacksFromSource, new Predicate() {
        
        @Override
        public boolean evaluate(Object o) {
            TimedAttack t = (TimedAttack) o;
            return t.getSource().equals(pSource) && t.getlArriveTime().equals(pArrive.getTime());
        }
    });
    
    if (result == null) {
        TimedAttack a = new TimedAttack(pSource, pArrive);
        a.setPossibleFake(fake);
        a.setPossibleSnob(snob);
        a.setUnit(pUnit);
        attacksFromSource.add(a);
        Collections.sort(attacksFromSource, SOSRequest.ARRIVE_TIME_COMPARATOR);
        updateAttackInfo();
        return true;
    }
    return false;
}
 
Example 20
Source File: Abi.java    From web3sdk with Apache License 2.0 4 votes vote down vote up
private <T extends Entry> T find(
        Class<T> resultClass, final Entry.Type type, final Predicate<T> searchPredicate) {
    return (T)
            CollectionUtils.find(
                    this, entry -> entry.type == type && searchPredicate.evaluate((T) entry));
}