本文整理匯總了Java中com.google.common.collect.Multisets類的典型用法代碼示例。如果您正苦於以下問題:Java Multisets類的具體用法?Java Multisets怎麽用?Java Multisets使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Multisets類屬於com.google.common.collect包,在下文中一共展示了Multisets類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: writeResult
import com.google.common.collect.Multisets; //導入依賴的package包/類
@Override
public void writeResult(final List<EALScorer2015Style.Result> perDocResults,
final File eventTypesDir) throws IOException {
final Multiset<Symbol> eventTypesSeen = gatherEventTypesSeen(perDocResults);
for (final Multiset.Entry<Symbol> typeEntry : Multisets.copyHighestCountFirst(eventTypesSeen)
.entrySet()) {
final Symbol type = typeEntry.getElement();
final Function<EALScorer2015Style.ArgResult, EALScorer2015Style.ArgResult>
filterFunction =
new Function<EALScorer2015Style.ArgResult, EALScorer2015Style.ArgResult>() {
@Override
public EALScorer2015Style.ArgResult apply(final
EALScorer2015Style.ArgResult input) {
return input.copyFiltered(compose(equalTo(type), type()));
}
};
final File eventTypeDir = new File(eventTypesDir, type.asString());
eventTypeDir.mkdirs();
writeOverallArgumentScoresForTransformedResults(perDocResults, filterFunction,
eventTypeDir);
}
}
示例2: testEntrySet_iteratorRemovePropagates
import com.google.common.collect.Multisets; //導入依賴的package包/類
@CollectionSize.Require(ONE)
@CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
public void testEntrySet_iteratorRemovePropagates() {
Iterator<Multiset.Entry<E>> iterator = getMultiset().entrySet().iterator();
assertTrue(
"non-empty multiset.entrySet() iterator.hasNext() returned false", iterator.hasNext());
assertEquals(
"multiset.entrySet() iterator.next() returned incorrect entry",
Multisets.immutableEntry(e0(), 1),
iterator.next());
assertFalse(
"size 1 multiset.entrySet() iterator.hasNext() returned true after next()",
iterator.hasNext());
iterator.remove();
assertTrue(
"multiset isn't empty after multiset.entrySet() iterator.remove()",
getMultiset().isEmpty());
}
示例3: setUp
import com.google.common.collect.Multisets; //導入依賴的package包/類
@Override
public void setUp() throws Exception {
super.setUp();
sortedMultiset = cast(getMultiset());
entries =
copyToList(
getSubjectGenerator()
.getSampleElements(getSubjectGenerator().getCollectionSize().getNumElements()));
Collections.sort(entries, sortedMultiset.comparator());
// some tests assume SEVERAL == 3
if (entries.size() >= 1) {
a = Multisets.immutableEntry(entries.get(0), sortedMultiset.count(entries.get(0)));
if (entries.size() >= 3) {
b = Multisets.immutableEntry(entries.get(1), sortedMultiset.count(entries.get(1)));
c = Multisets.immutableEntry(entries.get(2), sortedMultiset.count(entries.get(2)));
}
}
}
示例4: processPacket
import com.google.common.collect.Multisets; //導入依賴的package包/類
/**
* Passes this Packet on to the NetHandler for processing.
*/
@Override
public void processPacket(INetHandler inethandler)
{
this.netHandler = inethandler;
EmbeddedChannel internalChannel = NetworkRegistry.INSTANCE.getChannel(this.channel, this.target);
if (internalChannel != null)
{
internalChannel.attr(NetworkRegistry.NET_HANDLER).set(this.netHandler);
try
{
if (internalChannel.writeInbound(this))
{
badPackets.add(this.channel);
if (badPackets.size() % packetCountWarning == 0)
{
FMLLog.severe("Detected ongoing potential memory leak. %d packets have leaked. Top offenders", badPackets.size());
int i = 0;
for (Entry<String> s : Multisets.copyHighestCountFirst(badPackets).entrySet())
{
if (i++ > 10) break;
FMLLog.severe("\t %s : %d", s.getElement(), s.getCount());
}
}
}
internalChannel.inboundMessages().clear();
}
catch (FMLNetworkException ne)
{
FMLLog.log(Level.ERROR, ne, "There was a network exception handling a packet on channel %s", channel);
dispatcher.rejectHandshake(ne.getMessage());
}
catch (Throwable t)
{
FMLLog.log(Level.ERROR, t, "There was a critical exception handling a packet on channel %s", channel);
dispatcher.rejectHandshake("A fatal error has occurred, this connection is terminated");
}
}
}
示例5: identifyDuplicates
import com.google.common.collect.Multisets; //導入依賴的package包/類
private void identifyDuplicates(List<ModContainer> mods)
{
TreeMultimap<ModContainer, File> dupsearch = TreeMultimap.create(new ModIdComparator(), Ordering.arbitrary());
for (ModContainer mc : mods)
{
if (mc.getSource() != null)
{
dupsearch.put(mc, mc.getSource());
}
}
ImmutableMultiset<ModContainer> duplist = Multisets.copyHighestCountFirst(dupsearch.keys());
SetMultimap<ModContainer, File> dupes = LinkedHashMultimap.create();
for (Entry<ModContainer> e : duplist.entrySet())
{
if (e.getCount() > 1)
{
FMLLog.severe("Found a duplicate mod %s at %s", e.getElement().getModId(), dupsearch.get(e.getElement()));
dupes.putAll(e.getElement(),dupsearch.get(e.getElement()));
}
}
if (!dupes.isEmpty())
{
throw new DuplicateModsFoundException(dupes);
}
}
示例6: loadColors
import com.google.common.collect.Multisets; //導入依賴的package包/類
private void loadColors() {
if (myResourceResolver == null) {
myColorList = Collections.emptyList();
return;
}
int rows = myModel.getRowCount();
Multiset<Color> colorSet = HashMultiset.create();
for (int i = 0; i < rows; i++) {
if (myModel.getCellClass(i, 0) != Color.class) {
continue;
}
EditedStyleItem item = (EditedStyleItem)myModel.getValueAt(i, 0);
for (Color color : ResourceHelper.resolveMultipleColors(myResourceResolver, item.getItemResourceValue())) {
myColorReferences.put(color, item);
colorSet.add(color);
}
}
myColorList = ImmutableList.copyOf(Multisets.copyHighestCountFirst(colorSet).elementSet());
}
示例7: update
import com.google.common.collect.Multisets; //導入依賴的package包/類
private void update() {
ArrayList<UUID> onlinePlayers = new ArrayList<UUID>();
for (Object obj : FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerList()) {
EntityPlayerMP player = (EntityPlayerMP) obj;
UUID uuid = player.getUniqueID();
onlinePlayers.add(uuid);
timeOnCount.add(uuid);
//Kick players who are on too long
if ((maxTimeOn.containsKey(uuid) && timeOnCount.count(uuid) > maxTimeOn.get(uuid)) || (maxTimeOnGlobal != 0 && timeOnCount.count(uuid) > maxTimeOnGlobal)) {
rejoinTime.put(uuid, System.currentTimeMillis() + (breakTime.containsKey(uuid) ? breakTime.get(uuid) * 50 : breakTimeGlobal * 50));
kickPlayerForTime(player);
timeOnCount.remove(uuid, timeOnCount.count(uuid));
}
}
//Decrease timeOnCount time for players that aren't online
HashMultiset<UUID> uuids = HashMultiset.create();
for (UUID entry : timeOnCount.elementSet()) {
if (!onlinePlayers.contains(entry)) {
uuids.add(entry);
}
}
Multisets.removeOccurrences(timeOnCount, uuids);
}
示例8: testEntrySet_iteratorRemovePropagates
import com.google.common.collect.Multisets; //導入依賴的package包/類
@CollectionSize.Require(ONE)
@CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
public void testEntrySet_iteratorRemovePropagates() {
Iterator<Multiset.Entry<E>> iterator = getMultiset().entrySet().iterator();
assertTrue(
"non-empty multiset.entrySet() iterator.hasNext() returned false",
iterator.hasNext());
assertEquals("multiset.entrySet() iterator.next() returned incorrect entry",
Multisets.immutableEntry(e0(), 1), iterator.next());
assertFalse(
"size 1 multiset.entrySet() iterator.hasNext() returned true "
+ "after next()",
iterator.hasNext());
iterator.remove();
assertTrue(
"multiset isn't empty after multiset.entrySet() iterator.remove()",
getMultiset().isEmpty());
}
示例9: testKeysWithNullKey
import com.google.common.collect.Multisets; //導入依賴的package包/類
@CollectionSize.Require(SEVERAL)
@MapFeature.Require(ALLOWS_NULL_KEYS)
public void testKeysWithNullKey() {
resetContainer(
Helpers.mapEntry((K) null, v0()),
Helpers.mapEntry((K) null, v1()),
Helpers.mapEntry(k1(), v0()));
Multiset<K> keys = multimap().keys();
assertEquals(2, keys.count(null));
assertEquals(1, keys.count(k1()));
assertEquals(3, keys.size());
assertThat(keys).containsAllOf(null, k1());
assertThat(keys.entrySet()).containsAllOf(
Multisets.immutableEntry((K) null, 2),
Multisets.immutableEntry(k1(), 1));
}
示例10: setUp
import com.google.common.collect.Multisets; //導入依賴的package包/類
@Override
public void setUp() throws Exception {
super.setUp();
sortedMultiset = cast(getMultiset());
entries =
copyToList(getSubjectGenerator().getSampleElements(
getSubjectGenerator().getCollectionSize().getNumElements()));
Collections.sort(entries, sortedMultiset.comparator());
// some tests assume SEVERAL == 3
if (entries.size() >= 1) {
a = Multisets.immutableEntry(entries.get(0), sortedMultiset.count(entries.get(0)));
if (entries.size() >= 3) {
b = Multisets.immutableEntry(entries.get(1), sortedMultiset.count(entries.get(1)));
c = Multisets.immutableEntry(entries.get(2), sortedMultiset.count(entries.get(2)));
}
}
}
示例11: printTargetVectors
import com.google.common.collect.Multisets; //導入依賴的package包/類
/**
* Output to stdout the non-normalized vectors containing the
* cross-correlation between packages and patterns.
*/
public void printTargetVectors() {
final Multiset<String> packages = covariance.getElementCooccurence()
.getRowMultiset();
final List<String> topImports = getTopImports(packages);
printTopImports(packages, topImports);
final Set<Integer> topPatterns = getTopPatternsForImports(topImports);
// Just add top patterns because of their count. This should be general
// patterns
for (final int patternId : Multisets.copyHighestCountFirst(
covariance.getElementCooccurence().getColumnMultiset())
.elementSet()) {
if (topPatterns.size() > nTopPatterns) {
break;
}
topPatterns.add(patternId);
}
printTopPatterns(topPatterns);
printTopVectors(topImports, topPatterns);
}
示例12: reconnectToNearestProducer
import com.google.common.collect.Multisets; //導入依賴的package包/類
private void reconnectToNearestProducer(DisqueConnection<K, V> disqueConnection, boolean forcedReconnect) {
log.debug("reconnectToNearestProducer()");
Set<Multiset.Entry<String>> stats = Multisets.copyHighestCountFirst(nodePrefixes).entrySet();
nodePrefixes.clear();
if (!isNodeSwitchNecessary(stats) && !forcedReconnect) {
return;
}
String nodeIdPrefix = getNodeIdPrefix(stats);
if (nodeIdPrefix != null) {
log.debug("Set preferred node prefix to {}", nodeIdPrefix);
socketAddressSupplier.setPreferredNodeIdPrefix(nodeIdPrefix);
}
if (disqueConnection.isOpen()) {
if (nodeIdPrefix == null) {
log.info("Initiating reconnect");
} else {
log.info("Initiating reconnect to preferred node with prefix {}", nodeIdPrefix);
}
disconnect((RedisChannelHandler<?, ?>) disqueConnection);
}
}
示例13: getAlternativeNames
import com.google.common.collect.Multisets; //導入依賴的package包/類
/**
* @param relevantNgrams
* @param currentName
* @return
*/
public Multiset<String> getAlternativeNames(
final Multiset<NGram<String>> relevantNgrams,
final String currentName) {
// Get all alternative namings
final Multiset<String> nameAlternatives = ngramLM
.getAlternativeNamings(relevantNgrams, WILDCARD_TOKEN);
nameAlternatives.add(currentName); // Give the current identifier a
// chance...
// Prune naming alternatives
final Multiset<String> toKeep = TreeMultiset.create();
int seen = 0;
for (final Entry<String> ent : Multisets.copyHighestCountFirst(
nameAlternatives).entrySet()) {
if (seen > 1000) {
break;
}
toKeep.add(ent.getElement(), ent.getCount());
seen++;
}
toKeep.add(AbstractNGramLM.UNK_SYMBOL);
return toKeep;
}
示例14: findMinimalCoveringSet
import com.google.common.collect.Multisets; //導入依賴的package包/類
private List<Pattern> findMinimalCoveringSet(List<Pattern> sortedPatterns, List<String> types) {
List<Pattern> minimalSet = new LinkedList<Pattern>();
Multiset<String> sourceTypes = HashMultiset.create(types);
// Multiset<String> coveredTypes = HashMultiset.create();
for (Pattern p : sortedPatterns) {
Multiset<String> patternTypes = HashMultiset.create(p.getTypes());
Multiset<String> patternCommonTypes = Multisets.intersection(patternTypes, sourceTypes);
// if (Multisets.containsOccurrences(coveredTypes, patternCommonTypes)) // this pattern does not cover any new source type
if (patternCommonTypes.size() == 0) // this pattern does not cover any new source type
continue;
else {
minimalSet.add(p);
// coveredTypes.addAll(patternCommonTypes);
Multisets.removeOccurrences(sourceTypes, patternCommonTypes);
}
// if (Multisets.containsOccurrences(coveredTypes, sourceTypes))
if (sourceTypes.size() == 0)
break;
}
return minimalSet;
}
示例15: writeCatList
import com.google.common.collect.Multisets; //導入依賴的package包/類
private void writeCatList(Multiset<Category> cats, File outputFile) throws IOException {
Multiset<Category> catsNoPPorPRfeatures = HashMultiset.create();
for (Category cat : cats) {
catsNoPPorPRfeatures.add(cat.dropPPandPRfeatures());
}
FileWriter fw = new FileWriter(outputFile.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
int categories = 0;
for (Category type : Multisets.copyHighestCountFirst(cats).elementSet()) {
if (catsNoPPorPRfeatures.count(type.dropPPandPRfeatures()) >= 10) {
bw.write(type.toString());
bw.newLine();
categories++;
}
}
System.out.println("Number of cats occurring 10 times: " + categories);
bw.flush();
bw.close();
}