Example usage for java.util List removeIf

List of usage examples for java.util List removeIf

Introduction

In this page you can find the example usage for java.util List removeIf.

Prototype

default boolean removeIf(Predicate<? super E> filter) 

Source Link

Document

Removes all of the elements of this collection that satisfy the given predicate.

Usage

From source file:com.blackducksoftware.integration.hub.detect.detector.sbt.SbtPackager.java

private List<SbtDependencyModule> extractModules(final String path, final int depth, final String included,
        final String excluded) throws IOException, SAXException, ParserConfigurationException {
    final List<File> sbtFiles = detectFileFinder.findFilesToDepth(path, BUILD_SBT_FILENAME, depth);
    final List<File> resolutionCaches = detectFileFinder.findDirectoriesContainingDirectoriesToDepth(path,
            RESOLUTION_CACHE_DIRECTORY, depth);

    logger.info(String.format("Found %s build.sbt files.", sbtFiles.size()));
    logger.info(String.format("Found %s resolution caches.", resolutionCaches.size()));

    final List<SbtDependencyModule> modules = new ArrayList<>();
    final List<String> usedReports = new ArrayList<>();

    for (final File sbtFile : sbtFiles) {
        logger.debug(String.format("Found SBT build file: %s", sbtFile.getCanonicalPath()));
        final File sbtDirectory = sbtFile.getParentFile();
        final File reportPath = new File(sbtDirectory, REPORT_FILE_DIRECTORY);

        final List<SbtDependencyModule> foundModules = extractReportModules(path, reportPath, sbtDirectory,
                included, excluded, usedReports);
        modules.addAll(foundModules);/*from w w w  .j a v a  2  s.  com*/
    }

    for (final File resCache : resolutionCaches) {
        logger.debug(String.format("Found resolution cache: %s", resCache.getCanonicalPath()));
        final File reportPath = new File(resCache, REPORT_DIRECTORY);
        final List<SbtDependencyModule> foundModules = extractReportModules(path, reportPath,
                resCache.getParentFile(), included, excluded, usedReports);
        modules.addAll(foundModules);
    }

    modules.removeIf(it -> {
        if (it.name.contains("temp-module")) {
            logger.info("Excluding temp module: " + it.name);
            return true;
        } else {
            return false;
        }
    });

    if (modules.size() == 0) {
        if (sbtFiles.size() == 0) {
            logger.error("Sbt found no build.sbt files even though it applied.");
        } else if (resolutionCaches.size() == 0) {
            logger.error(
                    "Sbt found no resolution-caches, this most likely means you are not running post build.");
            logger.error("Please build the project before running detect.");
        } else {
            logger.error("Sbt was unable to parse any dependencies from any resolution caches.");
        }
    }

    return modules;
}

From source file:com.jvms.i18neditor.editor.Editor.java

public void importProject(Path dir, boolean showEmptyProjectError) {
    try {//from   w w w .j a  v a2 s. c o m
        Preconditions.checkArgument(Files.isDirectory(dir));

        if (!closeCurrentProject()) {
            return;
        }

        clearUI();
        project = new EditorProject(dir);
        restoreProjectState(project);

        Optional<ResourceType> type = Optional.ofNullable(project.getResourceType());
        List<Resource> resourceList = Resources.get(dir, project.getResourceName(), type);
        Map<String, String> keys = Maps.newTreeMap();

        if (resourceList.isEmpty()) {
            project = null;
            if (showEmptyProjectError) {
                executor.execute(() -> showError(MessageBundle.get("resources.import.empty", dir)));
            }
        } else {
            project.setResourceType(type.orElseGet(() -> {
                ResourceType t = resourceList.get(0).getType();
                resourceList.removeIf(r -> r.getType() != t);
                return t;
            }));
            resourceList.forEach(resource -> {
                try {
                    Resources.load(resource);
                    setupResource(resource);
                    project.addResource(resource);
                } catch (IOException e) {
                    log.error("Error importing resource file " + resource.getPath(), e);
                    showError(
                            MessageBundle.get("resources.import.error.single", resource.getPath().toString()));
                }
            });
            project.getResources().forEach(r -> keys.putAll(r.getTranslations()));
        }
        translationTree.setModel(new TranslationTreeModel(Lists.newArrayList(keys.keySet())));

        updateTreeNodeStatuses();
        updateHistory();
        updateUI();
        requestFocusInFirstResourceField();
    } catch (IOException e) {
        log.error("Error importing resource files", e);
        showError(MessageBundle.get("resources.import.error.multiple"));
    }
}

