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.eclipse.sirius.diagram.ui.tools.internal.layout.LayoutDataHelperImpl.java

/**
 * {@inheritDoc}//from   w  w w.j  a v  a 2s  . c o m
 */
@Override
public Map<? extends LayoutDataKey, ? extends AbstractLayoutData> getRootLayoutData(
        final Map<? extends LayoutDataKey, ? extends AbstractLayoutData> collection) {
    return Maps.filterValues(collection, ROOT_PREDICATE);
}

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

@Override
public Map<Set<Entry<String, String>>, Integer> getAllDefaultValues() {
    return Maps.filterValues(
            Maps.transformValues(contexts, dataEntry -> dataEntry == null ? null : dataEntry.defaultValue),
            v -> v != null);//  w  w w. j  a  v  a2s .  c  o m
}

From source file:com.b2international.snowowl.snomed.datastore.request.DescriptionRequestHelper.java

private Map<String, SnomedDescription> extractFirst(
        Multimap<String, SnomedDescription> descriptionsByConceptId) {
    Map<String, SnomedDescription> uniqueMap = Maps.transformValues(descriptionsByConceptId.asMap(),
            values -> Iterables.getFirst(values, null));
    return ImmutableMap.copyOf(Maps.filterValues(uniqueMap, Predicates.notNull()));
}

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

