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.onosproject.store.consistent.impl.MutexExecutionManager.java

/**
 * Detects and releases all locks held by this node.
 *///ww w  .  j  a v a  2s. c o m
private void releaseOldLocks() {
    Maps.filterValues(lockMap.asJavaMap(), state -> localNodeId.equals(state.holder())).keySet()
            .forEach(path -> {
                log.info("Detected zombie task still holding lock for {}. Releasing lock.", path);
                unlock(path);
            });
}

From source file:com.googlecode.jmxtrans.model.output.InfluxDbWriter.java

/**
 * <p>//  w w w.  j  a  v a 2 s.c  o  m
 * Each {@link Result} is written as a {@link Point} to InfluxDB
 * </p>
 *
 * <p>
 * The measurement for the {@link Point} is to {@link Result#getKeyAlias()}
 * <p>
 * <a href=
 * "https://influxdb.com/docs/v0.9/concepts/key_concepts.html#retention-policy">
 * The retention policy</a> for the measurement is set to "default" unless
 * overridden in settings:
 * </p>
 *
 * <p>
 * The write consistency level defaults to "ALL" unless overridden in
 * settings:
 *
 * <ul>
 * <li>ALL = Write succeeds only if write reached all cluster members.</li>
 * <li>ANY = Write succeeds if write reached any cluster members.</li>
 * <li>ONE = Write succeeds if write reached at least one cluster members.
 * </li>
 * <li>QUORUM = Write succeeds only if write reached a quorum of cluster
 * members.</li>
 * </ul>
 *
 * <p>
 * The time key for the {@link Point} is set to {@link Result#getEpoch()}
 * </p>
 *
 * <p>
 * All {@link Result#getValues()} are written as fields to the {@link Point}
 * </p>
 *
 * <p>
 * The following properties from {@link Result} are written as tags to the
 * {@link Point} unless overriden in settings:
 *
 * <ul>
 * <li>{@link Result#getAttributeName()}</li>
 * <li>{@link Result#getClassName()}</li>
 * <li>{@link Result#getObjDomain()}</li>
 * <li>{@link Result#getTypeName()}</li>
 * </ul>
 * <p>
 * {@link Server#getHost()} is set as a tag on every {@link Point}
 * </p>
 *
 */
@Override
public void doWrite(Server server, Query query, Iterable<Result> results) throws Exception {
    // Creates only if it doesn't already exist
    if (createDatabase)
        influxDB.createDatabase(database);

    BatchPoints batchPoints = BatchPoints.database(database).retentionPolicy(retentionPolicy)
            .tag(TAG_HOSTNAME, server.getSource()).consistency(writeConsistency).build();

    for (Result result : results) {

        HashMap<String, Object> filteredValues = newHashMap(Maps.filterValues(result.getValues(), isNotNaN));

        // send the point if filteredValues isn't empty
        if (!filteredValues.isEmpty()) {
            filteredValues.put("_jmx_port", Integer.parseInt(server.getPort()));
            Map<String, String> resultTagsToApply = buildResultTagMap(result);
            Point point = Point.measurement(result.getKeyAlias()).time(result.getEpoch(), MILLISECONDS)
                    .tag(resultTagsToApply).fields(filteredValues).build();
            batchPoints.point(point);
        }

    }

    influxDB.write(batchPoints);
}

From source file:org.onos.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.
 *///from w w w. jav a2  s  .c o  m
public static Map<NormalizedNode<?, ?>, DuplicateEntry> findDuplicates(
        @Nonnull final NormalizedNode<?, ?> node) {
    return Maps.filterValues(DuplicateFinder.findDuplicates(node), DUPLICATES_ONLY);
}

From source file:com.eucalyptus.auth.policy.key.Keys.java

public static Map<String, Key> getKeyInstances(final EvaluationConstraint constraint) {
    return Maps.transformValues(
            Maps.filterValues(KEY_MAP,
                    CollectionUtils.propertyContainsPredicate(constraint, Functions
                            .compose(PolicyKeyToEvaluationConstraints.INSTANCE, KeyClassToPolicyKey.INSTANCE))),
            KeyClassToKeyInstance.INSTANCE);
}

From source file:com.googlecode.blaisemath.style.AttributeSet.java

/**
 * Return attributes of the given type, whether in this set or the parent set.
 * @param type attribute type//from  w  w w  .jav  a  2  s  . c om
 * @return attribute keys
 */
public Set<String> getAllAttributes(Class type) {
    Map<String, Object> filtered = Maps.filterValues(attributeMap, Predicates.instanceOf(type));
    if (parent.isPresent()) {
        return Sets.union(filtered.keySet(), parent.get().getAllAttributes(type));
    } else {
        return filtered.keySet();
    }
}

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

