Example usage for com.google.common.collect Multiset entrySet

List of usage examples for com.google.common.collect Multiset entrySet

Introduction

In this page you can find the example usage for com.google.common.collect Multiset entrySet.

Prototype

Set<Entry<E>> entrySet();

Source Link

Document

Returns a view of the contents of this multiset, grouped into Multiset.Entry instances, each providing an element of the multiset and the count of that element.

Usage

From source file:additionalpipes.proxy.ClientProxy.java

@Override
public void showLasers(Multiset<ChunkCoordIntPair> coordSet) {
    World world = Minecraft.getMinecraft().theWorld;
    if (world == null) {
        return;//from  www . ja  va2 s .c  om
    }
    hideLasers();

    for (Multiset.Entry<ChunkCoordIntPair> e : coordSet.entrySet()) {
        int chunkX = e.getElement().chunkXPos << 4;
        int chunkZ = e.getElement().chunkZPos << 4;

        BoxEx outsideLaser = new BoxEx();
        outsideLaser.initialize(chunkX, playerY, chunkZ, 16, true);
        outsideLaser.createLasers(world, e.getCount() == 1 ? LaserKind.Blue : LaserKind.Stripes);
        lasers.add(outsideLaser);

        BoxEx insideLaser = new BoxEx();
        insideLaser.initialize(chunkX + 7, playerY, chunkZ + 7, 2, false);
        insideLaser.createLasers(world, LaserKind.Red);
        lasers.add(insideLaser);
    }
}

From source file:com.davidsoergel.stats.Multinomial.java

public Multinomial(Multiset<T> counts) throws DistributionException {
    this();/*from   w w w  .j a va 2 s . co  m*/
    for (Multiset.Entry<T> k : counts.entrySet()) {
        put((T) k.getElement(), k.getCount());
    }
    normalize();
}

From source file:com.sun.tools.hat.internal.server.RefsByTypeQuery.java

private void print(Multiset<JavaClass> multiset, JavaClass primary, Collection<JavaClass> referrers,
        boolean supportsChaining) {
    out.println("<table border='1' align='center'>");
    out.println("<tr><th>Class</th><th>Count</th></tr>");
    multiset.entrySet().stream().sorted(Ordering.natural().reverse().onResultOf(entry -> entry.getCount()))
            .forEach(entry -> {/* ww w .j a  v a 2 s . c  o  m*/
                out.println("<tr><td>");
                JavaClass clazz = entry.getElement();
                printClass(clazz);
                if (supportsChaining) {
                    out.printf(" (%s, %s)", formatLink("top", clazz, null, null),
                            formatLink("chain", primary, referrers, clazz));
                } else {
                    out.printf(" (%s)", formatLink("refs", clazz, null, null));
                }
                out.println("</td><td>");
                out.println(entry.getCount());
                out.println("</td></tr>");
            });
    out.println("</table>");
}

From source file:com.continuuity.loom.layout.ClusterLayout.java

public ClusterLayout(Constraints constraints, Multiset<NodeLayout> layout) {
    this.constraints = constraints;
    this.layout = ImmutableMultiset.copyOf(layout);
    this.serviceCounts = HashMultiset.create();
    for (Multiset.Entry<NodeLayout> entry : layout.entrySet()) {
        for (String service : entry.getElement().getServiceNames()) {
            serviceCounts.add(service, entry.getCount());
        }//from   w  ww  . ja va 2  s  .  c  o  m
    }
}

From source file:bio.gcat.operation.analysis.AminoAcids.java

@Override
public Result analyse(Collection<Tuple> tuples, Object... values) {
    Multiset<Compound> compounds = EnumMultiset.create(Compound.class);
    for (Tuple tuple : tuples)
        compounds.add(Compound.isStop(tuple) ? Compound.STOP
                : Optional.ofNullable(tuple.getCompound()).orElse(Compound.UNKNOWN));

    StringBuilder builder = new StringBuilder();
    for (Entry<Compound> compound : compounds.entrySet())
        builder.append(DELIMITER).append(compound.getCount()).append(TIMES).append(compound.getElement());

    return new SimpleResult(this, builder.substring(DELIMITER.length()).toString());
}

From source file:nextmethod.web.razor.parser.syntaxtree.Span.java

private String[] getSymbolGroupCounts() {
    final Multiset<Class<?>> counts = HashMultiset.create();
    counts.addAll(symbols.stream().map(ISymbol::getClass).collect(Collectors.toList()));
    final String[] ret = new String[counts.size()];
    int i = 0;//from  w  w w . j a v  a  2 s .c  o  m
    for (Multiset.Entry<Class<?>> entry : counts.entrySet()) {
        ret[i++] = String.format("%s:%d", entry.getElement().getSimpleName(), entry.getCount());
    }

    return ret;
}

From source file:com.google.devtools.build.lib.rules.objc.AppleWatch2Extension.java

