Example usage for com.google.common.collect Multimap isEmpty

List of usage examples for com.google.common.collect Multimap isEmpty

Introduction

In this page you can find the example usage for com.google.common.collect Multimap isEmpty.

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this multimap contains no key-value pairs.

Usage

From source file:org.javersion.json.web.VersionMetadata.java

public VersionMetadata(String _id, Set<Revision> _revs,
        Multimap<PropertyPath, VersionProperty<Object>> conflicts) {
    this._id = _id;
    this._revs = _revs.isEmpty() ? null : new ArrayList<>(_revs);
    this._conflicts = conflicts.isEmpty() ? null : conflicts.asMap();
}

From source file:matteroverdrive.items.android.RougeAndroidParts.java

@Override
public Multimap<String, AttributeModifier> getModifiers(AndroidPlayer player, ItemStack itemStack) {
    Multimap multimap = super.getModifiers(player, itemStack);
    if (multimap.isEmpty()) {
        multimap.put(SharedMonsterAttributes.maxHealth.getAttributeUnlocalizedName(), new AttributeModifier(
                UUID.fromString(healtModifiersIDs[itemStack.getItemDamage()]),
                MOStringHelper.translateToLocal(
                        "attribute.name." + SharedMonsterAttributes.maxHealth.getAttributeUnlocalizedName()),
                1f, 0));/*from   w  w  w  .j  a  v a  2s.com*/
    }
    return multimap;
}

From source file:org.apache.brooklyn.entity.group.zoneaware.BalancingNodePlacementStrategy.java

@Override
public List<Entity> entitiesToRemove(Multimap<Location, Entity> currentMembers, int numToRemove) {
    if (currentMembers.isEmpty()) {
        throw new IllegalArgumentException(
                "No members supplied, when requesting removal of " + numToRemove + " nodes");
    }/*from  w w w .j  a  v  a  2 s  .  c o m*/
    if (currentMembers.size() < numToRemove) {
        LOG.warn("Request to remove " + numToRemove + " when only " + currentMembers.size()
                + " members (continuing): " + currentMembers);
        numToRemove = currentMembers.size();
    }
    Map<Location, Integer> numToRemovePerLoc = Maps.newLinkedHashMap();
    Map<Location, Integer> locSizes = toMutableLocationSizes(currentMembers, ImmutableList.<Location>of());
    for (int i = 0; i < numToRemove; i++) {
        // TODO Inefficient to loop this many times! But not called with big numbers.
        Location mostPopulatedLoc = null;
        int mostPopulatedLocSize = 0;
        for (Location loc : locSizes.keySet()) {
            int locSize = locSizes.get(loc);
            if (locSize > 0 && (mostPopulatedLoc == null || locSize > mostPopulatedLocSize)) {
                mostPopulatedLoc = loc;
                mostPopulatedLocSize = locSize;
            }
        }
        assert mostPopulatedLoc != null : "leastPopulatedLoc=null; currentMembers=" + currentMembers;
        numToRemovePerLoc.put(mostPopulatedLoc, ((numToRemovePerLoc.get(mostPopulatedLoc) == null) ? 0
                : numToRemovePerLoc.get(mostPopulatedLoc)) + 1);
        locSizes.put(mostPopulatedLoc, locSizes.get(mostPopulatedLoc) - 1);
    }

    List<Entity> result = Lists.newArrayList();
    for (Map.Entry<Location, Integer> entry : numToRemovePerLoc.entrySet()) {
        result.addAll(pickNewest(currentMembers.get(entry.getKey()), entry.getValue()));
    }
    return result;
}

From source file:fr.ujm.tse.lt2c.satin.rules.run.RunRHODF7a.java

@Override
protected int process(final TripleStore ts1, final TripleStore ts2, final Collection<Triple> outputTriples) {

    final long subClassOf = AbstractDictionary.subClassOf;

    int loops = 0;

    final Multimap<Long, Long> subpropertyMultiMap = ts2.getMultiMapForPredicate(subClassOf);
    if (subpropertyMultiMap != null && !subpropertyMultiMap.isEmpty()) {
        for (final Entry<Long, Long> entry : subpropertyMultiMap.entries()) {
            loops++;/*from ww w . jav  a2 s . co m*/
            final Triple result1 = new ImmutableTriple(entry.getKey(), subClassOf, entry.getKey());
            final Triple result2 = new ImmutableTriple(entry.getValue(), subClassOf, entry.getValue());
            outputTriples.add(result1);
            outputTriples.add(result2);
        }
    }

    return loops;

}