From source file:org.egov.tl.web.actions.BaseLicenseAction.java

@Override
public List<String> getValidActions() {
    List<String> validActions = new ArrayList<>();
    if (null == getModel() || null == getModel().getId() || getModel().getCurrentState() == null
            || getModel().getCurrentState().getValue().endsWith("NEW")
            || (getModel() != null && getModel().getCurrentState() != null
                    ? getModel().getCurrentState().isEnded()
                    : false))/*from   w  ww . j  av a 2  s. c  o  m*/
        validActions = Arrays.asList("Save");
    else if (getModel().hasState())
        if (getModel().isNewWorkflow())
            validActions.addAll(this.customizedWorkFlowService.getNextValidActions(getModel().getStateType(),
                    getWorkFlowDepartment(), getAmountRule(), getAdditionalRule(),
                    getModel().getCurrentState().getValue(), getPendingActions(), getModel().getCreatedDate(),
                    "%" + license().getCurrentState().getOwnerPosition().getDeptDesig().getDesignation()
                            .getName() + "%"));
        else
            validActions.addAll(super.getValidActions());
    validActions.removeIf(validAction -> "Reassign".equals(validAction)
            && getModel().getState().getCreatedBy().getId().equals(ApplicationThreadLocals.getUserId()));
    return validActions;
}

From source file:org.languagetool.rules.de.GermanSpellerRule.java

@Override
protected void filterForLanguage(List<String> suggestions) {
    if (language.getShortCodeWithCountryAndVariant().equals("de-CH")) {
        for (int i = 0; i < suggestions.size(); i++) {
            String s = suggestions.get(i);
            suggestions.set(i, s.replace("", "ss"));
        }/* w ww  .  j  a  v  a 2s  . co m*/
    }
    // Remove suggestions like "Mafiosi s" and "Mafiosi s.":
    suggestions.removeIf(s -> Arrays.stream(s.split(" ")).anyMatch(k -> k.matches("\\w\\p{Punct}?")));
    // This is not quite correct as it might remove valid suggestions that start with "-",
    // but without this we get too many strange suggestions that start with "-" for no apparent reason
    // (e.g. for "Gratifikationskrisem" -> "-Gratifikationskrisen"):
    suggestions.removeIf(s -> s.length() > 1 && s.startsWith("-"));
}

From source file:squash.booking.lambdas.core.BookingManagerTest.java

@Test
public void testGetAllBookingsReturnsCorrectBookings() throws Exception {

    // ARRANGE/*from w  ww. j  a v  a2  s.c o m*/
    initialiseBookingManager();

    // Expect bookings that are not all on a single day. Also expect presence of
    // booking rules and lifecycle state in the database to be ignored.
    List<Booking> bookingsForMoreThanOneDay = expectOptimisticPersisterGetAllItemsToReturnAllBookings(true);

    // ACT
    // N.B. Parameter is arbitrary here.
    List<Booking> actualBookings = bookingManager.getAllBookings(true);

    // ASSERT
    for (Booking expectedBooking : bookingsForMoreThanOneDay) {
        assertTrue("Expected " + expectedBooking.toString(), actualBookings.contains(expectedBooking));
        actualBookings.removeIf(booking -> booking.equals(expectedBooking));
    }
    assertTrue("More bookings than expected were returned", actualBookings.size() == 0);
}

From source file:squash.booking.lambdas.core.BookingManagerTest.java