private Function<Map.Entry<String, Metric>, Map<String, Gauge>> beamMetricToGauges() {
    return new Function<Map.Entry<String, Metric>, Map<String, Gauge>>() {
        @Override//ww  w. jav a  2 s.co  m
        public Map<String, Gauge> apply(final Map.Entry<String, Metric> entry) {
            final Map<String, ?> metrics = ((SparkBeamMetric) entry.getValue()).renderAll();
            final String parentName = entry.getKey();
            final Map<String, Gauge> gaugeMap = Maps.transformEntries(metrics, 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:ninja.leaping.permissionsex.backend.sql.SqlSubjectData.java

@Override
public Map<Set<Entry<String, String>>, Map<String, Integer>> getAllPermissions() {
    return Maps.filterValues(
            Maps.transformValues(segments, dataEntry -> dataEntry == null ? null : dataEntry.getPermissions()),
            o -> o != null);/*  w w  w.ja  v a2s .co m*/
}

From source file:co.cask.cdap.internal.app.runtime.adapter.PluginRepository.java

/**
 * Returns a {@link Map.Entry} represents the plugin information for the plugin being requested.
 *
 * @param template name of the template/* ww  w.  j av  a2 s. c  o m*/
 * @param pluginType plugin type name
 * @param pluginName plugin name
 * @param selector for selecting which plugin to use
 * @return the entry found or {@code null} if none was found
 */
@Nullable
public Map.Entry<PluginInfo, PluginClass> findPlugin(String template, final String pluginType,
        final String pluginName, PluginSelector selector) {
    // Transform by matching type, name. If there is no match, the map value is null.
    // We then filter out null value
    SortedMap<PluginInfo, PluginClass> plugins = ImmutableSortedMap.copyOf(Maps.filterValues(
            Maps.transformValues(getPlugins(template), new Function<Collection<PluginClass>, PluginClass>() {
                @Nullable
                @Override
                public PluginClass apply(Collection<PluginClass> input) {
                    for (PluginClass pluginClass : input) {
                        if (pluginClass.getType().equals(pluginType)
                                && pluginClass.getName().equals(pluginName)) {
                            return pluginClass;
                        }
                    }
                    return null;
                }
            }), Predicates.notNull()));

    return plugins.isEmpty() ? null : selector.select(plugins);
}

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

@EventHandler(priority = EventPriority.HIGH)
public void on(PlayerDeathEvent event) {
    if (!isEnabled())
        return;//  w  ww  .  j  a va2s . c  o  m

    Player player = event.getEntity();

    // make the player invisible for the duration of their death animation
    player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 18, 1));

    Location location = player.getLocation();

    // create an armour stand at the player
    ArmorStand stand = player.getWorld().spawn(location.clone().add(0, .2D, 0), ArmorStand.class);
    stand.setBasePlate(false);
    stand.setArms(true);

    // give the armour stand the death message as a name
    stand.setCustomName(STAND_PREFIX + event.getDeathMessage());
    stand.setCustomNameVisible(true);

    // face the same direction as the player
    stand.getLocation().setDirection(location.getDirection());

    // set the armour stand helmet to be looking at the same yaw
    stand.setHeadPose(new EulerAngle(Math.toRadians(location.getPitch()), 0, 0));

    // use the player's velocity as a base and apply it to the stand
    stand.setVelocity(player.getVelocity().clone().multiply(1.5D).add(new Vector(0D, .2D, 0D)));

    // start with player's existing items in each slot (if exists)
    Map<EquipmentSlot, ItemStack> toSet = getItems(player.getInventory());

    // overide with any saved items in the metadata
    toSet.putAll(getSavedSlots(player));

    // filter out the invalid items
    toSet = Maps.filterValues(toSet, Predicates.not(EMPTY_ITEM));

    List<ItemStack> drops = event.getDrops();

    for (Map.Entry<EquipmentSlot, ItemStack> entry : toSet.entrySet()) {
        ItemStack stack = entry.getValue();

        if (stack == null)
            continue;

        // remove the first matching stack in the drop list
        removeFirstEquals(drops, stack);

        // set the item on the armour stand in the correct slot
        switch (entry.getKey()) {
        case HAND:
            stand.setItemInHand(stack);
            break;
        case HEAD:
            stand.setHelmet(stack);
            break;
        case CHEST:
            stand.setChestplate(stack);
            break;
        case LEGS:
            stand.setLeggings(stack);
            break;
        case FEET:
            stand.setBoots(stack);
            break;
        }
    }
}

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

public static Map<String, IDoorMovement> listMovements() {
    return Maps.filterValues(movements, new Predicate<IDoorMovement>() {
        @Override//w  ww  .j  a  v a  2 s.  c  om
        public boolean apply(IDoorMovement input) {
            return !input.isSpecial();
        }
    });

}