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

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

Introduction

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

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this collection contains no elements.

Usage

From source file:org.caleydo.view.domino.internal.toolbar.NodeTools.java

/**
 * @param actives/*from w w w.j a va2 s . c o m*/
 * @return
 */
private static <T> T mostFrequent(Multiset<T> sets) {
    if (sets.isEmpty())
        return null;
    Set<T> elems = sets.elementSet();
    T maxV = elems.iterator().next();
    int max = sets.count(maxV);
    for (T elem : elems) {
        int c = sets.count(elem);
        if (c > max) {
            max = c;
            maxV = elem;
        }
    }
    return maxV;
}

From source file:org.apache.aurora.scheduler.async.preemptor.PendingTaskProcessor.java

/**
 * Creates execution sequence for pending task groups by interleaving their unique occurrences.
 * For example: {G1, G1, G1, G2, G2} will be converted into {G1, G2, G1, G2, G1}.
 *
 * @param groups Multiset of task groups.
 * @return A task group execution sequence.
 *///from w  ww.  j ava2  s.  co  m
private static List<TaskGroupKey> getPreemptionSequence(Multiset<TaskGroupKey> groups) {
    Multiset<TaskGroupKey> mutableGroups = HashMultiset.create(groups);
    List<TaskGroupKey> instructions = Lists.newLinkedList();
    Set<TaskGroupKey> keys = ImmutableSet.copyOf(groups.elementSet());
    while (!mutableGroups.isEmpty()) {
        for (TaskGroupKey key : keys) {
            if (mutableGroups.contains(key)) {
                instructions.add(key);
                mutableGroups.remove(key);
            }
        }
    }

    return instructions;
}

From source file:org.apache.aurora.scheduler.preemptor.PendingTaskProcessor.java

/**
 * Creates execution sequence for pending task groups by interleaving batches of requested size of
 * their occurrences. For example: {G1, G1, G1, G2, G2} with batch size of 2 task per group will
 * be converted into {G1, G1, G2, G2, G1}.
 *
 * @param groups Multiset of task groups.
 * @param batchSize The batch size of tasks from each group to sequence together.
 * @return A task group execution sequence.
 *///from   w w w .  ja  v  a2 s  .c om
@VisibleForTesting
static List<TaskGroupKey> getPreemptionSequence(Multiset<TaskGroupKey> groups, int batchSize) {

    Preconditions.checkArgument(batchSize > 0, "batchSize should be positive.");

    Multiset<TaskGroupKey> mutableGroups = HashMultiset.create(groups);
    List<TaskGroupKey> instructions = Lists.newLinkedList();
    Set<TaskGroupKey> keys = ImmutableSet.copyOf(groups.elementSet());
    while (!mutableGroups.isEmpty()) {
        for (TaskGroupKey key : keys) {
            if (mutableGroups.contains(key)) {
                int elementCount = mutableGroups.remove(key, batchSize);
                int removedCount = Math.min(elementCount, batchSize);
                instructions.addAll(Collections.nCopies(removedCount, key));
            }
        }
    }

    return instructions;
}

From source file:org.apache.sqoop.test.asserts.HdfsAsserts.java

/**
 * Verify that mapreduce output (across all files) is as expected.
 *
 * @param directory Mapreduce output directory
 * @param lines Expected lines//ww  w. j  a  v a2  s. com
 * @throws IOException
 */
public static void assertMapreduceOutput(FileSystem fs, String directory, String... lines) throws IOException {
    Multiset<String> setLines = HashMultiset.create(Arrays.asList(lines));
    List<String> notFound = new LinkedList<String>();

    Path[] files = HdfsUtils.getOutputMapreduceFiles(fs, directory);
    for (Path file : files) {
        BufferedReader br = new BufferedReader(new InputStreamReader(fs.open(file)));

        String line;
        while ((line = br.readLine()) != null) {
            if (!setLines.remove(line)) {
                notFound.add(line);
            }
        }
        br.close();
    }

    if (!setLines.isEmpty() || !notFound.isEmpty()) {
        LOG.error("Output do not match expectations.");
        LOG.error("Expected lines that weren't present in the files:");
        LOG.error("\t'" + StringUtils.join(setLines, "'\n\t'") + "'");
        LOG.error("Extra lines in files that weren't expected:");
        LOG.error("\t'" + StringUtils.join(notFound, "'\n\t'") + "'");
        fail("Output do not match expectations.");
    }
}