private void validateAttributesAndConfiguration(RuleContext ruleContext) throws RuleErrorException {
    boolean hasError = false;

    Multiset<Artifact> appResources = HashMultiset.create();
    appResources.addAll(ruleContext.getPrerequisiteArtifacts("app_resources", Mode.TARGET).list());
    appResources.addAll(ruleContext.getPrerequisiteArtifacts("app_strings", Mode.TARGET).list());

    for (Multiset.Entry<Artifact> entry : appResources.entrySet()) {
        if (entry.getCount() > 1) {
            ruleContext.ruleError("The same file was included multiple times in this rule: "
                    + entry.getElement().getRootRelativePathString());
            hasError = true;/* w  ww .  j  a v a 2s .c o  m*/
        }
    }

    Multiset<Artifact> extResources = HashMultiset.create();
    extResources.addAll(ruleContext.getPrerequisiteArtifacts("ext_resources", Mode.TARGET).list());
    extResources.addAll(ruleContext.getPrerequisiteArtifacts("ext_strings", Mode.TARGET).list());

    for (Multiset.Entry<Artifact> entry : extResources.entrySet()) {
        if (entry.getCount() > 1) {
            ruleContext.ruleError("The same file was included multiple times in this rule: "
                    + entry.getElement().getRootRelativePathString());
            hasError = true;
        }
    }

    AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class);
    Platform watchPlatform = appleConfiguration.getMultiArchPlatform(PlatformType.WATCHOS);
    Platform iosPlatform = appleConfiguration.getMultiArchPlatform(PlatformType.IOS);
    if (watchPlatform.isDevice() != iosPlatform.isDevice()) {
        hasError = true;
        if (watchPlatform.isDevice()) {
            ruleContext.ruleError(String.format(
                    "Building a watch extension for watch device architectures [%s] "
                            + "requires a device ios architecture. Found [%s] instead.",
                    Joiner.on(",").join(appleConfiguration.getMultiArchitectures(PlatformType.WATCHOS)),
                    Joiner.on(",").join(appleConfiguration.getMultiArchitectures(PlatformType.IOS))));
        } else {
            ruleContext.ruleError(String.format(
                    "Building a watch extension for ios device architectures [%s] "
                            + "requires a device watch architecture. Found [%s] instead.",
                    Joiner.on(",").join(appleConfiguration.getMultiArchitectures(PlatformType.IOS)),
                    Joiner.on(",").join(appleConfiguration.getMultiArchitectures(PlatformType.WATCHOS))));
        }
        ruleContext.ruleError("For building watch extension, there may only be a watch device "
                + "architecture if and only if there is an ios device architecture");
    }

    if (hasError) {
        throw new RuleErrorException();
    }
}

From source file:org.onosproject.layout.AccessNetworkLayout.java

@Override
protected boolean classify(Device device) {
    if (!super.classify(device)) {
        String role;//from   w  ww. j a  v a2 s.  c o m

        // Does the device have any hosts attached? If not, it's a spine
        if (hostService.getConnectedHosts(device.id()).isEmpty()) {
            // Does the device have any aggregate links to other devices?
            Multiset<DeviceId> destinations = HashMultiset.create();
            linkService.getDeviceEgressLinks(device.id()).stream().map(l -> l.dst().deviceId())
                    .forEach(destinations::add);

            // If yes, it's the main spine; otherwise it's an aggregate spine
            role = destinations.entrySet().stream().anyMatch(e -> e.getCount() > 1) ? SPINE : AGGREGATION;
        } else {
            // Does the device have any multi-home hosts attached?
            // If yes, it's a service leaf; otherwise it's an access leaf
            role = hostService.getConnectedHosts(device.id()).stream().map(Host::locations)
                    .anyMatch(s -> s.size() > 1) ? LEAF : ACCESS;
        }
        deviceCategories.put(role, device.id());
    }
    return true;
}

From source file:com.b2international.index.mapping.Mappings.java

public Mappings(Collection<Class<?>> types) {
    checkArgument(!types.isEmpty(), "At least one document type should be specified");
    final Multiset<String> duplicates = HashMultiset.create();
    for (Class<?> type : ImmutableSet.copyOf(types)) {
        // XXX register only root mappings, nested mappings should be looked up via the parent/ancestor mapping
        DocumentMapping mapping = new DocumentMapping(type);
        mappingsByType.put(type, mapping);
        duplicates.add(mapping.typeAsString());
    }//from  ww w. java 2 s  .  c o  m
    for (Entry<String> duplicate : duplicates.entrySet()) {
        if (duplicate.getCount() > 1) {
            throw new IllegalArgumentException(
                    "Multiple Java types with the same document name: " + duplicate.getElement());
        }
    }
}

From source file:org.carrot2.text.clustering.MultilingualClustering.java

private List<Cluster> clusterInMajorityLanguage(List<Document> documents,
        IMonolingualClusteringAlgorithm algorithm) {
    final Multiset<LanguageCode> counts = HashMultiset.create();
    for (Document d : documents) {
        counts.add(d.getLanguage());/*from   ww  w.  j  a  va2 s .  c  om*/
    }
    LanguageCode majorityLanguage = defaultLanguage;
    int maxCount = 0;
    for (Entry<LanguageCode> entry : counts.entrySet()) {
        if (entry.getElement() != null) {
            if (entry.getCount() > maxCount) {
                maxCount = entry.getCount();
                majorityLanguage = entry.getElement();
                this.majorityLanguage = entry.getElement().getIsoCode();
            }
        }
        languageCounts.put(entry.getElement() != null ? entry.getElement().getIsoCode() : "", entry.getCount());
    }

    logger.debug("Performing clustering in majority language: " + majorityLanguage);
    final List<Cluster> clusters = algorithm.process(documents, majorityLanguage);
    Cluster.appendOtherTopics(documents, clusters);
    return clusters;
}