Example usage for com.google.common.collect Maps filterValues

List of usage examples for com.google.common.collect Maps filterValues

Introduction

In this page you can find the example usage for com.google.common.collect Maps filterValues.

Prototype

@CheckReturnValue
public static <K, V> BiMap<K, V> filterValues(BiMap<K, V> unfiltered,
        final Predicate<? super V> valuePredicate) 

Source Link

Document

Returns a bimap containing the mappings in unfiltered whose values satisfy a predicate.

Usage

From source file:org.jfrog.build.client.ArtifactoryClientConfiguration.java

public void persistToPropertiesFile() {
    if (StringUtils.isEmpty(getPropertiesFile())) {
        return;//ww w .j a  v  a2 s .c  om
    }
    Predicate<String> nonNullPredicate = new Predicate<String>() {
        @Override
        public boolean apply(String input) {
            return StringUtils.isNotBlank(input);
        }
    };
    Properties props = new Properties();
    props.putAll(Maps.filterValues(root.props, nonNullPredicate));
    props.putAll(Maps.filterValues(rootConfig.props, nonNullPredicate));
    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(new File(getPropertiesFile()).getCanonicalFile());
        props.store(fos, "BuildInfo configuration property file");
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        IOUtils.closeQuietly(fos);
    }
}

From source file:com.google.security.zynamics.binnavi.disassembly.types.SectionContainerBackend.java

/**
 * Loads all sections from the database.
 * //  w w w  .j a v a 2 s  . co  m
 * @return The list of all sections.
 * @throws CouldntLoadDataException Thrown if the list of sections could not be determined.
 */
protected List<Section> loadSections() throws CouldntLoadDataException {

    final Map<Section, Integer> sectionToComment = provider.loadSections(module);

    final Map<Section, Integer> sectionWithCommemnt = Maps.filterValues(sectionToComment,
            new Predicate<Integer>() {
                @Override
                public boolean apply(final Integer commentId) {
                    return commentId != null;
                }
            });

    final CommentManager manager = CommentManager.get(provider);
    final HashMap<Integer, ArrayList<IComment>> typeInstanceTocomments = provider
            .loadMultipleCommentsById(sectionWithCommemnt.values());
    for (final Entry<Section, Integer> entry : sectionWithCommemnt.entrySet()) {
        manager.initializeSectionComment(entry.getKey(), typeInstanceTocomments.get(entry.getValue()));
    }

    return Lists.newArrayList(sectionToComment.keySet());
}

From source file:org.sonar.plugins.csharp.gallio.results.coverage.CoverageResultParser.java

/**
 * Parses a file//from  w w w. j  a  v a2  s. c om
 * 
 * @param file
 *          : the file to parse
 * 
 */
public ParserResult parse(final Project sonarProject, final File file) {

    try {
        SMInputFactory inf = new SMInputFactory(XMLInputFactory.newInstance());
        SMHierarchicCursor rootCursor = inf.rootElementCursor(file);
        SMInputCursor root = rootCursor.advance();

        LOG.debug("\nrootCursor is at : {}", findElementName(rootCursor));
        // First define the version
        chooseParsingStrategy(root);

        SMInputCursor rootChildCursor = descendantElements(root);

        // Then all the indexed files are extracted
        sourceFilesById = currentStrategy.findFiles(rootChildCursor);

        if (sourceFilesById.isEmpty()) {
            // no source, ther is no point to parse further
            return new ParserResult(Collections.EMPTY_LIST, Collections.EMPTY_LIST);
        }

        // filter files according to the exclusion patterns
        sourceFilesById = Maps.filterValues(sourceFilesById, new Predicate<FileCoverage>() {

            public boolean apply(FileCoverage input) {
                return context.isIndexed(org.sonar.api.resources.File.fromIOFile(input.getFile(), sonarProject),
                        false);
            }
        });

        // We finally process the coverage details
        fillProjects(rootChildCursor);

        // We summarize the files
        for (FileCoverage fileCoverage : sourceFilesById.values()) {
            fileCoverage.summarize();
        }
        for (ProjectCoverage project : projectsByAssemblyName.values()) {
            LOG.debug("Summarize project: {}", project);
            project.summarize();
        }
    } catch (XMLStreamException e) {
        throw new SonarException("Could not parse the result file", e);
    }
    List<ProjectCoverage> projects = new ArrayList<ProjectCoverage>(projectsByAssemblyName.values());
    List<FileCoverage> sourceFiles = new ArrayList<FileCoverage>(sourceFilesById.values());
    return new ParserResult(projects, sourceFiles);
}

