List of usage examples for java.util.function BiPredicate BiPredicate
BiPredicate
From source file:dk.dma.ais.view.rest.QueryParameterHelper.java
public BiPredicate<AisPacketSource, TargetInfo> getSourceAndTargetPredicate() { final Predicate<AisPacketSource> ps = getSourcePredicate(); final Predicate<TargetInfo> pt = getTargetPredicate(); return new BiPredicate<AisPacketSource, TargetInfo>() { @Override//from w ww . j a v a2 s . co m public boolean test(AisPacketSource t, TargetInfo u) { return ps.test(t) && pt.test(u); } }; }
From source file:com.diversityarrays.kdxplore.trials.TrialViewPanel.java
private void doRemoveTraitInstancesWithoutSamples() { TableModel model = trialDataTable.getModel(); if (model instanceof TrialData) { TrialData trialData = (TrialData) model; TraitNameStyle tns = trialData.trial.getTraitNameStyle(); List<Integer> modelRows = GuiUtil.getSelectedModelRows(trialDataTable); List<TraitInstance> withData = new ArrayList<>(); List<TraitInstance> withoutData = new ArrayList<>(); for (Integer row : modelRows) { TraitInstance ti = trialData.getTraitInstanceAt(row); int traitId = ti.getTraitId(); int instanceNumber = ti.getInstanceNumber(); boolean[] anyScored = new boolean[1]; BiPredicate<SampleGroup, KdxSample> sampleVisitor = new BiPredicate<SampleGroup, KdxSample>() { @Override/*from w w w . j av a 2 s . c om*/ public boolean test(SampleGroup sg, KdxSample s) { if (traitId != s.getTraitId()) { return true; // not the correct trait } if (instanceNumber != s.getTraitInstanceNumber()) { return true; // not the correct trait } // Ok - it is for this traitInstance if (s.hasBeenScored()) { anyScored[0] = true; return false; } return true; // keep looking for scored samples } }; trialData.visitSampleGroupSamples(sampleVisitor); if (anyScored[0]) { withData.add(ti); } else { withoutData.add(ti); } } if (withoutData.isEmpty()) { if (withData.isEmpty()) { MsgBox.warn(TrialViewPanel.this, "Nothing to do!", "Remove Trait/Instances"); } else { String s = withData.stream().map(ti -> tns.makeTraitInstanceName(ti)) .collect(Collectors.joining("</li><li>", "<html>With Data:<ul><li>", "</li></ul>")); MsgBox.warn(TrialViewPanel.this, s, "Cannot remove Traits with Data"); } } else { String s = withoutData.stream().map(ti -> tns.makeTraitInstanceName(ti)) .collect(Collectors.joining("</li><li>", "<html><ul><li>", "</li></ul>")); int answer = JOptionPane.showConfirmDialog(TrialViewPanel.this, s, "Confirm Trait Instance Removeal", JOptionPane.YES_NO_OPTION); if (JOptionPane.YES_OPTION == answer) { try { offlineData.getKdxploreDatabase().removeTraitInstancesFromTrial(trial, withoutData); } catch (IOException e) { MsgBox.warn(TrialViewPanel.this, e, "Remove Trait/Instances from Trial"); } finally { setCurrentTrialDetails(trial, false); onTraitInstancesRemoved.accept(trial); } } } } }
From source file:com.redhat.example.rules.unittest.CsvTestHelper.java
/** * create BiPredicate to check equality of an actual fact and an expected record fact. * @param columnDefs column definition list * @param clazz FACT class//from www.j a va 2 s. c om * @param keyClass the key class if FACTs are in a Map as values, null if FACTs are not in a Map * @return BiPredicate to check equality of an actual fact and an expected record fact. */ private static BiPredicate<ExpectedRecord, Object> createTestPredicate(List<CsvColumnDef> columnDefs, Class<?> clazz, Class<?> keyClass) { BiPredicate<ExpectedRecord, Object> predicate = new BiPredicate<ExpectedRecord, Object>() { @Override public boolean test(ExpectedRecord expected, Object fact) { boolean isMap = keyClass != null; if (!isMap && !fact.getClass().isAssignableFrom(clazz)) { return false; } boolean ret = true; for (CsvColumnDef columnDef : columnDefs) { if (columnDef.getTestPK() != null && columnDef.getTestPK() == Boolean.TRUE) { Object value1 = RuleFactWatcher.getProperty(expected.fact, columnDef.getColumnName()); Object value2 = RuleFactWatcher.getProperty(fact, columnDef.getColumnName()); if (value1 == null) { if (value2 != null) { ret = false; } } else { if (!value1.equals(value2)) { ret = false; } } } } return ret; } }; return predicate; }