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:ninja.leaping.permissionsex.backend.sql.SqlSubjectData.java

@Override
public Map<Set<Entry<String, String>>, List<Entry<String, String>>> getAllParents() {
    return Maps.filterValues(
            Maps.transformValues(segments, dataEntry -> dataEntry == null ? null
                    : dataEntry.getParents() == null ? null : ImmutableList.copyOf(dataEntry.getParents())),
            v -> v != null);//from   w ww  . ja  va 2s  . com
}

From source file:com.isotrol.impe3.core.config.ConfigurationDefinition.java

/**
 * Returns the configuration parameters that are required and have no default value.
 * @return The "must be provided" configuration parameters.
 *///from w  w  w.j  a v  a  2  s.  co m
public Map<String, Item> getMBPParameters() {
    return Maps.filterValues(parameters, IS_MBP);
}

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

@Override
public void register(final Set<String> componentIds) {
    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);//from   w ww  .  j a  v a 2s. c  o  m
    }

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

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

    HttpPost registerRequest = null;
    String currentNamespace = null;

    try {

        if (availableOrReservedSctIds.size() > 1) {
            final Multimap<String, String> componentIdsByNamespace = toNamespaceMultimap(
                    availableOrReservedSctIds.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 registration request for namespace %s with size %d.",
                                    currentNamespace, bulkIds.size()));
                    registerRequest = httpPost(String.format("sct/bulk/register?token=%s", getToken()),
                            createBulkRegistrationData(bulkIds));
                    execute(registerRequest);
                }
            }

        } else {

            final String componentId = Iterables.getOnlyElement(availableOrReservedSctIds.keySet());
            currentNamespace = SnomedIdentifiers.getNamespace(componentId);
            registerRequest = httpPost(String.format("sct/register?token=%s", getToken()),
                    createRegistrationData(componentId));
            execute(registerRequest);
        }

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

From source file:gg.uhc.uhc.modules.death.DeathStandsModule.java

@EventHandler
public void on(PlayerArmorStandManipulateEvent event) {
    ArmorStand stand = event.getRightClicked();

    if (!isProtectedArmourStand(stand))
        return;//ww w  . ja  va  2  s .  com

    ItemStack players = event.getPlayerItem();
    ItemStack stands = event.getArmorStandItem();

    // if the player is holding something it will be a swap
    if (players == null || players.getType() != Material.AIR)
        return;

    // if the stand hasn't got something then the player is adding
    // items or nothing will happen
    if (stands == null || stands.getType() == Material.AIR)
        return;

    // they're removing an item from the armour stand. If there
    // is only 1 item on the stand then this is the final item
    // on the armour stand so kill it (fire optional)
    if (Maps.filterValues(getItems(stand), Predicates.not(EMPTY_ITEM)).values().size() == 1) {
        stand.remove();
    }
}

From source file:net.malisis.doors.door.DoorRegistry.java

public static Map<String, IDoorSound> listSounds() {
    return Maps.filterValues(sounds, new Predicate<IDoorSound>() {
        @Override//from  w  w  w  .ja  v  a2s. c  om
        public boolean apply(IDoorSound input) {
            return !(input instanceof RustyHatchSound);
        }
    });
}

From source file:org.cinchapi.concourse.server.storage.temp.Limbo.java

/**
 * Calculate the browsable view of {@code record} at {@code timestamp} using
 * prior {@code context} as if it were also a part of the Buffer.
 * /*from w w  w. j ava  2  s . c o  m*/
 * @param key
 * @param timestamp
 * @param context
 * @return a possibly empty Map of data
 */
