List of usage examples for java.util.function Predicate test
boolean test(T t);
From source file:at.gridtec.lambda4j.operator.ternary.BooleanTernaryOperator.java
/** * Returns a composed {@link TriPredicate} that first applies the {@code before} predicates to its input, and * then applies this operator to the result. * If evaluation of either operation throws an exception, it is relayed to the caller of the composed operation. * * @param <A> The type of the argument to the first given predicate, and of composed predicate * @param <B> The type of the argument to the second given predicate, and of composed predicate * @param <C> The type of the argument to the third given predicate, and of composed predicate * @param before1 The first predicate to apply before this operator is applied * @param before2 The second predicate to apply before this operator is applied * @param before3 The third predicate to apply before this operator is applied * @return A composed {@code TriPredicate} that first applies the {@code before} predicates to its input, and then * applies this operator to the result./* w w w . j av a 2 s. c o m*/ * @throws NullPointerException If given argument is {@code null} * @implSpec The input argument of this method is able to handle every type. */ @Nonnull default <A, B, C> TriPredicate<A, B, C> compose(@Nonnull final Predicate<? super A> before1, @Nonnull final Predicate<? super B> before2, @Nonnull final Predicate<? super C> before3) { Objects.requireNonNull(before1); Objects.requireNonNull(before2); Objects.requireNonNull(before3); return (a, b, c) -> applyAsBoolean(before1.test(a), before2.test(b), before3.test(c)); }
From source file:at.gridtec.lambda4j.function.tri.obj.BiObjBooleanToFloatFunction.java
/** * Returns a composed {@link ToFloatTriFunction} that first applies the {@code before} functions to its input, and * then applies this function to the result. * If evaluation of either operation throws an exception, it is relayed to the caller of the composed operation. * * @param <A> The type of the argument to the first given function, and of composed function * @param <B> The type of the argument to the second given function, and of composed function * @param <C> The type of the argument to the third given predicate, and of composed function * @param before1 The first function to apply before this function is applied * @param before2 The second function to apply before this function is applied * @param before3 The third predicate to apply before this function is applied * @return A composed {@code ToFloatTriFunction} that first applies the {@code before} functions to its input, and * then applies this function to the result. * @throws NullPointerException If given argument is {@code null} * @implSpec The input argument of this method is able to handle every type. *///from w ww . j a v a 2s . com @Nonnull default <A, B, C> ToFloatTriFunction<A, B, C> compose(@Nonnull final Function<? super A, ? extends T> before1, @Nonnull final Function<? super B, ? extends U> before2, @Nonnull final Predicate<? super C> before3) { Objects.requireNonNull(before1); Objects.requireNonNull(before2); Objects.requireNonNull(before3); return (a, b, c) -> applyAsFloat(before1.apply(a), before2.apply(b), before3.test(c)); }
From source file:at.gridtec.lambda4j.function.tri.obj.BiObjBooleanToShortFunction.java
/** * Returns a composed {@link ToShortTriFunction} that first applies the {@code before} functions to its input, and * then applies this function to the result. * If evaluation of either operation throws an exception, it is relayed to the caller of the composed operation. * * @param <A> The type of the argument to the first given function, and of composed function * @param <B> The type of the argument to the second given function, and of composed function * @param <C> The type of the argument to the third given predicate, and of composed function * @param before1 The first function to apply before this function is applied * @param before2 The second function to apply before this function is applied * @param before3 The third predicate to apply before this function is applied * @return A composed {@code ToShortTriFunction} that first applies the {@code before} functions to its input, and * then applies this function to the result. * @throws NullPointerException If given argument is {@code null} * @implSpec The input argument of this method is able to handle every type. *///from w ww . ja va 2 s. c o m @Nonnull default <A, B, C> ToShortTriFunction<A, B, C> compose(@Nonnull final Function<? super A, ? extends T> before1, @Nonnull final Function<? super B, ? extends U> before2, @Nonnull final Predicate<? super C> before3) { Objects.requireNonNull(before1); Objects.requireNonNull(before2); Objects.requireNonNull(before3); return (a, b, c) -> applyAsShort(before1.apply(a), before2.apply(b), before3.test(c)); }
From source file:dk.dma.ais.view.rest.AisStoreResource.java
/** * Produce KML output for POSTed AIS data in NMEA format. * * Use 'curl -X POST -T <ais-data-file> http://127.0.0.1:8090/store/history/kml' to test * Or with expression filter:/*from w w w. j a va 2s.c om*/ * 'curl -X POST -T <ais-data-file> http://127.0.0.1:8090/store/history/kml?filter="m.mmsi=247469000" > test.kmz' */ @POST @Path("/history/kml") @Produces(MEDIA_TYPE_KMZ) public Response createKml(@QueryParam("filter") String filterExpression, InputStream inputStream) { LOG.debug("Filter expression: " + filterExpression); Predicate<AisPacket> filter = isBlank(filterExpression) ? p -> true : AisPacketFilters.parseExpressionFilter(filterExpression); ArrayList<AisPacket> packets = new ArrayList<>(); AisReader reader = AisReaders.createReaderFromInputStream(inputStream); reader.registerPacketHandler(aisPacket -> { if (filter.test(aisPacket)) packets.add(aisPacket); }); reader.start(); try { reader.join(); } catch (InterruptedException e) { LOG.error(e.getMessage(), e); return Response.serverError().build(); } StreamingOutput output = StreamingUtil.createZippedStreamingOutput(packets, AisPacketOutputSinks.newKmlSink(), "history.kml"); return Response.ok().entity(output).type(MEDIA_TYPE_KMZ).build(); }
From source file:at.gridtec.lambda4j.function.tri.obj.BiObjBooleanToDoubleFunction.java
/** * Returns a composed {@link ToDoubleTriFunction} that first applies the {@code before} functions to its input, and * then applies this function to the result. * If evaluation of either operation throws an exception, it is relayed to the caller of the composed operation. * * @param <A> The type of the argument to the first given function, and of composed function * @param <B> The type of the argument to the second given function, and of composed function * @param <C> The type of the argument to the third given predicate, and of composed function * @param before1 The first function to apply before this function is applied * @param before2 The second function to apply before this function is applied * @param before3 The third predicate to apply before this function is applied * @return A composed {@code ToDoubleTriFunction} that first applies the {@code before} functions to its input, and * then applies this function to the result. * @throws NullPointerException If given argument is {@code null} * @implSpec The input argument of this method is able to handle every type. */// w w w . ja v a 2 s . c o m @Nonnull default <A, B, C> ToDoubleTriFunction<A, B, C> compose(@Nonnull final Function<? super A, ? extends T> before1, @Nonnull final Function<? super B, ? extends U> before2, @Nonnull final Predicate<? super C> before3) { Objects.requireNonNull(before1); Objects.requireNonNull(before2); Objects.requireNonNull(before3); return (a, b, c) -> applyAsDouble(before1.apply(a), before2.apply(b), before3.test(c)); }
From source file:com.joyent.manta.client.crypto.EncryptingEntityTest.java
private static void verifyEncryptionWorksRoundTrip(byte[] keyBytes, SupportedCipherDetails cipherDetails, HttpEntity entity, Predicate<byte[]> validator) throws Exception { SecretKey key = SecretKeyUtils.loadKey(keyBytes, cipherDetails); EncryptingEntity encryptingEntity = new EncryptingEntity(key, cipherDetails, entity); File file = File.createTempFile("ciphertext-", ".data"); FileUtils.forceDeleteOnExit(file);/* www .j a v a 2 s . c o m*/ try (FileOutputStream out = new FileOutputStream(file)) { encryptingEntity.writeTo(out); } Assert.assertEquals(file.length(), encryptingEntity.getContentLength(), "Expected ciphertext file size doesn't match actual file size " + "[originalContentLength=" + entity.getContentLength() + "] -"); byte[] iv = encryptingEntity.getCipher().getIV(); Cipher cipher = cipherDetails.getCipher(); cipher.init(Cipher.DECRYPT_MODE, key, cipherDetails.getEncryptionParameterSpec(iv)); final long ciphertextSize; if (cipherDetails.isAEADCipher()) { ciphertextSize = encryptingEntity.getContentLength(); } else { ciphertextSize = encryptingEntity.getContentLength() - cipherDetails.getAuthenticationTagOrHmacLengthInBytes(); } try (FileInputStream in = new FileInputStream(file); BoundedInputStream bin = new BoundedInputStream(in, ciphertextSize); CipherInputStream cin = new CipherInputStream(bin, cipher)) { final byte[] actualBytes = IOUtils.toByteArray(cin); final byte[] hmacBytes = new byte[cipherDetails.getAuthenticationTagOrHmacLengthInBytes()]; in.read(hmacBytes); Assert.assertTrue(validator.test(actualBytes), "Entity validation failed"); } }
From source file:org.mitre.mpf.wfm.service.PipelineServiceImpl.java
private boolean actionSupportsProcessingType(String actionName, Predicate<AlgorithmDefinition> supportsPred) { ActionDefinition action = getAction(actionName); AlgorithmDefinition algorithm = getAlgorithm(action); return supportsPred.test(algorithm); }
From source file:org.savantbuild.dep.maven.SavantBridge.java
private String ask(String message, String defaultValue, String errorMessage, Predicate<String> predicate) { String answer;/*from w ww . j a va 2s . c om*/ boolean valid; do { System.out.printf(message + (defaultValue != null ? " [" + defaultValue + "]" : "") + "?\n"); try { answer = input.readLine(); } catch (IOException e) { throw new RuntimeException(e); } if (StringUtils.isBlank(answer) && defaultValue != null) { return defaultValue; } if (predicate != null) { valid = predicate.test(answer); if (!valid) { System.out.printf(errorMessage); } } else { valid = true; } } while (!valid); return answer; }
From source file:de.ks.flatadocdb.session.Session.java
private <E, V> Set<V> queryValuesFromIndex(Query<E, V> query, Predicate<V> filter, Set<String> idsToIgnore) { Map<IndexElement, Optional<V>> elements = globalIndex.getQueryElements(query); if (elements == null) { return Collections.emptySet(); } else {/* w w w . java 2s . c o m*/ return elements.entrySet().stream()// .filter(entry -> !idsToIgnore.contains(entry.getKey().getId()))// .filter(entry -> entry.getValue().isPresent())// .filter(entry -> filter.test(entry.getValue().get()))// .map(entry -> entry.getValue().get())// .collect(Collectors.toSet()); } }