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.thoughtworks.go.remote.work.ArtifactsPublisherTest.java

private File getFileUploaded(String s) throws IOException {
    return Files.walk(Paths.get(workingFolder.toURI())).filter(new Predicate<Path>() {
        @Override/*  ww  w  .  j  av a 2 s.c o  m*/
        public boolean test(Path file) {
            return file.toFile().getName().equals(s);
        }
    }).findFirst().get().toFile();
}

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

/**
 * Return false if this message is known to be related to a target with a COG comparing false to 'cog'.
 * //from w  ww. j  av  a 2 s . c  om
 * @param operator
 * @param cog
 * @return
 */

public Predicate<AisPacket> filterOnTargetCourseOverGround(final CompareToOperator operator, Float cog) {
    final float rhsCog = cog;
    return new Predicate<AisPacket>() {
        public boolean test(AisPacket p) {
            aisPacketStream.add(p); // Update state
            final int mmsi = getMmsi(p); // Get MMSI in question
            final float lhsCog = getCog(mmsi); // Extract cog - if we know it
            return lhsCog != lhsCog /* NaN */ ? false : compare(lhsCog, rhsCog, operator);
        }

        public String toString() {
            return "cog " + operator + " " + rhsCog;
        }
    };
}

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

/**
 * Return false if this message is known to be related to a target with a COG outside the given range.
 *///w w  w.j ava  2  s . c o m

public Predicate<AisPacket> filterOnTargetCourseOverGround(final float min, final float 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 float lhsCog = getCog(mmsi); // Extract cog - if we know it
            return lhsCog != lhsCog /* NaN */ ? false : inRange(min, max, lhsCog);
        }

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

From source file:com.vmware.photon.controller.common.dcp.helpers.dcp.MultiHostEnvironment.java

private void waitForHostReady(final H host) throws Throwable {
    ServiceHostUtils.waitForState(new Supplier<H>() {
        @Override/*ww  w  . j a v  a  2  s  . c o  m*/
        public H get() {
            return host;
        }
    }, new Predicate<H>() {
        @Override
        public boolean test(H esxCloudDcpServiceHost) {
            boolean isReady = esxCloudDcpServiceHost.isReady();
            return isReady;
        }
    }, getEnvironmentCleanup());
}

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

/**
 * Return false if this message is known to be related to a target with a COG comparing false to 'hdg'.
 * //from  ww  w. j av a  2 s  .  c o  m
 * @param operator
 * @param hdg
 * @return
 */

public Predicate<AisPacket> filterOnTargetTrueHeading(final CompareToOperator operator, Integer hdg) {
    final int rhsHdg = hdg;
    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 lhsHdg = getHdg(mmsi); // Extract hdg - if we know it
            return lhsHdg < 0 ? false : compare(lhsHdg, rhsHdg, operator);
        }

        public String toString() {
            return "hdg " + operator + " " + rhsHdg;
        }
    };
}

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

protected static void validateVM(VirtualMachine vmInput, VirtualMachine vmOut) {
    Assert.assertTrue(vmOut.getProvisioningState() != null && !vmOut.getProvisioningState().isEmpty());
    Assert.assertEquals(vmInput.getHardwareProfile().getVirtualMachineSize(),
            vmOut.getHardwareProfile().getVirtualMachineSize());
    Assert.assertTrue(vmOut.getStorageProfile().getOSDisk() != null);
    Assert.assertNotNull(vmOut.getAvailabilitySetReference());
    Assert.assertEquals(vmInput.getAvailabilitySetReference().getReferenceUri().toLowerCase(),
            vmOut.getAvailabilitySetReference().getReferenceUri().toLowerCase());

    if (vmInput.getStorageProfile().getOSDisk() != null) {
        Assert.assertEquals(vmInput.getStorageProfile().getOSDisk().getName(),
                vmOut.getStorageProfile().getOSDisk().getName());
        Assert.assertEquals(vmInput.getStorageProfile().getOSDisk().getVirtualHardDisk().getUri(),
                vmOut.getStorageProfile().getOSDisk().getVirtualHardDisk().getUri());
        Assert.assertEquals(vmInput.getStorageProfile().getOSDisk().getCaching(),
                vmOut.getStorageProfile().getOSDisk().getCaching());
    }/* w  ww .ja  va 2s. c om*/

    if (vmInput.getStorageProfile().getDataDisks() != null
            && !vmInput.getStorageProfile().getDataDisks().isEmpty()) {
        for (DataDisk diskInput : vmInput.getStorageProfile().getDataDisks()) {
            DataDisk diskOut = null;
            for (DataDisk tmpDisk : vmOut.getStorageProfile().getDataDisks()) {
                if (tmpDisk.getName().equals(diskInput.getName())) {
                    diskOut = tmpDisk;
                }
            }

            Assert.assertNotNull(diskOut);
            Assert.assertNotNull(diskOut.getVirtualHardDisk());
            Assert.assertNotNull(diskOut.getVirtualHardDisk().getUri());

            if (diskInput.getSourceImage() != null && diskInput.getSourceImage().getUri() != null) {
                Assert.assertNotNull(diskOut.getSourceImage());
                Assert.assertEquals(diskInput.getSourceImage().getUri(), diskOut.getSourceImage().getUri());
            }
        }
    }

    // validate secret vault certificates
    if (vmInput.getOSProfile() != null && vmInput.getOSProfile().getSecrets() != null
            && !vmInput.getOSProfile().getSecrets().isEmpty()) {
        for (final VaultSecretGroup secret : vmInput.getOSProfile().getSecrets()) {
            VaultSecretGroup secretOut = vmOut.getOSProfile().getSecrets().stream()
                    .filter(new Predicate<VaultSecretGroup>() {
                        @Override
                        public boolean test(VaultSecretGroup vaultSecretGroup) {
                            return vaultSecretGroup.getSourceVault().getReferenceUri()
                                    .equals(secret.getSourceVault().getReferenceUri());
                        }
                    }).findAny().get();
            Assert.assertNotNull("secretOut not null", secretOut);
            Assert.assertNotNull("secretOut vaultCertificate not null", secretOut.getVaultCertificates());
            secretOut.getVaultCertificates().sort(new Comparator<VaultCertificate>() {
                @Override
                public int compare(VaultCertificate o1, VaultCertificate o2) {
                    return o1.getCertificateUrl().compareTo(o2.getCertificateUrl());
                }
            });

            secret.getVaultCertificates().sort(new Comparator<VaultCertificate>() {
                @Override
                public int compare(VaultCertificate o1, VaultCertificate o2) {
                    return o1.getCertificateUrl().compareTo(o2.getCertificateUrl());
                }
            });

            Assert.assertEquals("vault cert sizes", secret.getVaultCertificates().size(),
                    secretOut.getVaultCertificates().size());
            for (int i = 0; i < secret.getVaultCertificates().size(); i++) {
                Assert.assertTrue("cert store", secret.getVaultCertificates().get(i).getCertificateStore()
                        .equalsIgnoreCase(secretOut.getVaultCertificates().get(i).getCertificateStore()));
                Assert.assertTrue("cert url", secret.getVaultCertificates().get(i).getCertificateUrl()
                        .equalsIgnoreCase(secretOut.getVaultCertificates().get(i).getCertificateUrl()));
            }
        }
    }

    validatePlan(vmInput.getPlan(), vmOut.getPlan());
}

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