From source file:ninja.leaping.permissionsex.extrabackends.groupmanager.GroupManagerSubjectData.java

@Override
public Map<Set<Map.Entry<String, String>>, List<Map.Entry<String, String>>> getAllParents() {
    return Maps.filterValues(Maps.asMap(getActiveContexts(), this::getParents),
            input -> input != null && !input.isEmpty());
}

From source file:org.apache.beam.runners.spark.aggregators.metrics.WithNamedAggregatorsSupport.java

private Function<Map.Entry<String, Metric>, Map<String, Gauge>> toGauges() {
    return new Function<Map.Entry<String, Metric>, Map<String, Gauge>>() {
        @Override/* w w w .  j  a  va  2 s .c om*/
        public Map<String, Gauge> apply(final Map.Entry<String, Metric> entry) {
            final NamedAggregators agg = ((AggregatorMetric) entry.getValue()).getNamedAggregators();
            final String parentName = entry.getKey();
            final Map<String, Gauge> gaugeMap = Maps.transformEntries(agg.renderAll(), toGauge());
            final Map<String, Gauge> fullNameGaugeMap = Maps.newLinkedHashMap();
            for (Map.Entry<String, Gauge> gaugeEntry : gaugeMap.entrySet()) {
                fullNameGaugeMap.put(parentName + "." + gaugeEntry.getKey(), gaugeEntry.getValue());
            }
            return Maps.filterValues(fullNameGaugeMap, Predicates.notNull());
        }
    };
}

From source file:org.pentaho.di.trans.dataservice.validation.DataServiceStepValidation.java

private Map<String, Set<StepField>> fieldsWithStepsNotSupportingPushdown(
        Map<String, Set<StepField>> originSteps, final Map<String, StepMeta> stepMetaMap) {
    return Maps.filterValues(originSteps, new Predicate<Set<StepField>>() {
        @Override//from   w ww .  j a v a2 s. c o m
        public boolean apply(Set<StepField> stepFields) {
            return !stepFieldsSupportPushDown(stepFields, stepMetaMap);
        }
    });
}

From source file:com.b2international.snowowl.snomed.datastore.id.memory.DefaultSnomedIdentifierService.java

@Override
public void register(final Set<String> componentIds) {
    if (CompareUtils.isEmpty(componentIds)) {
        return;/*from   w  w w  . j a v a 2 s . c o m*/
    }
    LOGGER.debug(String.format("Registering {} component IDs.", componentIds.size()));

    final Map<String, SctId> sctIds = getSctIds(componentIds);
    final Map<String, SctId> problemSctIds = ImmutableMap.copyOf(Maps.filterValues(sctIds,
            Predicates.<SctId>not(Predicates.or(SctId::isAvailable, SctId::isReserved, SctId::isAssigned))));

    if (!problemSctIds.isEmpty()) {
        throw new SctIdStatusException(
                "Cannot register %s component IDs because they are not available, reserved, or already assigned.",
                problemSctIds);
    }

    final Map<String, SctId> availableOrReservedSctIds = ImmutableMap
            .copyOf(Maps.filterValues(sctIds, Predicates.or(SctId::isAvailable, SctId::isReserved)));

    for (final SctId sctId : availableOrReservedSctIds.values()) {
        sctId.setStatus(IdentifierStatus.ASSIGNED.getSerializedName());
    }

    putSctIds(availableOrReservedSctIds);
}

From source file:org.apache.brooklyn.location.jclouds.BlobStoreContextFactoryImpl.java

