Example usage for com.google.common.collect Iterables removeIf

List of usage examples for com.google.common.collect Iterables removeIf

Introduction

In this page you can find the example usage for com.google.common.collect Iterables removeIf.

Prototype

public static <T> boolean removeIf(Iterable<T> removeFrom, Predicate<? super T> predicate) 

Source Link

Document

Removes, from an iterable, every element that satisfies the provided predicate.

Usage

From source file:org.apache.phoenix.filter.EncodedQualifiersColumnProjectionFilter.java

@Override
public void filterRowCells(List<Cell> kvs) throws IOException {
    if (kvs.isEmpty())
        return;/* w  ww . j a v a 2s.c om*/
    Cell firstKV = kvs.get(0);
    Iterables.removeIf(kvs, new Predicate<Cell>() {
        @Override
        public boolean apply(Cell kv) {
            int qualifier = encodingScheme.decode(kv.getQualifierArray(), kv.getQualifierOffset(),
                    kv.getQualifierLength());
            return !trackedColumns.get(qualifier);
        }
    });
    if (kvs.isEmpty()) {
        kvs.add(new KeyValue(firstKV.getRowArray(), firstKV.getRowOffset(), firstKV.getRowLength(),
                this.emptyCFName, 0, this.emptyCFName.length, ENCODED_EMPTY_COLUMN_BYTES, 0,
                ENCODED_EMPTY_COLUMN_BYTES.length, HConstants.LATEST_TIMESTAMP, Type.Maximum, null, 0, 0));
    }
}

From source file:org.obiba.onyx.quartz.editor.locale.LocaleProperties.java

public void removeValue(IQuestionnaireElement element, final String key) {
    for (Locale locale : getLocales()) {
        ListMultimap<Locale, KeyValue> labels = getElementLabels(element);
        if (labels != null) {
            List<KeyValue> keyValueList = labels.get(locale);
            if (keyValueList != null && !keyValueList.isEmpty()) {
                Iterables.removeIf(keyValueList, new Predicate<KeyValue>() {
                    @Override/*from  w ww  .j  a v  a2  s  . c o m*/
                    public boolean apply(@Nullable KeyValue keyValue) {
                        return keyValue != null && StringUtils.equals(keyValue.getKey(), key);
                    }
                });
            }
        }
    }
}

From source file:org.syncany.config.DaemonConfigHelper.java

public static boolean removeFolder(String localDirIdentifier) throws ConfigException {
    File daemonConfigFile = new File(UserConfig.getUserConfigDir(), UserConfig.DAEMON_FILE);

    if (daemonConfigFile.exists()) {
        DaemonConfigTO daemonConfigTO = DaemonConfigTO.load(daemonConfigFile);

        // Is index?
        Integer localDirIndex = Ints.tryParse(localDirIdentifier);
        boolean isLocalDirIndex = localDirIndex != null;
        boolean folderRemoved = false;

        // Remove by index
        if (isLocalDirIndex) {
            localDirIndex--;/*from   ww  w .  j  ava2  s.c  o  m*/

            if (localDirIndex >= 0 && localDirIndex < daemonConfigTO.getFolders().size()) {
                logger.log(Level.INFO, "Given identifier (" + localDirIndex + ") is a valid index for "
                        + daemonConfigTO.getFolders().get(localDirIndex).getPath() + ". REMOVING.");
                folderRemoved = null != daemonConfigTO.getFolders().remove((int) localDirIndex);
            } else {
                logger.log(Level.INFO,
                        "Given identifier (" + localDirIndex + ") is a INVALID index. NOT REMOVING.");
            }
        }

        // Remove by name/path
        else {
            final String localDirPath = FileUtil.getCanonicalFile(new File(localDirIdentifier))
                    .getAbsolutePath();

            folderRemoved = Iterables.removeIf(daemonConfigTO.getFolders(), new Predicate<FolderTO>() {
                @Override
                public boolean apply(FolderTO folder) {
                    return folder.getPath().equals(localDirPath);
                }
            });
        }

        // Save (if removed)
        if (folderRemoved) {
            logger.log(Level.INFO, "Folder was removed. Saving daemon.xml ...");

            daemonConfigTO.save(daemonConfigFile);
            return true;
        } else {
            return false;
        }
    } else {
        createAndWriteDaemonConfig(daemonConfigFile, Arrays.asList(new FolderTO[] {}));
        return true;
    }
}

From source file:me.gladwell.eclipse.m2e.android.JUnitClasspathProvider.java

private void removeMavenBuildOutputFolder(ILaunchConfiguration config, List<IRuntimeClasspathEntry> classpath)
        throws CoreException {
    IProject project = workspace.getRoot().getProject(config.getAttribute(ATTR_PROJECT_NAME, (String) null));
    IDEAndroidProject androidProject = eclipseFactory.createAndroidProject(project);
    MavenAndroidProject mavenProject = mavenFactory.createAndroidProject(androidProject);

    final String mavenOutputDirectory = mavenProject.getOutputDirectory();
    Path mavenOutputDirectoryPath = new Path(mavenOutputDirectory);
    IPath binFolderPath = project.getFolder("bin" + File.separator + "classes").getLocation();

    if (!mavenOutputDirectoryPath.equals(binFolderPath)) {
        Iterables.removeIf(classpath, new Predicate<IRuntimeClasspathEntry>() {

            public boolean apply(IRuntimeClasspathEntry entry) {
                return mavenOutputDirectory.equals(entry.getLocation());
            }/* www.ja  v a2  s  .  co  m*/
        });
    }
}

From source file:clocker.docker.location.strategy.basic.GroupPlacementStrategy.java

