Example usage for java.util.function Predicate Predicate

List of usage examples for java.util.function Predicate Predicate

Introduction

In this page you can find the example usage for java.util.function Predicate Predicate.

Prototype

Predicate

Source Link

Usage

From source file:com.microsoft.azure.utility.compute.TestCleanupTask.java

private void removeRGs(ArrayList<ResourceGroupExtended> groups) {
    groups.stream().filter(new Predicate<ResourceGroupExtended>() {
        @Override//from  w  ww  . j  a  va2s  .co  m
        public boolean test(ResourceGroupExtended rg) {
            return rg.getName().startsWith("javatest");
        }
    }).forEach(new Consumer<ResourceGroupExtended>() {
        @Override
        public void accept(ResourceGroupExtended rg) {
            try {
                resourceManagementClient.getResourceGroupsOperations().beginDeleting(rg.getName());
                log.info("removed rg: " + rg.getName());
            } catch (Exception e) {
                log.info(e.toString());
            }
        }
    });
}

From source file:ambroafb.general.StagesContainer.java

/**
 * The function removes only children stages of given stage from bidirectional map if they exists.
 * @param stage which children must be remove.
 *///from  ww w  . j  av  a2 s  .  com
public static void removeOnlySubstagesFor(Stage stage) {
    String path = (String) bidmap.getKey(stage);
    List<String> pathes = (ArrayList<String>) bidmap.keySet().stream().filter(new Predicate() {
        @Override
        public boolean test(Object key) {
            return ((String) key).startsWith(path) && !((String) key).equals(path);
        }
    }).collect(Collectors.toList());
    //        bidmap.keySet().stream().forEach((key) -> {
    //            if (((String) key).startsWith(path) && !((String) key).equals(path)) {
    //                pathes.add((String) key);
    //            }
    //        });
    pathes.stream().forEach((currPath) -> {
        bidmap.remove((String) currPath);
    });
}

From source file:jease.cms.web.system.parameter.Editor.java

public void validate() {
    validate(StringUtils.isEmpty(key.getValue()), I18N.get("Key_is_required"));
    validate(!Database.isUnique(getObject(), new Predicate<Parameter>() {
        public boolean test(Parameter parameter) {
            return parameter.getKey().equals(key.getText());
        }//from w w  w.  j av a2s  . c o m
    }), I18N.get("Key_must_be_unique"));
}

From source file:com.yqboots.web.thymeleaf.processor.element.AlertElementProcessor.java

/**
 * {@inheritDoc}//www .  jav  a 2  s  .  c o m
 */
@Override
protected List<Node> getMarkupSubstitutes(final Arguments arguments, final Element element) {
    final List<Node> nodes = new ArrayList<>();

    final String levelAttrValue = StringUtils.defaultIfBlank(element.getAttributeValue(ATTR_LEVEL),
            DEFAULT_LEVEL);

    final VariablesMap<String, Object> variables = arguments.getContext().getVariables();
    variables.values().stream().filter(new Predicate<Object>() {
        @Override
        public boolean test(final Object o) {
            return BindingResult.class.isAssignableFrom(o.getClass());
        }
    }).forEach(new Consumer<Object>() {
        @Override
        public void accept(final Object value) {
            BindingResult bindingResult = (BindingResult) value;
            if (bindingResult.hasGlobalErrors()) {
                nodes.add(build(arguments, bindingResult.getGlobalErrors(), levelAttrValue));
            }
        }
    });

    return nodes;
}

From source file:dk.dma.ais.packet.AisPacketFiltersStateful.java

/**
 * Return false if this message is known to be related to a target with an IMO no. different to 'imo'.
 * /*from  www  .jav  a  2  s.  co  m*/
 * @param operator
 * @param rhsImo
 * @return
 */

public Predicate<AisPacket> filterOnTargetImo(final CompareToOperator operator, Integer rhsImo) {
    final int imo = rhsImo;
    return new Predicate<AisPacket>() {
        public boolean test(AisPacket p) {
            aisPacketStream.add(p); // Update state
            final int mmsi = getMmsi(p); // Get MMSI in question
            final int lhsImo = getImo(mmsi); // Extract IMO no. - if we know it
            return lhsImo < 0 ? false : compare(lhsImo, imo, operator);
        }

        public String toString() {
            return "imo = " + imo;
        }
    };
}

From source file:de.vandermeer.skb.commons.Predicates.java

