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:org.ado.biblio.desktop.AppPresenter.java

public void search(Event event) throws SQLException {
    LOGGER.info("search");
    String searchSequence = textFieldSearch.getCharacters().toString();
    LOGGER.debug(searchSequence);/*from w  w w .  j  a  va2  s.  c om*/
    reloadBooksTable();
    if (!StringUtils.isBlank(searchSequence)) {
        bookData.removeIf(new Predicate<Book>() {
            @Override
            public boolean test(Book book) {

                final boolean containsMatch = book.getTitle().toLowerCase().contains(searchSequence)
                        || book.getAuthor().toLowerCase().contains(searchSequence)
                        || book.getTags().toLowerCase().contains(searchSequence);

                return !containsMatch;
            }
        });
    }
}

From source file:org.apache.bookkeeper.mledger.impl.ManagedLedgerTest.java

@Test
public void testBackwardCompatiblityForMeta() throws Exception {
    final ManagedLedgerInfo[] storedMLInfo = new ManagedLedgerInfo[3];
    final Stat[] versions = new Stat[1];

    ManagedLedgerFactory factory = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle());
    ManagedLedgerConfig conf = new ManagedLedgerConfig();
    conf.setMaxEntriesPerLedger(1);/* w ww .j  a v a2  s.  c  o m*/
    conf.setRetentionSizeInMB(10);
    conf.setRetentionTime(1, TimeUnit.HOURS);

    ManagedLedger ml = factory.open("backward_test_ledger", conf);
    ml.openCursor("c1");
    ml.addEntry("msg1".getBytes());
    ml.addEntry("msg2".getBytes());
    ml.close();

    MetaStore store = new MetaStoreImplZookeeper(zkc, executor);
    CountDownLatch l1 = new CountDownLatch(1);

    // obtain the ledger info
    store.getManagedLedgerInfo("backward_test_ledger", false, new MetaStoreCallback<ManagedLedgerInfo>() {
        @Override
        public void operationComplete(ManagedLedgerInfo result, Stat version) {
            storedMLInfo[0] = result;
            versions[0] = version;
            l1.countDown();
        }

        @Override
        public void operationFailed(MetaStoreException e) {
            fail("on get ManagedLedgerInfo backward_test_ledger");
        }
    });

    l1.await();
    ManagedLedgerInfo.Builder builder1 = ManagedLedgerInfo.newBuilder();

    // simulate test for old ledger with no timestampl
    for (LedgerInfo info : storedMLInfo[0].getLedgerInfoList()) {
        LedgerInfo noTimestamp = ManagedLedgerInfo.LedgerInfo.newBuilder().mergeFrom(info).clearTimestamp()
                .build();
        assertFalse(noTimestamp.hasTimestamp(), "expected old version info with no timestamp");
        builder1.addLedgerInfo(noTimestamp);

    }
    storedMLInfo[1] = builder1.build();

    // test timestamp on new ledger

    CountDownLatch l2 = new CountDownLatch(1);
    store.asyncUpdateLedgerIds("backward_test_ledger", storedMLInfo[1], versions[0],
            new MetaStoreCallback<Void>() {
                @Override
                public void operationComplete(Void result, Stat version) {
                    l2.countDown();
                }

                @Override
                public void operationFailed(MetaStoreException e) {
                    fail("on asyncUpdateLedgerIds");
                }
            });

    // verify that after update ledgers have timestamp

    ManagedLedgerImpl newVersionLedger = (ManagedLedgerImpl) factory.open("backward_test_ledger", conf);
    List<LedgerInfo> mlInfo = newVersionLedger.getLedgersInfoAsList();

    assertTrue(mlInfo.stream().allMatch(new Predicate<LedgerInfo>() {
        @Override
        public boolean test(LedgerInfo ledgerInfo) {
            return ledgerInfo.hasTimestamp();
        }
    }));
}

From source file:org.eclipse.vorto.maven.GeneratorMojo.java

private byte[] loadInformationModels() throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final ZipOutputStream zaos = new ZipOutputStream(baos);

    Files.walk(Paths.get((project.getBasedir().toURI()))).filter(new Predicate<Path>() {

        public boolean test(Path path) {
            return !path.toFile().isDirectory()
                    && (path.getFileName().toString().endsWith(ModelType.InformationModel.getExtension())
                            || path.getFileName().toString().endsWith(ModelType.Functionblock.getExtension())
                            || path.getFileName().toString().endsWith(ModelType.Datatype.getExtension()));
        }//w w  w.j av  a  2s.  co m
    }).forEach(new Consumer<Path>() {

        public void accept(Path t) {
            addToZip(zaos, t);
        }
    });

    return baos.toByteArray();
}

From source file:org.eclipse.vorto.maven.GeneratorMojo.java

private byte[] loadMappingModels() throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final ZipOutputStream zaos = new ZipOutputStream(baos);

    Files.walk(Paths.get((project.getBasedir().toURI()))).filter(new Predicate<Path>() {

        public boolean test(Path path) {
            return !path.toFile().isDirectory()
                    && (path.getFileName().toString().endsWith(ModelType.Mapping.getExtension())
                            || path.getFileName().toString().endsWith(ModelType.Functionblock.getExtension()));
        }/*from  ww  w . j av a2  s .  c om*/
    }).forEach(new Consumer<Path>() {

        public void accept(Path t) {
            addToZip(zaos, t);
        }
    });

    return baos.toByteArray();
}

From source file:org.fenixedu.academic.ui.struts.action.phd.academicAdminOffice.PhdIndividualProgramProcessDA.java

