List of usage examples for java.util.function Predicate Predicate
Predicate
From source file:dk.dma.ais.packet.AisPacketFiltersStateful.java
/** * Return false if this message is known to be related to a target with a latitude comparing false to 'lat'. * //w w w. j a v a 2 s .c o m * @param operator * @param lat * @return */ public Predicate<AisPacket> filterOnTargetLatitude(final CompareToOperator operator, Float lat) { final float rhsLat = lat; 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 lhsLat = getLatitude(mmsi); // Extract lat - if we know it return lhsLat != lhsLat /* NaN */ ? false : compare(lhsLat, rhsLat, operator); } public String toString() { return "lat " + operator + " " + rhsLat; } }; }
From source file:dk.dma.ais.packet.AisPacketFiltersStateful.java
/** * Return false if this message is known to be related to a target with a latitude outside the given range. */// w w w .j av a 2 s . com public Predicate<AisPacket> filterOnTargetLatitude(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 lhsLat = getLatitude(mmsi); // Extract - if we know it return lhsLat != lhsLat /* NaN */ ? false : inRange(min, max, lhsLat); } public String toString() { return "lat in " + min + ".." + max; } }; }
From source file:com.vmware.photon.controller.common.xenon.MultiHostEnvironment.java
private void waitForReplication(String serviceUri, String serviceLink) throws Throwable { for (ServiceHost host : getHosts()) { ServiceHostUtils.waitForServiceState(ServiceDocumentQueryResult.class, serviceUri, new Predicate<ServiceDocumentQueryResult>() { @Override//ww w. j av a 2 s . c o m public boolean test(ServiceDocumentQueryResult serviceDocumentQueryResult) { for (String documentLink : serviceDocumentQueryResult.documentLinks) { if (documentLink.equals(serviceLink)) { return true; } } return false; } }, host, WAIT_ITERATION_SLEEP, WAIT_ITERATION_COUNT, null); } }
From source file:dk.dma.ais.packet.AisPacketFiltersStateful.java
/** * Return false if this message is known to be related to a target with a longitude comparing false to 'lon'. * //from w w w . ja v a 2 s. c o m * @param operator * @param lon * @return */ public Predicate<AisPacket> filterOnTargetLongitude(final CompareToOperator operator, Float lon) { final float rhsLon = lon; 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 lhsLon = getLongitude(mmsi); // Extract lon - if we know it return lhsLon != lhsLon /* NaN */ ? false : compare(lhsLon, rhsLon, operator); } public String toString() { return "lon " + operator + " " + rhsLon; } }; }
From source file:dk.dma.ais.packet.AisPacketFiltersStateful.java
/** * Return false if this message is known to be related to a target with a longitude outside the given range. *///from w ww .j a v a 2 s. co m public Predicate<AisPacket> filterOnTargetLongitude(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 lhsLon = getLongitude(mmsi); // Extract cog - if we know it return lhsLon != lhsLon /* NaN */ ? false : inRange(min, max, lhsLon); } public String toString() { return "lon in " + min + ".." + max; } }; }
From source file:dk.dma.ais.view.rest.AisStoreResource.java
/** * Search data from AisStore and generate KMZ output. * //from w ww. j a v a 2 s .c o m * @param area * extract AisPackets from AisStore inside this area. * @param interval * extract AisPackets from AisStore inside this time interval. * @param title * Stamp this title into the generated KML (optional). * @param description * Stamp this description into the generated KML (optional). * @param primaryMmsi * Style this MMSI as the primary target in the scenario * (optional). * @param secondaryMmsi * Style this MMSI as the secondary target in the scenario * (optional). * @param snapshotAt * Generate a KML snapshot folder for exactly this point in time * (optional). * @param interpolationStepSecs * Interpolate targets between AisPackets using this time step in * seconds (optional). * @return HTTP response carrying KML for Google Earth */ @SuppressWarnings("unchecked") private Response scenarioKmz(final BoundingBox area, final Interval interval, final String title, final String description, final boolean createSituationFolder, final boolean createMovementsFolder, final boolean createTracksFolder, final Integer primaryMmsi, final Integer secondaryMmsi, final DateTime snapshotAt, final Integer interpolationStepSecs) { // Pre-check input final Duration duration = interval.toDuration(); final long hours = duration.getStandardHours(); final long minutes = duration.getStandardMinutes(); if (hours > 60) { throw new IllegalArgumentException("Queries spanning more than 6 hours are not allowed."); } final float size = area.getArea(); if (size > 2500.0 * 1e6) { throw new IllegalArgumentException( "Queries spanning more than 2500 square kilometers are not allowed."); } LOG.info("Preparing KML for span of " + hours + " hours + " + minutes + " minutes and " + (float) size + " square kilometers."); // Create the query //AisStoreQueryBuilder b = AisStoreQueryBuilder.forTime(); // Cannot use // getArea // because this // removes all // type 5 AisStoreQueryBuilder b = AisStoreQueryBuilder.forArea(area); b.setFetchSize(200); b.setInterval(interval); // Execute the query AisStoreQueryResult queryResult = get(CassandraConnection.class).execute(b); // Apply filters Iterable<AisPacket> filteredQueryResult = Iterables.filter(queryResult, AisPacketFilters.filterOnMessageId(1, 2, 3, 5, 18, 19, 24)); filteredQueryResult = Iterables.filter(filteredQueryResult, AisPacketFilters.filterRelaxedOnMessagePositionWithin(area)); if (!filteredQueryResult.iterator().hasNext()) { LOG.warn("No AIS data matching criteria."); } Predicate<? super AisPacket> isPrimaryMmsi = primaryMmsi == null ? e -> true : aisPacket -> aisPacket.tryGetAisMessage().getUserId() == primaryMmsi.intValue(); Predicate<? super AisPacket> isSecondaryMmsi = secondaryMmsi == null ? e -> true : aisPacket -> aisPacket.tryGetAisMessage().getUserId() == secondaryMmsi.intValue(); Predicate<? super AisPacket> triggerSnapshot = snapshotAt != null ? new Predicate<AisPacket>() { private final long snapshotAtMillis = snapshotAt.getMillis(); private boolean snapshotGenerated; @Override public boolean test(AisPacket aisPacket) { boolean generateSnapshot = false; if (!snapshotGenerated) { if (aisPacket.getBestTimestamp() >= snapshotAtMillis) { generateSnapshot = true; snapshotGenerated = true; } } return generateSnapshot; } } : e -> true; Supplier<? extends String> supplySnapshotDescription = () -> { return "<table width=\"300\"><tr><td><h4>" + title + "</h4></td></tr><tr><td><p>" + description + "</p></td></tr></table>"; }; Supplier<? extends String> supplyTitle = title != null ? () -> title : null; Supplier<? extends String> supplyDescription = description != null ? () -> description : null; Supplier<? extends Integer> supplyInterpolationStep = interpolationStepSecs != null ? () -> interpolationStepSecs : null; final OutputStreamSink<AisPacket> kmzSink = AisPacketOutputSinks.newKmzSink(e -> true, createSituationFolder, createMovementsFolder, createTracksFolder, isPrimaryMmsi, isSecondaryMmsi, triggerSnapshot, supplySnapshotDescription, supplyInterpolationStep, supplyTitle, supplyDescription, null); return Response.ok().entity(StreamingUtil.createStreamingOutput(filteredQueryResult, kmzSink)) .type(MEDIA_TYPE_KMZ).header("Content-Disposition", "attachment; filename = \"scenario.kmz\"") .build(); }
From source file:dk.dma.ais.packet.AisPacketFiltersStateful.java
/** * Return false if this message is known to be related to a target with a name not comparing to rhs parameter. * /*from w w w . j a va2s . c o m*/ * @return */ public Predicate<AisPacket> filterOnTargetName(final CompareToOperator operator, final String rhsName) { return new Predicate<AisPacket>() { public boolean test(AisPacket p) { aisPacketStream.add(p); // Update state final int mmsi = getMmsi(p); // Get MMSI in question final String lhsName = getName(mmsi); // Extract - if we know it return lhsName == null ? false : compare(lhsName, rhsName, operator); } public String toString() { return "name " + operator + " " + rhsName; } }; }
From source file:dk.dma.ais.packet.AisPacketFiltersStateful.java
/** * Return false if this message is known to be related to a target with a callsign not comparing to rhs parameter. * //from w w w .j a v a 2 s . c o m * @return */ public Predicate<AisPacket> filterOnTargetCallsign(final CompareToOperator operator, final String rhsCallsign) { return new Predicate<AisPacket>() { public boolean test(AisPacket p) { aisPacketStream.add(p); // Update state final int mmsi = getMmsi(p); // Get MMSI in question final String lhsCallsign = getCallsign(mmsi); // Extract - if we know it return lhsCallsign == null ? false : compare(lhsCallsign, rhsCallsign, operator); } public String toString() { return "cs " + operator + " " + rhsCallsign; } }; }
From source file:dk.dma.ais.packet.AisPacketFiltersStateful.java
/** * Return false if this message is known to be related to a target with a callsign not comparing to rhs parameter. * //w ww .java 2 s . co m * @return */ public Predicate<AisPacket> filterOnTargetCallsignMatch(final String pattern) { final String glob = preprocessExpressionString(pattern); return new Predicate<AisPacket>() { public boolean test(AisPacket p) { aisPacketStream.add(p); // Update state final int mmsi = getMmsi(p); // Get MMSI in question final String callsign = getCallsign(mmsi); // Extract - if we know it return callsign == null ? false : matchesGlob(preprocessAisString(callsign), glob); } public String toString() { return "cs ~ " + glob; } }; }
From source file:dk.dma.ais.packet.AisPacketFiltersStateful.java
/** * Filter on message to have known position inside given area. * * @param area/* w ww. ja v a 2 s .c o m*/ * The area that the position must reside inside. * @return */ public Predicate<AisPacket> filterOnTargetPositionWithin(final Area area) { requireNonNull(area); return new Predicate<AisPacket>() { public boolean test(AisPacket p) { aisPacketStream.add(p); // Update state final int mmsi = getMmsi(p); // Get MMSI in question final AisPosition pos = getPosition(mmsi); // Extract - if we know it return (pos == null || pos.getGeoLocation() == null) ? false : area.contains(pos.getGeoLocation()); } public String toString() { return "pos within " + area; } }; }