From source file:fr.ujm.tse.lt2c.satin.rules.run.RunRHODF6b.java

@Override
protected int process(final TripleStore ts1, final TripleStore ts2, final Collection<Triple> outputTriples) {

    final long subPropertyOf = AbstractDictionary.subPropertyOf;

    int loops = 0;

    final Multimap<Long, Long> subpropertyMultimap = ts2.getMultiMapForPredicate(subPropertyOf);
    if (subpropertyMultimap != null && !subpropertyMultimap.isEmpty()) {
        for (final Entry<Long, Long> entry : subpropertyMultimap.entries()) {
            loops++;//from w w  w  . j a  va 2s .  c o  m
            final Triple result1 = new ImmutableTriple(entry.getKey(), subPropertyOf, entry.getKey());
            final Triple result2 = new ImmutableTriple(entry.getValue(), subPropertyOf, entry.getValue());
            outputTriples.add(result1);
            outputTriples.add(result2);
        }
    }

    return loops;

}

From source file:com.google.devtools.build.lib.analysis.config.ConfigurationResolver.java

/**
 * This method allows resolution of configurations outside of a skyfunction call.
 *
 * <p>If {@link BuildConfiguration.Options#trimConfigurations()} is true, transforms a collection
 * of <Target, Configuration> pairs by trimming each target's configuration to only the fragments
 * the target and its transitive dependencies need.
 *
 * <p>Else returns configurations that unconditionally include all fragments.
 *
 * <p>Preserves the original input order (but merges duplicate nodes that might occur due to
 * top-level configuration transitions) . Uses original (untrimmed) configurations for targets
 * that can't be evaluated (e.g. due to loading phase errors).
 *
 * <p>This is suitable for feeding {@link ConfiguredTargetValue} keys: as general principle {@link
 * ConfiguredTarget}s should have exactly as much information in their configurations as they need
 * to evaluate and no more (e.g. there's no need for Android settings in a C++ configured target).
 *
 * @param inputs the original targets and configurations
 * @param asDeps the inputs repackaged as dependencies
 * @param eventHandler/*from   w  ww. j  a  v a 2  s. co m*/
 * @param skyframeExecutor
 */
// TODO(bazel-team): error out early for targets that fail - untrimmed configurations should
// never make it through analysis (and especially not seed ConfiguredTargetValues)
public static LinkedHashSet<TargetAndConfiguration> getConfigurationsFromExecutor(
        Iterable<TargetAndConfiguration> inputs, Multimap<BuildConfiguration, Dependency> asDeps,
        ExtendedEventHandler eventHandler, SkyframeExecutor skyframeExecutor) throws InterruptedException {

    Map<Label, Target> labelsToTargets = new LinkedHashMap<>();
    for (TargetAndConfiguration targetAndConfig : inputs) {
        labelsToTargets.put(targetAndConfig.getLabel(), targetAndConfig.getTarget());
    }

    // Maps <target, originalConfig> pairs to <target, finalConfig> pairs for targets that
    // could be successfully Skyframe-evaluated.
    Map<TargetAndConfiguration, TargetAndConfiguration> successfullyEvaluatedTargets = new LinkedHashMap<>();
    if (!asDeps.isEmpty()) {
        for (BuildConfiguration fromConfig : asDeps.keySet()) {
            Multimap<Dependency, BuildConfiguration> trimmedTargets = skyframeExecutor
                    .getConfigurations(eventHandler, fromConfig.getOptions(), asDeps.get(fromConfig));
            for (Map.Entry<Dependency, BuildConfiguration> trimmedTarget : trimmedTargets.entries()) {
                Target target = labelsToTargets.get(trimmedTarget.getKey().getLabel());
                successfullyEvaluatedTargets.put(new TargetAndConfiguration(target, fromConfig),
                        new TargetAndConfiguration(target, trimmedTarget.getValue()));
            }
        }
    }

    LinkedHashSet<TargetAndConfiguration> result = new LinkedHashSet<>();
    for (TargetAndConfiguration originalInput : inputs) {
        if (successfullyEvaluatedTargets.containsKey(originalInput)) {
            // The configuration was successfully trimmed.
            result.add(successfullyEvaluatedTargets.get(originalInput));
        } else {
            // Either the configuration couldn't be determined (e.g. loading phase error) or it's null.
            result.add(originalInput);
        }
    }
    return result;
}