/**
 * Returns a predicate that evaluates to true if the set contains strings starting with a given character sequence.
 * @param nodes set of strings as base/*  w w w . ja  v a 2  s. c  o m*/
 * @return predicate that returns true if set contains strings starting with it, false otherwise
 */
final public static Predicate<StrBuilder> CONTAINS_STRINGS_STARTING_WITH(final Set<String> nodes) {
    return new Predicate<StrBuilder>() {
        @Override
        public boolean test(final StrBuilder fqpn) {
            if (fqpn == null) {
                return false;
            }
            String key = fqpn.toString();
            if (!nodes.contains(key)) {
                return false;
            }

            Set<String> tail = new TreeSet<String>(nodes).tailSet(key, false);
            if (tail.size() == 0) {
                return false;
            }

            String child = tail.iterator().next();
            if (child.startsWith(key)) {
                return true;
            }
            return false;
        }
    };
}

From source file:dk.dma.ais.packet.AisPacketKMLOutputSink.java

public static void main(String[] args) throws IOException {
    Predicate<AisPacket> filter = new Predicate<AisPacket>() {
        @Override//from   w  ww.java 2 s  . c o m
        public boolean test(AisPacket aisPacket) {
            return aisPacket.tryGetAisMessage().getUserId() == 477325700;
        }
    };

    AisPacketKMLOutputSink kmlOutputSink = new AisPacketKMLOutputSink(filter);

    try (FileOutputStream fos = new FileOutputStream(Paths.get("/Users/tbsalling/Desktop/test.kml").toFile())) {
        AisPacketReader reader = AisPacketReader
                .createFromFile(Paths.get("/Users/tbsalling/Desktop/ais-sample.txt"), true);
        reader.writeTo(fos, kmlOutputSink);
    }
}

From source file:dk.dma.ais.packet.AisPacketFiltersStateful.java

/**
 * Return false if this message is known to be related to a target with an IMO outside the given range.
 *//*from w w  w .  j  av a 2s. com*/

public Predicate<AisPacket> filterOnTargetImo(final int min, final int max) {
    return new Predicate<AisPacket>() {
        public boolean test(AisPacket p) {
            aisPacketStream.add(p); // Update state
            final int mmsi = getMmsi(p); // Get MMSI in question
            final int imo = getImo(mmsi); // Extract IMO no. - if we know it
            return imo < 0 ? false : inRange(min, max, imo);
        }

        public String toString() {
            return "imo in " + min + ".." + max;
        }
    };
}

From source file:com.diversityarrays.kdxplore.trialmgr.trait.repair.TraitsToRepair.java

public void getProblemSampleCountByTrialId() throws IOException {

    traitSamplesByTrait.clear();/* w w w  . j  a  v a2s  . c  o m*/

    Map<Integer, String> trialNameById = new HashMap<>();

    Predicate<KdxSample> predicate = new Predicate<KdxSample>() {
        @Override
        public boolean test(KdxSample sample) {
            int traitId = sample.getTraitId();

            int trialId = sample.getTrialId();

            if (traitById.keySet().contains(traitId)) {
                int snum = sample.getSpecimenNumber();

                Trait trait = traitById.get(traitId);

                TraitSamplesToRepair traitSamplesByTrialId = traitSamplesByTrait.get(trait);
                if (traitSamplesByTrialId == null) {
                    traitSamplesByTrialId = new TraitSamplesToRepair(trait);
                    traitSamplesByTrait.put(trait, traitSamplesByTrialId);
                }

                String trialName = trialNameById.get(trialId);
                if (trialName == null) {
                    try {
                        Trial trial = kdxdb.getKDXploreKSmartDatabase().getTrial(trialId);
                        trialName = trial.getTrialName();
                    } catch (IOException ignore) {
                        trialName = "Trial#" + trialId;
                    }
                    trialNameById.put(trialId, trialName);
                }

                traitSamplesByTrialId.addSampleCount(trialId, trialName, sample);
            }
            return true;
        }
    };

    // No traitId so all Traits are scanned
    kdxdb.visitScoredKdxSamples(null, predicate);
}

From source file:com.thoughtworks.go.agent.service.TokenRequesterTest.java

private NameValuePair findParam(List<NameValuePair> nameValuePairs, final String paramName) {
    return nameValuePairs.stream().filter(new Predicate<NameValuePair>() {
        @Override/*w w w . j a v a2s. c  o  m*/
        public boolean test(NameValuePair nameValuePair) {
            return nameValuePair.getName().equals(paramName);
        }
    }).findFirst().orElse(null);
}