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.sonar.plugins.csharp.gallio.results.coverage.AbstractParsingStrategy.java

public List<FileCoverage> parse(final SensorContext context, VisualStudioSolution solution,
        final Project sonarProject, SMInputCursor root) {

    SMInputCursor rootChildCursor = descendantElements(root);

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

    if (sourceFilesById.isEmpty()) {
        // no source, there is no point to parse further
        return Collections.EMPTY_LIST;
    }/*  w  w w .  j a  v  a 2 s  .c o m*/

    // 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);

    List<FileCoverage> sourceFiles = new ArrayList<FileCoverage>(sourceFilesById.values());
    return sourceFiles;
}

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

@Override
public void release(final Set<String> componentIds) {
    LOGGER.debug("Releasing {} 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::isAssigned, SctId::isReserved, SctId::isAvailable))));

    if (!problemSctIds.isEmpty()) {
        throw new SctIdStatusException(
                "Cannot release %s component IDs because they are not assigned, reserved, or already available.",
                problemSctIds);/*from  www .  ja v a2s .c  o m*/
    }

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

    // XXX: It might be better to keep the last state change recorded in the index on these SctIds, but for now we remove them entirely
    removeSctIds(assignedOrReservedSctIds.keySet());
}

From source file:org.apache.gobblin.metrics.event.sla.SlaEventSubmitter.java

/**
 * Builds an EventMetadata {@link Map} from the {@link #SlaEventSubmitter}. The method filters out metadata by
 * applying {@link #NOT_NULL_OR_EMPTY_PREDICATE}
 *
 *//*from  w  w  w  .j av  a 2 s  .c  o  m*/
private Map<String, String> buildEventMap() {

    Map<String, String> eventMetadataMap = Maps.newHashMap();
    eventMetadataMap.put(withoutPropertiesPrefix(SlaEventKeys.DATASET_URN_KEY), datasetUrn);
    eventMetadataMap.put(withoutPropertiesPrefix(SlaEventKeys.PARTITION_KEY), partition);
    eventMetadataMap.put(withoutPropertiesPrefix(SlaEventKeys.ORIGIN_TS_IN_MILLI_SECS_KEY), originTimestamp);
    eventMetadataMap.put(withoutPropertiesPrefix(SlaEventKeys.UPSTREAM_TS_IN_MILLI_SECS_KEY),
            upstreamTimestamp);
    eventMetadataMap.put(withoutPropertiesPrefix(SlaEventKeys.COMPLETENESS_PERCENTAGE_KEY),
            completenessPercentage);
    eventMetadataMap.put(withoutPropertiesPrefix(SlaEventKeys.RECORD_COUNT_KEY), recordCount);
    eventMetadataMap.put(withoutPropertiesPrefix(SlaEventKeys.PREVIOUS_PUBLISH_TS_IN_MILLI_SECS_KEY),
            previousPublishTimestamp);
    eventMetadataMap.put(withoutPropertiesPrefix(SlaEventKeys.DEDUPE_STATUS_KEY), dedupeStatus);
    eventMetadataMap.put(withoutPropertiesPrefix(SlaEventKeys.IS_FIRST_PUBLISH), isFirstPublish);

    if (additionalMetadata != null) {
        eventMetadataMap.putAll(additionalMetadata);
    }
    return Maps.newHashMap(Maps.filterValues(eventMetadataMap, NOT_NULL_OR_EMPTY_PREDICATE));
}

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

@Override
public Map<Set<Map.Entry<String, String>>, Integer> getAllDefaultValues() {
    return Maps.filterValues(Maps.asMap(getActiveContexts(), this::getDefaultValue),
            input -> input != null && input != 0);
}

From source file:org.apache.hadoop.hive.metastore.utils.MetaStoreServerUtils.java

/**
 * We have a need to sanity-check the map before conversion from persisted objects to
 * metadata thrift objects because null values in maps will cause a NPE if we send
 * across thrift. Pruning is appropriate for most cases except for databases such as
 * Oracle where Empty strings are stored as nulls, in which case we need to handle that.
 * See HIVE-8485 for motivations for this.
 *//* w  w w  . j av  a2 s  . co m*/
public static Map<String, String> trimMapNulls(Map<String, String> dnMap,
        boolean retrieveMapNullsAsEmptyStrings) {
    if (dnMap == null) {
        return null;
    }
    // Must be deterministic order map - see HIVE-8707
    //   => we use Maps.newLinkedHashMap instead of Maps.newHashMap
    if (retrieveMapNullsAsEmptyStrings) {
        // convert any nulls present in map values to empty strings - this is done in the case
        // of backing dbs like oracle which persist empty strings as nulls.
        return Maps.newLinkedHashMap(Maps.transformValues(dnMap, transFormNullsToEmptyString));
    } else {
        // prune any nulls present in map values - this is the typical case.
        return Maps.newLinkedHashMap(Maps.filterValues(dnMap, Predicates.notNull()));
    }
}

From source file:org.jclouds.openstack.nova.v1_1.domain.Image.java

public Map<String, String> getMetadata() {
    // in case this was assigned in gson
    return ImmutableMap.copyOf(Maps.filterValues(this.metadata, Predicates.notNull()));
}

From source file:com.isotrol.impe3.web20.impl.MigrationServiceImpl.java

private CommunityEntity fillCommunity(CommunityEntity entity, CommunityDTO dto) {
    final Calendar date = Calendar.getInstance();
    date.setTime(dto.getDate());/*from w  ww  . ja v a 2 s  .  c o  m*/
    entity.setDate(date);
    entity.setDescription(dto.getDescription());
    entity.setCode(dto.getCode());
    entity.setName(dto.getName());

    final Map<String, String> properties = entity.getProperties();
    properties.clear();
    final Map<String, String> dtopr = dto.getProperties();
    if (dtopr != null) {
        properties.putAll(Maps.filterKeys(Maps.filterValues(dtopr, notNull()), notNull()));
    }

    return entity;
}

From source file:ninja.leaping.permissionsex.backend.memory.MemorySubjectData.java

@Override
public Map<Set<Entry<String, String>>, Map<String, String>> getAllOptions() {
    return Maps.filterValues(
            Maps.transformValues(contexts, dataEntry -> dataEntry == null ? null : dataEntry.options),
            el -> el != null);//  w  w w  .  ja  v  a 2s.  com
}

From source file:com.github.sevntu.checkstyle.domain.BaseCheckTestSupport.java

protected void verify(Checker checker, File[] processedFiles, Map<String, List<String>> expectedViolations)
        throws Exception {
    stream.flush();/* w  ww .j  a v a2 s.  c om*/
    final List<File> theFiles = Lists.newArrayList();
    Collections.addAll(theFiles, processedFiles);
    final int errs = checker.process(theFiles);

    // process each of the lines
    final Map<String, List<String>> actualViolations = getActualViolations(errs);
    final Map<String, List<String>> realExpectedViolations = Maps.filterValues(expectedViolations,
            new Predicate<List<String>>() {
                @Override
                public boolean apply(List<String> input) {
                    return !input.isEmpty();
                }
            });
    final MapDifference<String, List<String>> violationDifferences = Maps.difference(realExpectedViolations,
            actualViolations);

    final Map<String, List<String>> missingViolations = violationDifferences.entriesOnlyOnLeft();
    final Map<String, List<String>> unexpectedViolations = violationDifferences.entriesOnlyOnRight();
    final Map<String, ValueDifference<List<String>>> differingViolations = violationDifferences
            .entriesDiffering();

    final StringBuilder message = new StringBuilder();
    if (!missingViolations.isEmpty()) {
        message.append("missing violations: ").append(missingViolations);
    }
    if (!unexpectedViolations.isEmpty()) {
        if (message.length() > 0) {
            message.append('\n');
        }
        message.append("unexpected violations: ").append(unexpectedViolations);
    }
    if (!differingViolations.isEmpty()) {
        if (message.length() > 0) {
            message.append('\n');
        }
        message.append("differing violations: ").append(differingViolations);
    }

    assertTrue(message.toString(),
            missingViolations.isEmpty() && unexpectedViolations.isEmpty() && differingViolations.isEmpty());

    checker.destroy();
}

From source file:ninja.leaping.permissionsex.backend.memory.MemoryOptionSubjectData.java

@Override
public Map<Set<Entry<String, String>>, Map<String, String>> getAllOptions() {
    return Maps.filterValues(Maps.transformValues(contexts, new Function<DataEntry, Map<String, String>>() {
        @Nullable/*from w  ww.j a va  2 s  .  com*/
        @Override
        public Map<String, String> apply(@Nullable DataEntry dataEntry) {
            return dataEntry == null ? null : dataEntry.options;
        }
    }), Predicates.notNull());
}