From source file:fr.ujm.tse.lt2c.satin.rules.run.RunPRP_RNG.java

@Override
protected int process(final TripleStore ts1, final TripleStore ts2, final Collection<Triple> outputTriples) {

    final long range = AbstractDictionary.range;
    final long type = AbstractDictionary.type;

    final int loops = 0;

    final Multimap<Long, Long> rangeMultiMap = ts1.getMultiMapForPredicate(range);
    if (rangeMultiMap != null && !rangeMultiMap.isEmpty()) {

        final HashMap<Long, Collection<Triple>> cachePredicates = new HashMap<>();

        for (final Long p : rangeMultiMap.keySet()) {

            Collection<Triple> matchingTriples;
            if (!cachePredicates.containsKey(p)) {
                matchingTriples = ts2.getbyPredicate(p);
                cachePredicates.put(p, matchingTriples);
            } else {
                matchingTriples = cachePredicates.get(p);
            }//  w  w  w  .  j a v  a2s  .  c  om

            for (final Triple triple : matchingTriples) {

                for (final Long c : rangeMultiMap.get(p)) {

                    if (triple.getObject() >= 0) {
                        final Triple result = new ImmutableTriple(triple.getObject(), type, c);
                        outputTriples.add(result);
                    }
                }
            }
        }
    }

    return loops;

}

From source file:org.apache.sentry.core.common.utils.PolicyFile.java

private String getSection(String name, Multimap<String, String> mapping) {
    if (mapping.isEmpty()) {
        return "";
    }/*w w w. j  av a2  s.c  o  m*/
    Joiner kvJoiner = Joiner.on(" = ");
    Joiner itemJoiner = Joiner.on(" , ");
    List<String> lines = Lists.newArrayList();
    lines.add("[" + name + "]");
    for (String key : mapping.keySet()) {
        lines.add(kvJoiner.join(key, itemJoiner.join(mapping.get(key))));
    }
    return Joiner.on(NL).join(lines);
}

From source file:fr.ujm.tse.lt2c.satin.rules.run.RunPRP_DOM.java

@Override
protected int process(final TripleStore ts1, final TripleStore ts2, final Collection<Triple> outputTriples) {

    final long domain = AbstractDictionary.domain;
    final long type = AbstractDictionary.type;

    final int loops = 0;

    final Multimap<Long, Long> domainMultiMap = ts1.getMultiMapForPredicate(domain);
    if (domainMultiMap != null && !domainMultiMap.isEmpty()) {

        final HashMap<Long, Collection<Triple>> cachePredicates = new HashMap<>();

        for (final Long p : domainMultiMap.keySet()) {

            Collection<Triple> matchingTriples;
            if (!cachePredicates.containsKey(p)) {
                matchingTriples = ts2.getbyPredicate(p);
                cachePredicates.put(p, matchingTriples);
            } else {
                matchingTriples = cachePredicates.get(p);
            }/*from   w  ww. j  av  a2 s .  c  om*/

            for (final Triple triple : matchingTriples) {

                for (final Long c : domainMultiMap.get(p)) {

                    if (triple.getSubject() >= 0) {
                        final Triple result = new ImmutableTriple(triple.getSubject(), type, c);
                        outputTriples.add(result);
                    }
                }
            }
        }
    }

    return loops;

}

From source file:de.metas.ui.web.order.sales.purchasePlanning.process.WEBUI_SalesOrder_Apply_Availability_Row.java

@Override
public final ProcessPreconditionsResolution checkPreconditionsApplicable() {
    final Multimap<PurchaseRow, PurchaseRow> lineRows2availabilityRows = //
            extractLineRow2availabilityRows();
    if (lineRows2availabilityRows.isEmpty()) {
        return ProcessPreconditionsResolution.reject();
    }//from w w  w  . ja  v a2s . co m

    if (hasMultipleAvailabilityRowsPerLineRow(lineRows2availabilityRows)) {
        return ProcessPreconditionsResolution.reject();
    }

    return ProcessPreconditionsResolution.accept();
}