@Test
public void testGetBookingsReturnsCorrectBookings() throws Exception {

    // Test happy path for getBookings: we query for a valid date and verify
    // that we get back the bookings we expect

    // ARRANGE/*from ww  w .j a va2s  . c  o  m*/
    initialiseBookingManager();

    // (the version number must be set here but its value is irrelevant)
    expectOptimisticPersisterGetToReturnVersionedAttributesOrThrow(Optional.of(42), bookingsBeforeCall,
            Optional.empty());

    // ACT
    // Ask for the bookings for a valid date. N.B. Second parameter is arbitrary
    // here.
    List<Booking> actualBookings = bookingManager.getBookings(fakeCurrentDateString, true);

    // ASSERT
    for (Booking expectedBooking : bookingsBeforeCall) {
        assertTrue("Expected " + expectedBooking.toString(), actualBookings.contains(expectedBooking));
        actualBookings.removeIf(booking -> booking.equals(expectedBooking));
    }
    assertTrue("More bookings than expected were returned", actualBookings.size() == 0);
}

From source file:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.java

/**
 * Extract a filtered set of PropertyDescriptors from the given BeanWrapper,
 * excluding ignored dependency types or properties defined on ignored dependency interfaces.
 * @param bw the BeanWrapper the bean was created with
 * @return the filtered PropertyDescriptors
 * @see #isExcludedFromDependencyCheck//from   w  w w .j a v  a 2 s .c  o m
 */
protected PropertyDescriptor[] filterPropertyDescriptorsForDependencyCheck(BeanWrapper bw) {
    List<PropertyDescriptor> pds = new ArrayList<>(Arrays.asList(bw.getPropertyDescriptors()));
    pds.removeIf(this::isExcludedFromDependencyCheck);
    return pds.toArray(new PropertyDescriptor[0]);
}

From source file:squash.booking.lambdas.core.BookingManagerTest.java

@Test
public void testDeleteBookingReturnsCorrectBookings() throws Exception {
    // ARRANGE/*from   w  w  w . j a va2  s.  c  om*/
    initialiseBookingManager();

    expectedBookingsAfterCall.addAll(bookingsBeforeCall);
    // Remove the booking we're deleting - so the manager thinks the delete is
    // successful
    expectedBookingsAfterCall.removeIf(booking -> booking.equals(existingSingleBooking));
    expectDeleteBookingToReturnUpdatedBookingsOrThrow(existingSingleBooking,
            Optional.of(expectedBookingsAfterCall), Optional.empty());

    // Act
    // N.B. Second parameter is arbitrary here.
    List<Booking> actualBookings = bookingManager.deleteBooking(existingSingleBooking, true);

    // ASSERT
    // Verify the returned list of bookings is same as that returned from
    // the optimistic persister.
    for (Booking expectedBooking : expectedBookingsAfterCall) {
        assertTrue("Expected " + expectedBooking.toString(), actualBookings.contains(expectedBooking));
        actualBookings.removeIf(booking -> booking.equals(expectedBooking));
    }
    assertTrue("More bookings than expected were returned", actualBookings.size() == 0);
}

From source file:squash.booking.lambdas.core.BookingManagerTest.java

@Test
public void testCreateBookingReturnsCorrectBookings() throws Exception {
    // ARRANGE/* w ww.j  a v  a  2  s . c o m*/
    initialiseBookingManager();

    // Set up mock optimistic persister to expect a booking to be created
    expectCreateBookingToReturnUpdatedBookingsOrThrow(bookingsBeforeCall, singleBookingOfFreeCourt,
            Optional.empty());
    expectedBookingsAfterCall.addAll(bookingsBeforeCall);
    expectedBookingsAfterCall.add(singleBookingOfFreeCourt);

    // Act
    // N.B. Second parameter is arbitrary here.
    List<Booking> actualBookings = bookingManager.createBooking(singleBookingOfFreeCourt, true);

    // ASSERT
    // Verify the returned list of bookings is same as that returned from the
    // optimistic persister.
    for (Booking expectedBooking : expectedBookingsAfterCall) {
        assertTrue("Expected " + expectedBooking.toString(), actualBookings.contains(expectedBooking));
        actualBookings.removeIf(booking -> booking.equals(expectedBooking));
    }
    assertTrue("More bookings than expected were returned", actualBookings.size() == 0);
}