/**
 * Return false if this message is known to be related to a target with a COG outside the given range.
 *//*  w ww .j a  va  2  s. co m*/

public Predicate<AisPacket> filterOnTargetTrueHeading(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 lhsHdg = getHdg(mmsi); // Extract cog - if we know it
            return lhsHdg < 0 ? false : inRange(min, max, lhsHdg);
        }

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

From source file:com.diversityarrays.kdxplore.heatmap.HeatMapPanel.java

public void applyDecoratorsToHeatMap(HeatMapModelData<T> hmmd) {

    HeatMapModel<PlotOrSpecimen> model = hmmd.model;
    Map<Point, PlotOrSpecimen> plotSpecimensByPoint = model.getCellContentByPoint();

    Point[] decoratedPoints = null;

    Set<Integer> inactivePlotIds = plotInfoProvider.getPlots().stream().filter(p -> !p.isActivated())
            .map(Plot::getPlotId).collect(Collectors.toSet());

    if (!inactivePlotIds.isEmpty()) {
        Predicate<Point> containsInactivePlotId = new Predicate<Point>() {
            @Override//w  ww  .  j  av a2 s  .c o m
            public boolean test(Point pt) {
                PlotOrSpecimen pos = plotSpecimensByPoint.get(pt);
                if (pos == null) {
                    return false;
                }
                return inactivePlotIds.contains(pos.getPlotId());
            }
        };
        Set<Point> points = plotSpecimensByPoint.keySet().stream().filter(containsInactivePlotId)
                .collect(Collectors.toSet());
        if (!points.isEmpty()) {
            decoratedPoints = points.toArray(new Point[points.size()]);
        }
    }

    heatMap.setDecoratedPoints(diagonalDecorator, decoratedPoints);
}

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

/**
 * Return false if this message is known to be related to a target with a draught comparing false to 'draught'.
 * //from   w  w  w.  ja  va 2 s .c o  m
 * @param operator
 * @param draught
 * @return
 */

public Predicate<AisPacket> filterOnTargetDraught(final CompareToOperator operator, Float draught) {
    final float rhsDraught = draught;
    return new Predicate<AisPacket>() {
        public boolean test(AisPacket p) {
            aisPacketStream.add(p); // Update state
            final int mmsi = getMmsi(p); // Get MMSI in question
            final float lhsDraught = getDraught(mmsi); // Extract draught - if we know it
            return lhsDraught != lhsDraught /* NaN */ ? false : compare(lhsDraught, rhsDraught, operator);
        }

        public String toString() {
            return "draught " + operator + " " + rhsDraught;
        }
    };
}

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

/**
 * Return false if this message is known to be related to a target with a draught outside the given range.
 *///www. ja  v  a  2 s  .  c o  m

public Predicate<AisPacket> filterOnTargetDraught(final float min, final float 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 float lhsDraught = getDraught(mmsi); // Extract cog - if we know it
            return lhsDraught != lhsDraught /* NaN */ ? false : inRange(min, max, lhsDraught);
        }

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