@Override
public List<DockerHostLocation> filterLocations(List<DockerHostLocation> locations, Entity entity) {
    if (locations == null || locations.isEmpty()) {
        return ImmutableList.of();
    }/*from  ww w . ja  va  2 s  .  c o m*/
    if (getDockerInfrastructure() == null)
        config().set(DOCKER_INFRASTRUCTURE, Iterables.getLast(locations).getDockerInfrastructure());
    List<DockerHostLocation> available = MutableList.copyOf(locations);
    boolean requireExclusive = config().get(REQUIRE_EXCLUSIVE);

    try {
        acquireMutex(entity.getApplicationId(), "Filtering locations for " + entity);
    } catch (InterruptedException ie) {
        Exceptions.propagate(ie); // Should never happen...
    }

    // Find hosts with entities from our application deployed there
    Iterable<DockerHostLocation> sameApplication = Iterables.filter(available,
            hasApplicationId(entity.getApplicationId()));

    // Check if hosts have any deployed entities that share a parent with the input entity
    Optional<DockerHostLocation> sameParent = Iterables.tryFind(sameApplication,
            childrenOf(entity.getParent()));
    if (sameParent.isPresent()) {
        LOG.debug("Returning {} (same parent) for {} placement", sameParent.get(), entity);
        return ImmutableList.copyOf(sameParent.asSet());
    }

    // Remove hosts if they have any entities from our application deployed there
    Iterables.removeIf(available, hasApplicationId(entity.getApplicationId()));
    if (requireExclusive) {
        Iterables.removeIf(available, nonEmpty());
    }
    LOG.debug("Returning {} for {} placement", Iterables.toString(available), entity);
    return available;
}

From source file:it.f2informatica.core.services.ConsultantServiceImpl.java

private LanguageModel[] removeFurtherEmptyLanguages(LanguageModel[] languageModels) {
    List<LanguageModel> languages = Lists.newArrayList(languageModels);
    Iterables.removeIf(languages, DOES_NOT_HAVE_ITEM_TO_ADD);
    return Iterables.toArray(languages, LanguageModel.class);
}

From source file:com.btmatthews.atlas.core.common.PagingBuilder.java

/**
 * Remove the sort ordering./*from ww  w . ja  va2  s  .  co  m*/
 *
 * @param field The field name.
 * @return Always returns the {@link PagingBuilder} object.
 */
public PagingBuilder removeOrdering(final String field) {
    Iterables.removeIf(sortOrderings, findOrdering(field));
    return this;
}

From source file:org.bonitasoft.connectors.rest.AbstractRESTConnectorImpl.java

protected final java.util.List getUrlHeaders() {
    final java.util.List headers = (java.util.List) getInputParameter(URLHEADERS_INPUT_PARAMETER);
    Iterables.removeIf(headers, emptyLines());
    return headers;
}

From source file:org.eclipse.wb.internal.swing.model.bean.AbstractActionInfo.java

private List<Property> createProperties() throws Exception {
    CreationSupport creationSupport = getCreationSupport();
    // no additional properties available
    if (!(creationSupport instanceof IActionSupport)) {
        return Lists.newArrayList();
    }/*from   w w  w .j a  va2 s.  c o m*/
    // create properties
    List<Property> properties = Lists.newArrayList();
    properties.add(createStringProperty("name", "NAME"));
    properties.add(createStringProperty("short description", "SHORT_DESCRIPTION"));
    properties.add(createStringProperty("long description", "LONG_DESCRIPTION"));
    properties.add(createIconProperty("small icon", "SMALL_ICON"));
    properties.add(createStringProperty("action command", "ACTION_COMMAND_KEY"));
    properties.add(createProperty("accelerator", "ACCELERATOR_KEY", null, KeyStrokePropertyEditor.INSTANCE));
    properties
            .add(createProperty("mnemonic", "MNEMONIC_KEY", null, DisplayedMnemonicKeyPropertyEditor.INSTANCE));
    if (SystemUtils.JAVA_VERSION_FLOAT >= 1.6) {
        properties.add(createProperty("displayed mnemonic index", "DISPLAYED_MNEMONIC_INDEX_KEY",
                IntegerConverter.INSTANCE, IntegerPropertyEditor.INSTANCE));
        properties.add(createIconProperty("large icon", "LARGE_ICON_KEY"));
    }
    // remove null-s
    Iterables.removeIf(properties, Predicates.isNull());
    return properties;
}

From source file:org.eclipse.osee.define.report.internal.SafetyInformationAccumulator.java

private List<ArtifactReadable> checkSubsystemRequirements(ArtifactReadable subsystemFunction) {

    // needs related artifacts
    List<ArtifactReadable> localSubsystemRequirements = Lists
            .newArrayList(subsystemFunction.getRelated(CoreRelationTypes.Design__Requirement));

    Iterator<ArtifactReadable> ssrIter = localSubsystemRequirements.iterator();
    while (ssrIter.hasNext()) {
        ArtifactReadable subsystemRequirement = ssrIter.next();
        List<ArtifactReadable> localSoftwareRequirements = Lists.newArrayList(
                subsystemRequirement.getRelated(CoreRelationTypes.Requirement_Trace__Lower_Level));

        // test software requirements for suitability - is it a subclass of software requirement?
        Iterables.removeIf(localSoftwareRequirements, notAbstractSoftwareRequirement);

        if (localSoftwareRequirements.isEmpty()) {
            //remove the subsystemRequirement
            ssrIter.remove();/* w  ww  .  j  av a2 s.c  om*/
        } else {
            // save
            softwareRequirements.put(subsystemRequirement, localSoftwareRequirements);
        }
    }
    return localSubsystemRequirements;
}