From source file:org.simmetrics.metrics.GeneralizedOverlapCoefficient.java

@Override
public float compare(Multiset<T> a, Multiset<T> b) {

    if (a.isEmpty() && b.isEmpty()) {
        return 1.0f;
    }//  w ww. j a  v  a  2 s  . co m

    if (a.isEmpty() || b.isEmpty()) {
        return 0.0f;
    }

    // q  r / min{q, r}
    return intersection(a, b).size() / (float) min(a.size(), b.size());
}

From source file:org.simmetrics.metrics.EuclideanDistance.java

@Override
public float compare(Multiset<T> a, Multiset<T> b) {

    if (a.isEmpty() && b.isEmpty()) {
        return 1.0f;
    }// w  w  w . j a va 2 s  .  c  om

    float maxDistance = (float) sqrt((a.size() * a.size()) + (b.size() * b.size()));
    return 1.0f - distance(a, b) / maxDistance;
}

From source file:org.simmetrics.metrics.BlockDistance.java

@Override
public float compare(Multiset<T> a, Multiset<T> b) {

    if (a.isEmpty() && b.isEmpty()) {
        return 1.0f;
    }/* w  ww . j  ava2s . c  o  m*/

    if (a.isEmpty() || b.isEmpty()) {
        return 0.0f;
    }

    return 1.0f - distance(a, b) / (a.size() + b.size());
}

From source file:org.simmetrics.metrics.GeneralizedJaccard.java

@Override
public float compare(Multiset<T> a, Multiset<T> b) {

    if (a.isEmpty() && b.isEmpty()) {
        return 1.0f;
    }/* w w w.j a  v  a2  s  . co m*/

    if (a.isEmpty() || b.isEmpty()) {
        return 0.0f;
    }

    final int intersection = intersection(a, b).size();

    // a  b / a  b
    // Implementation note: The size of the union of two sets is equal to
    // the size of both sets minus the duplicate elements.
    return intersection / (float) (a.size() + b.size() - intersection);
}

From source file:org.simmetrics.metrics.CosineSimilarity.java

@Override
public float compare(Multiset<T> a, Multiset<T> b) {

    if (a.isEmpty() && b.isEmpty()) {
        return 1.0f;
    }/*w  w w .  j a  v a 2 s.co  m*/

    if (a.isEmpty() || b.isEmpty()) {
        return 0.0f;
    }

    float dotProduct = 0;
    float magnitudeA = 0;
    float magnitudeB = 0;

    for (T entry : union(a, b).elementSet()) {
        float aCount = a.count(entry);
        float bCount = b.count(entry);

        dotProduct += aCount * bCount;
        magnitudeA += aCount * aCount;
        magnitudeB += bCount * bCount;
    }

    //  ab / (||a|| * ||b||)
    return (float) (dotProduct / (sqrt(magnitudeA) * sqrt(magnitudeB)));
}

From source file:com.b2international.snowowl.snomed.reasoner.server.diff.DefaultNamespaceAndModuleAssigner.java

@Override
public void allocateRelationshipIdsAndModules(Multiset<String> conceptIds,
        final SnomedEditingContext editingContext) {
    if (conceptIds.isEmpty())
        return;// ww  w .j ava  2 s  . c  o  m

    ISnomedIdentifierService identifierService = getServiceForClass(ISnomedIdentifierService.class);
    String defaultNamespace = editingContext.getDefaultNamespace();
    reservedIds = identifierService.reserve(defaultNamespace, ComponentCategory.RELATIONSHIP,
            conceptIds.size());
    relationshipIds = reservedIds.iterator();
    defaultRelationshipModuleConcept = editingContext.getDefaultModuleConcept();
}