private CommunityEntity fill(CommunityEntity entity, CommunityDTO dto) {
    final Calendar date = Calendar.getInstance();
    date.setTime(dto.getDate());//from w  w w  . j  ava2s .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:org.eclipse.sirius.diagram.ui.tools.internal.format.FormatDataHelperImpl.java

/**
 * {@inheritDoc}//w w  w  .  j a va 2s  .  c  om
 */
@Override
public Map<? extends FormatDataKey, ? extends AbstractFormatData> getRootFormatData(
        final Map<? extends FormatDataKey, ? extends AbstractFormatData> collection) {
    return Maps.filterValues(collection, ROOT_PREDICATE);
}

From source file:com.b2international.snowowl.snomed.datastore.id.cis.CisSnomedIdentifierService.java

@Override
public void deprecate(final Set<String> componentIds) {
    LOGGER.debug("Deprecating {} 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::isPublished, SctId::isDeprecated))));

    if (!problemSctIds.isEmpty()) {
        throw new SctIdStatusException(
                "Cannot deprecate %s component IDs because they are not assigned, published, or already deprecated.",
                problemSctIds);/*ww  w . j a va2s .  co  m*/
    }

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

    if (assignedOrPublishedSctIds.isEmpty()) {
        return;
    }

    HttpPut deprecateRequest = null;
    String currentNamespace = null;

    try {

        if (assignedOrPublishedSctIds.size() > 1) {
            final Multimap<String, String> componentIdsByNamespace = toNamespaceMultimap(
                    assignedOrPublishedSctIds.keySet());
            for (final Entry<String, Collection<String>> entry : componentIdsByNamespace.asMap().entrySet()) {
                currentNamespace = entry.getKey();

                for (final Collection<String> bulkIds : Iterables.partition(entry.getValue(), BULK_LIMIT)) {
                    LOGGER.debug(
                            String.format("Sending bulk deprecation request for namespace %s with size %d.",
                                    currentNamespace, bulkIds.size()));
                    deprecateRequest = httpPut(String.format("sct/bulk/deprecate?token=%s", getToken()),
                            createBulkDeprecationData(currentNamespace, bulkIds));
                    execute(deprecateRequest);
                }
            }

        } else {

            final String componentId = Iterables.getOnlyElement(assignedOrPublishedSctIds.keySet());
            currentNamespace = SnomedIdentifiers.getNamespace(componentId);
            deprecateRequest = httpPut(String.format("sct/deprecate?token=%s", getToken()),
                    createDeprecationData(componentId));
            execute(deprecateRequest);
        }

    } catch (IOException e) {
        throw new SnowowlRuntimeException(
                String.format("Exception while deprecating IDs for namespace %s.", currentNamespace), e);
    } finally {
        release(deprecateRequest);
    }
}

From source file:org.syncany.gui.tray.TrayIcon.java

private void updateSyncStatus(String root, boolean syncStatus) {
    clientSyncStatus.put(root, syncStatus);
    logger.log(Level.FINE, "Sync status for " + root + ": " + syncStatus);

    // Update 'syncing' variable: Set true if any of the folders is syncing
    Map<String, Boolean> syncingFolders = Maps.filterValues(clientSyncStatus, new Predicate<Boolean>() {
        @Override/*from   w  w  w .  j  a  v  a2 s. com*/
        public boolean apply(Boolean syncStatus) {
            return syncStatus;
        }
    });

    syncing.set(syncingFolders.size() > 0);
}

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

@Override
public Map<Set<Entry<String, String>>, Integer> getAllDefaultValues() {
    return Maps.filterValues(Maps.transformValues(contexts, new Function<DataEntry, Integer>() {
        @Nullable//from w  ww .j a v a 2s  .  c o m
        @Override
        public Integer apply(@Nullable DataEntry dataEntry) {
            return dataEntry == null ? null : dataEntry.defaultValue;
        }
    }), Predicates.notNull());
}

From source file:net.hillsdon.reviki.web.pages.impl.DefaultPageImpl.java

public View editor(final PageReference page, final ConsumedPath path, final HttpServletRequest request,
        final HttpServletResponse response) throws Exception {
    final boolean preview = request.getParameter(SUBMIT_PREVIEW) != null;
    VersionedPageInfo pageInfo = _store.getUnderlying().tryToLock(page);
    request.setAttribute(ATTR_PAGE_INFO, pageInfo);
    request.setAttribute(ATTR_ORIGINAL_ATTRIBUTES, pageInfo.getAttributes());
    copySessionIdAsAttribute(request);//  w w  w.j  a  va2 s  .c  o  m
    if (!isLockTokenValid(pageInfo, request, preview)) {
        if (preview) {
            return diffEditorView(page, null, request);
        } else {
            request.setAttribute("flash", "Could not lock the page.");
            return new JspView("ViewPage");
        }
    } else {
        if (preview) {
            if (!isSessionIdValid(request)) {
                return diffEditorView(page, ERROR_SESSION_EXPIRED, request);
            } else {
                final String oldContent = pageInfo.getContent();
                final String newContent = getContent(request);
                pageInfo = pageInfo.withAlternativeContent(newContent);
                pageInfo = pageInfo.withAlternativeAttributes(
                        Maps.filterValues(getAttributes(request), new Predicate<String>() {
                            public boolean apply(final String value) {
                                if (value == null) {
                                    return false;
                                }
                                return true;
                            }
                        }));
                request.setAttribute(ATTR_PAGE_INFO, pageInfo);
                String rendered = _renderers.getDefaultRenderer()
                        .render(pageInfo, new ResponseSessionURLOutputFilter(request, response)).get();
                request.setAttribute(ATTR_PREVIEW, rendered);
                request.setAttribute(ATTR_MARKED_UP_DIFF, _diffGenerator.getDiffMarkup(oldContent, newContent));
            }
        }
        return new JspView("EditPage");
    }
}

From source file:org.linagora.linshare.ldap.JScriptLdapQuery.java

/**
 * Filtering database LDAP attributes map to get only attributes needed for
 * completion./*from  w  ww  .  j  a v a2 s . com*/
 * 
 * @return
 */
private Map<String, LdapAttribute> getLdapDbAttributeForCompletion() {
    Map<String, LdapAttribute> dbAttributes = domainPattern.getAttributes();
    Predicate<LdapAttribute> completionFilter = new Predicate<LdapAttribute>() {
        public boolean apply(LdapAttribute attr) {
            if (attr.getEnable()) {
                // Is attribute needed for completion ?
                return attr.getCompletion();
            }
            return false;
        }
    };

    Map<String, LdapAttribute> filterValues = Maps.filterValues(dbAttributes, completionFilter);
    return filterValues;
}