@Override
@EntryPoint/*from w  w  w .ja v  a2  s.c  om*/
public ActionForward manageProcesses(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) {

    SearchPhdIndividualProgramProcessBean searchBean = (SearchPhdIndividualProgramProcessBean) getObjectFromViewState(
            "searchProcessBean");

    if (searchBean == null) {
        searchBean = initializeSearchBean(request);
    }

    AndPredicate<PhdIndividualProgramProcess> predicate = searchBean.getPredicates();

    predicate.add(new Predicate<PhdIndividualProgramProcess>() {
        @Override
        public boolean test(PhdIndividualProgramProcess process) {
            return process.isAllowedToManageProcess(Authenticate.getUser());
        }
    });

    request.setAttribute("searchProcessBean", searchBean);
    request.setAttribute("processes",
            PhdIndividualProgramProcess.search(searchBean.getExecutionYear(), predicate));

    RenderUtils.invalidateViewState();

    return mapping.findForward("manageProcesses");
}

From source file:org.fenixedu.academic.ui.struts.action.phd.academicAdminOffice.PhdIndividualProgramProcessDA.java

public ActionForward viewMigratedProcesses(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) {/*  w ww  . j  a  v a2 s .  co m*/

    SearchPhdMigrationProcessBean searchBean = (SearchPhdMigrationProcessBean) getObjectFromViewState(
            "searchMigrationProcessBean");

    if (searchBean == null) {
        searchBean = initializeMigrationSearchBean(request);
    }

    AndPredicate<PhdMigrationIndividualProcessData> predicate = searchBean.getPredicates();

    predicate.add(new Predicate<PhdMigrationIndividualProcessData>() {
        @Override
        public boolean test(PhdMigrationIndividualProcessData process) {
            return AcademicAccessRule
                    .getPhdProgramsAccessibleToFunction(AcademicOperationType.MANAGE_PHD_PROCESSES,
                            Authenticate.getUser())
                    .collect(Collectors.toSet()).contains(process.getProcessBean().getPhdProgram());
        }
    });

    request.setAttribute("searchMigrationProcessBean", searchBean);
    request.setAttribute("migrationProcesses",
            PhdIndividualProgramProcess.searchMigrationProcesses(searchBean.getExecutionYear(), predicate));

    return mapping.findForward("viewAllMigratedProcesses");
}

From source file:org.springframework.web.reactive.function.server.RequestPredicates.java

/**
 * Return a {@code RequestPredicate} that tests if the request's
 * {@linkplain ServerRequest.Headers#contentType() content type} is
 * {@linkplain MediaType#includes(MediaType) included} by any of the given media types.
 * @param mediaTypes the media types to match the request's content type against
 * @return a predicate that tests the request's content type against the given media types
 *///from   w w  w.j  ava  2  s  .  co  m
public static RequestPredicate contentType(MediaType... mediaTypes) {
    Assert.notEmpty(mediaTypes, "'mediaTypes' must not be empty");
    Set<MediaType> mediaTypeSet = new HashSet<>(Arrays.asList(mediaTypes));

    return headers(new Predicate<ServerRequest.Headers>() {
        @Override
        public boolean test(ServerRequest.Headers headers) {
            MediaType contentType = headers.contentType().orElse(MediaType.APPLICATION_OCTET_STREAM);
            boolean match = mediaTypeSet.stream().anyMatch(mediaType -> mediaType.includes(contentType));
            traceMatch("Content-Type", mediaTypeSet, contentType, match);
            return match;
        }

        @Override
        public String toString() {
            return String.format("Content-Type: %s", mediaTypeSet);
        }
    });
}

From source file:org.springframework.web.reactive.function.server.RequestPredicates.java

/**
 * Return a {@code RequestPredicate} that tests if the request's
 * {@linkplain ServerRequest.Headers#accept() accept} header is
 * {@linkplain MediaType#isCompatibleWith(MediaType) compatible} with any of the given media types.
 * @param mediaTypes the media types to match the request's accept header against
 * @return a predicate that tests the request's accept header against the given media types
 */// www . ja va  2  s. c  o  m
public static RequestPredicate accept(MediaType... mediaTypes) {
    Assert.notEmpty(mediaTypes, "'mediaTypes' must not be empty");
    Set<MediaType> mediaTypeSet = new HashSet<>(Arrays.asList(mediaTypes));

    return headers(new Predicate<ServerRequest.Headers>() {
        @Override
        public boolean test(ServerRequest.Headers headers) {
            List<MediaType> acceptedMediaTypes = headers.accept();
            if (acceptedMediaTypes.isEmpty()) {
                acceptedMediaTypes = Collections.singletonList(MediaType.ALL);
            } else {
                MediaType.sortBySpecificityAndQuality(acceptedMediaTypes);
            }
            boolean match = acceptedMediaTypes.stream().anyMatch(
                    acceptedMediaType -> mediaTypeSet.stream().anyMatch(acceptedMediaType::isCompatibleWith));
            traceMatch("Accept", mediaTypeSet, acceptedMediaTypes, match);
            return match;
        }

        @Override
        public String toString() {
            return String.format("Accept: %s", mediaTypeSet);
        }
    });
}

From source file:pt.ist.expenditureTrackingSystem.domain.organization.Unit.java

public static Unit findUnitByCostCenter(final String costCenter) {
    for (final Unit unit : ExpenditureTrackingSystem.getInstance().getTopLevelUnitsSet()) {
        final Unit result = Unit.findMatch(unit.getUnit(), new Predicate<Unit>() {
            @Override/*from   w w  w. jav a  2s. c o  m*/
            public boolean test(final Unit unit) {
                return unit instanceof CostCenter && ((CostCenter) unit).getCostCenter().equals(costCenter);
            }
        });
        if (result != null) {
            return result;
        }
    }
    return null;
}