public Map<String, Set<TObject>> browse(long record, long timestamp, Map<String, Set<TObject>> context) {
    Iterator<Write> it = iterator();
    while (it.hasNext()) {
        Write write = it.next();
        if (write.getRecord().longValue() == record && write.getVersion() <= timestamp) {
            Set<TObject> values;
            values = context.get(write.getKey().toString());
            if (values == null) {
                values = Sets.newHashSet();
                context.put(write.getKey().toString(), values);
            }
            if (write.getType() == Action.ADD) {
                values.add(write.getValue().getTObject());
            } else {
                values.remove(write.getValue().getTObject());
            }
        } else if (write.getVersion() > timestamp) {
            break;
        } else {
            continue;
        }
    }
    return Maps.newTreeMap((SortedMap<String, Set<TObject>>) Maps.filterValues(context, emptySetFilter));
}

From source file:org.eclipse.sirius.ui.business.api.viewpoint.ViewpointSelection.java

/**
 * Create a selection wizard page to select a viewpoint.
 *
 * @param fileExtension/*from  w w  w  . ja  v  a 2  s . co m*/
 *            the semantic file extension.
 * @param viewpointsMap
 *            an empty map, which will be filled
 * @return the wizard page
 * @since 0.9.0
 */
public static WizardPage createWizardPage(final String fileExtension,
        final SortedMap<Viewpoint, Boolean> viewpointsMap) {
    final SortedSet<Viewpoint> viewpoints = new TreeSet<Viewpoint>(new ViewpointRegistry.ViewpointComparator());
    viewpoints.addAll(ViewpointSelection.getViewpoints(fileExtension));

    for (final Viewpoint viewpoint : viewpoints) {
        viewpointsMap.put(viewpoint, Boolean.FALSE);
    }

    final WizardPage page = new WizardPage(ViewpointSelection.VIEWPOINTS_SELECTION_WIZARD_PAGE_ID,
            ViewpointSelection.VIEWPOINT_SELECTION_WIZARD_PAGE_TITLE, null) {

        @Override
        public void createControl(final Composite parent) {
            setControl(ViewpointSelection.createViewpointsTableControl(parent, this.getContainer(),
                    viewpointsMap));
        }

        private boolean isThereOneSelectedViewpoint() {
            return Maps.filterValues(viewpointsMap, new Predicate<Boolean>() {
                @Override
                public boolean apply(final Boolean input) {
                    return input.booleanValue();
                }
            }).entrySet().iterator().hasNext();
        }

        @Override
        public boolean isPageComplete() {
            return super.isPageComplete() && isThereOneSelectedViewpoint();
        }

    };
    return page;
}

From source file:com.eucalyptus.event.AbstractNamedRegistry.java

public TYPE enableFirst(Predicate<TYPE> filter) throws NoSuchElementException {
    this.canHas.writeLock().lock();
    try {//from  w  ww . j a  v a2 s . c  o m
        TYPE first = Maps.filterValues(this.disabledMap, filter).values().iterator().next();
        if (first == null) {
            throw new NoSuchElementException("Disabled map is empty.");
        }
        this.activeMap.put(first.getName(), first);
        return first;
    } finally {
        this.canHas.writeLock().unlock();
    }
}

From source file:com.isotrol.impe3.core.modules.ModuleDefinition.java

/**
 * Return the required external dependencies.
 * @return The required external dependencies.
 */// w  w w. ja va 2s .  c o  m
public final Map<String, Dependency> getRequiredExternalDependencies() {
    return Maps.filterValues(getExternalDependencies(), Dependency.IS_REQUIRED);
}

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

@Override
public void publish(final Set<String> componentIds) {
    LOGGER.debug("Publishing {} 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))));

    final Map<String, SctId> assignedSctIds = ImmutableMap.copyOf(Maps.filterValues(sctIds, SctId::isAssigned));

    for (final SctId sctId : assignedSctIds.values()) {
        sctId.setStatus(IdentifierStatus.PUBLISHED.getSerializedName());
    }//from  ww w.  j a v  a 2s .  com

    putSctIds(assignedSctIds);

    if (!problemSctIds.isEmpty()) {
        LOGGER.warn(
                "Cannot publish the following component IDs because they are not assigned or already published: {}",
                problemSctIds);
    }
}