@Override
public BlobStoreContext newBlobStoreContext(Location location) {
    String rawProvider = checkNotNull(location.getConfig(LocationConfigKeys.CLOUD_PROVIDER),
            "provider must not be null");
    String provider = DeserializingJcloudsRenamesProvider.INSTANCE.applyJcloudsRenames(rawProvider);
    String identity = checkNotNull(location.getConfig(LocationConfigKeys.ACCESS_IDENTITY),
            "identity must not be null");
    String credential = checkNotNull(location.getConfig(LocationConfigKeys.ACCESS_CREDENTIAL),
            "credential must not be null");
    String endpoint = location.getConfig(CloudLocationConfig.CLOUD_ENDPOINT);

    Properties overrides = new Properties();
    // * Java 7,8 bug workaround - sockets closed by GC break the internal bookkeeping
    //   of HttpUrlConnection, leading to invalid handling of the "HTTP/1.1 100 Continue"
    //   response. Coupled with a bug when using SSL sockets reads will block
    //   indefinitely even though a read timeout is explicitly set.
    // * Java 6 ignores the header anyways as it is included in its restricted headers black list.
    // * Also there's a bug in SL object store which still expects Content-Length bytes
    //   even when it responds with a 408 timeout response, leading to incorrectly
    //   interpreting the next request (triggered by above problem).
    overrides.setProperty(Constants.PROPERTY_STRIP_EXPECT_HEADER, "true");

    // Add extra jclouds-specific configuration
    Map<String, Object> extra = Maps.filterKeys(((LocationInternal) location).config().getBag().getAllConfig(),
            Predicates.containsPattern("^jclouds\\."));
    if (extra.size() > 0) {
        LOG.debug("Configuring custom jclouds property overrides for {}: {}", provider,
                Sanitizer.sanitize(extra));
    }/*from w ww.j  a va 2  s  .  c om*/
    overrides.putAll(Maps.filterValues(extra, Predicates.notNull()));

    ContextBuilder contextBuilder = ContextBuilder.newBuilder(provider).credentials(identity, credential);
    contextBuilder.modules(MutableList.copyOf(getCommonModules()));
    if (!org.apache.brooklyn.util.text.Strings.isBlank(endpoint)) {
        contextBuilder.endpoint(endpoint);
    }
    contextBuilder.overrides(overrides);
    BlobStoreContext context = contextBuilder.buildView(BlobStoreContext.class);
    return context;
}

From source file:org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes.java

/**
 * Find duplicate NormalizedNode instances within a subtree. Duplicates are those, which compare
 * as equal, but do not refer to the same object.
 *
 * @param node A normalized node subtree, may not be null
 * @return A Map of NormalizedNode/DuplicateEntry relationships.
 *///  ww w  . j  a  v  a  2s  .  c  o  m
public static Map<NormalizedNode<?, ?>, DuplicateEntry> findDuplicates(
        @Nonnull final NormalizedNode<?, ?> node) {
    return Maps.filterValues(DuplicateFinder.findDuplicates(node), input -> !input.getDuplicates().isEmpty());
}

From source file:org.apache.beam.runners.spark.metrics.WithMetricsSupport.java

private Function<Map.Entry<String, Metric>, Map<String, Gauge>> aggregatorMetricToGauges() {
    return new Function<Map.Entry<String, Metric>, Map<String, Gauge>>() {
        @Override//from w w w  .  j av a 2 s  . co m
        public Map<String, Gauge> apply(final Map.Entry<String, Metric> entry) {
            final NamedAggregators agg = ((AggregatorMetric) entry.getValue()).getNamedAggregators();
            final String parentName = entry.getKey();
            final Map<String, Gauge> gaugeMap = Maps.transformEntries(agg.renderAll(), toGauge());
            final Map<String, Gauge> fullNameGaugeMap = Maps.newLinkedHashMap();
            for (Map.Entry<String, Gauge> gaugeEntry : gaugeMap.entrySet()) {
                fullNameGaugeMap.put(parentName + "." + gaugeEntry.getKey(), gaugeEntry.getValue());
            }
            return Maps.filterValues(fullNameGaugeMap, Predicates.notNull());
        }
    };
}