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

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

Introduction

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

Prototype

@Override
boolean remove(@Nullable Object element);

Source Link

Document

Removes a single occurrence of the specified element from this multiset, if present.

Usage

From source file:org.javafunk.funk.Multisets.java

public static <T> Multiset<T> difference(Iterable<? extends Iterable<? extends T>> iterables) {
    Multiset<T> differences = multisetFrom(first(iterables).get());
    for (Iterable<? extends T> iterable : rest(iterables)) {
        for (T item : iterable) {
            differences.remove(item);
        }//from w w  w  . ja  v a2  s . co m
    }
    return differences;
}

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//from w  w w.  j ava2 s.co m
 * @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.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 ww  w.  jav a 2  s.c  o 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.simmetrics.metrics.MatchingCoefficient.java

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

    if (a.isEmpty() && b.isEmpty()) {
        return 1.0f;
    }/*from  www .jav a2s.  c o m*/

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

    // Count elements in the list intersection.
    // Elements are counted only once in both lists.
    // E.g. the intersection of [ab,ab,ab] and [ab,ab,ac,ad] is [ab,ab].
    // Note: this is not the same as b.retainAll(a).size()
    int intersection = 0;
    // Copy for destructive list difference
    Multiset<T> bCopy = create(b);
    for (T token : a) {
        if (bCopy.remove(token)) {
            intersection++;
        }
    }
    // Implementation note: The size of the union of two sets is equal to
    // the size of both lists minus the duplicate elements.
    return intersection / (float) (a.size() + b.size() - intersection);
}

From source file:org.javafunk.matchbox.implementations.HasOnlyItemsInAnyOrderMatcher.java

private boolean checkForDifferences(Multiset<E> expectedSet, Multiset<E> actualSet, Description description,
        String message) {//from w  w  w.  j av a  2s  .  c om
    Multiset<E> differences = HashMultiset.create(expectedSet);
    for (E item : actualSet) {
        differences.remove(item);
    }
    if (differences.size() > 0) {
        description.appendText("\n").appendText(message).appendValueList("", ", ", "", differences);
        return true;
    }
    return false;
}

From source file:additionalpipes.chunk.ChunkManager.java

public void sendPersistentChunks(EntityPlayerMP player) {
    Multiset<ChunkCoordIntPair> oldSet = players.get(player);
    boolean showAllPersistentChunks = oldSet.remove(null);
    Multiset<ChunkCoordIntPair> newSet = HashMultiset.create();

    WorldServer world = (WorldServer) player.worldObj;
    for (Map.Entry<ChunkCoordIntPair, Ticket> e : ForgeChunkManager.getPersistentChunksFor(world).entries()) {
        if (!showAllPersistentChunks && !APDefaultProps.ID.equals(e.getValue().getModId())) {
            continue;
        }/*from   w ww .  j ava  2  s.  c  om*/

        if (world.getPlayerManager().isPlayerWatchingChunk(player, e.getKey().chunkXPos,
                e.getKey().chunkZPos)) {
            newSet.add(e.getKey());
        }
    }

    if (!oldSet.equals(newSet)) {
        PacketChunkCoordList packet = new PacketChunkCoordList(APPacketIds.UPDATE_LASERS, newSet);
        CoreProxy.proxy.sendToPlayer(player, packet);
        if (showAllPersistentChunks) {
            newSet.add(null);
        }
        players.put(player, newSet);
    }
}

From source file:com.google.inject.internal.WeakKeySet.java

/**
 * There may be multiple child injectors blacklisting a certain key so only remove the source
 * that's relevant.//from w ww.  j  a v  a  2  s.  c  o m
 */
private void cleanUpForCollectedState(Set<KeyAndSource> keysAndSources) {
    synchronized (lock) {
        for (KeyAndSource keyAndSource : keysAndSources) {
            Multiset<Object> set = backingMap.get(keyAndSource.blacklistKey);
            if (set != null) {
                set.remove(keyAndSource.source);
                if (set.isEmpty()) {
                    backingMap.remove(keyAndSource.blacklistKey);
                }
            }
        }
    }
}

From source file:gr.forth.ics.swkm.model2.util.NamespaceDependenciesIndex.java

private void removeDependency(Uri uri1, Uri uri2, Direction direction) {
    Map<Uri, Multiset<Uri>> deps = deps(direction);
    Multiset<Uri> depsOfNamespace = depsPerNamespace(deps, uri1);
    depsOfNamespace.remove(uri2);

    if (depsOfNamespace.isEmpty()) {
        deps.remove(uri1);//from w w w.  j  a v a 2s  .c  om
    }
}

From source file:com.sonarsource.lits.IssuesChecker.java

@Override
public boolean accept(FilterableIssue issue, IssueFilterChain chain) {
    if (disabled) {
        return true;
    }//from  w  ww .ja va 2 s  . c  o m

    IssueKey issueKey = new IssueKey(issue.componentKey(), issue.ruleKey().toString(), issue.line());
    dump.add(issueKey);
    Multiset<IssueKey> componentIssues = getByComponentKey(issueKey.componentKey);
    if (componentIssues.contains(issueKey)) {
        // old issue => no need to persist
        componentIssues.remove(issueKey);
        Preconditions.checkState(Severity.INFO.equals(issue.severity()));
        return false;
    } else {
        // new issue => persist
        different = true;
        differences++;
        return true;
    }
}

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

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

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

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

    // Copy for destructive list difference
    Multiset<T> bCopy = HashMultiset.create(b);

    // Count elements in the list intersection.
    // Elements are counted only once in both lists.
    // E.g. the intersection of [ab,ab,ab] and [ab,ab,ac,ad] is [ab,ab].
    // Note: this is not the same as b.retainAll(a).size()
    int intersection = 0;
    for (T token : a) {
        if (bCopy.remove(token)) {
            intersection++;
        }
    }

    return 2.0f * intersection / (a.size() + b.size());

}