本文整理匯總了Java中com.google.common.collect.Multiset.add方法的典型用法代碼示例。如果您正苦於以下問題:Java Multiset.add方法的具體用法?Java Multiset.add怎麽用?Java Multiset.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.collect.Multiset
的用法示例。
在下文中一共展示了Multiset.add方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: checkAttributeNamesForDuplicates
import com.google.common.collect.Multiset; //導入方法依賴的package包/類
private void checkAttributeNamesForDuplicates(ValueType type, Protoclass protoclass) {
if (!type.attributes.isEmpty()) {
Multiset<String> attributeNames = HashMultiset.create(type.attributes.size());
for (ValueAttribute attribute : type.attributes) {
attributeNames.add(attribute.name());
}
List<String> duplicates = Lists.newArrayList();
for (Multiset.Entry<String> entry : attributeNames.entrySet()) {
if (entry.getCount() > 1) {
duplicates.add(entry.getElement());
}
}
if (!duplicates.isEmpty()) {
protoclass.report()
.error("Duplicate attribute names %s. You should check if correct @Value.Style applied",
duplicates);
}
}
}
示例2: getSiaSeed
import com.google.common.collect.Multiset; //導入方法依賴的package包/類
@Test
public void getSiaSeed() throws Exception {
final SiaSeedService siaSeedService = new SiaSeedService(new StaticEncyptionKeyProvider("123"));
// final List<String> strings = siaSeedService.buildSiaSeed("123");
final Multiset<Long> counts;
counts = HashMultiset.create();
for (int i = 0; i < 100000; i++) {
final String secretKey = "abc123782567825784__" + i;
final List<String> words = siaSeedService.buildSiaSeed(secretKey);
final String wordsList = Joiner.on(" ").join(words);
final String errrorMessage = "secret produced unexpected length: " + secretKey + " words: " + wordsList;
counts.add((long) words.size());
// Assert.assertEquals(errrorMessage, 29, words.size());
}
counts.forEachEntry((length, count) -> System.out.println(length + " occurred " + count + " times"));
}
示例3: intRange
import com.google.common.collect.Multiset; //導入方法依賴的package包/類
@Test
public void intRange() throws Exception {
Entropy e = new MutableEntropy(SEED);
Range<Integer> range = Range.closedOpen(-5, 5);
Multiset<Integer> distribution = HashMultiset.create();
// Choose 1k values and check that they are in the range
for(int i = 0; i < 10000; i++) {
final int value = e.randomInt(range);
assertContains(range, value);
distribution.add(value);
e.advance();
}
// Assert that each of the 10 values was chosen ~1000 times
Ranges.forEach(range, value -> {
assertEquals(1000D, distribution.count(value), 50D);
});
}
示例4: expressionsAreParallel
import com.google.common.collect.Multiset; //導入方法依賴的package包/類
/**
* Returns true if {@code atLeastM} of the expressions in the given column are the same kind.
*/
private static boolean expressionsAreParallel(
List<List<ExpressionTree>> rows, int column, int atLeastM) {
Multiset<Tree.Kind> nodeTypes = HashMultiset.create();
for (List<? extends ExpressionTree> row : rows) {
if (column >= row.size()) {
continue;
}
nodeTypes.add(row.get(column).getKind());
}
for (Multiset.Entry<Tree.Kind> nodeType : nodeTypes.entrySet()) {
if (nodeType.getCount() >= atLeastM) {
return true;
}
}
return false;
}
示例5: tokenizeToMultiset
import com.google.common.collect.Multiset; //導入方法依賴的package包/類
@Override
public Multiset<String> tokenizeToMultiset(String input) {
// tokenizeToList is not reused here on purpose. Removing duplicate
// words early means these don't have to be tokenized multiple
// times. Increases performance.
Multiset<String> tokens = HashMultiset.create(input.length());
tokens.add(input);
Multiset<String> newTokens = HashMultiset.create(input.length());
for (Tokenizer t : tokenizers) {
for (String token : tokens) {
newTokens.addAll(t.tokenizeToList(token));
}
Multiset<String> swap = tokens;
tokens = newTokens;
newTokens = swap;
newTokens.clear();
}
return tokens;
}
示例6: gen_subgraph
import com.google.common.collect.Multiset; //導入方法依賴的package包/類
/**
* Generate a subgraph of size k starting at node_id using bfs
*/
public Multiset<Integer> gen_subgraph(int k, boolean bfs) {
Multiset<Integer> result = HashMultiset.create();
CFGFeature.logger.debug("Generating subgraphs using BFS with k = {} ...", k);
if(this.nodes.size() == 0) {
CFGFeature.logger.debug("Empty body.");
return result;
}
for (CFGNode node : this.nodes) {
// System.out.println(node.node.toString());
int code = this.gen_subgraph_helper(node, k, bfs);
// System.out.println("code : " + code + "\n\n");
result.add(code);
}
CFGFeature.logger.debug("Done generating CFG feature.");
return result;
}
示例7: add
import com.google.common.collect.Multiset; //導入方法依賴的package包/類
public void add(Key<?> key, State state, Object source) {
if (backingMap == null) {
backingMap = Maps.newHashMap();
}
// if it's an instanceof Class, it was a JIT binding, which we don't
// want to retain.
if (source instanceof Class || source == SourceProvider.UNKNOWN_SOURCE) {
source = null;
}
Multiset<Object> sources = backingMap.get(key);
if (sources == null) {
sources = LinkedHashMultiset.create();
backingMap.put(key, sources);
}
Object convertedSource = Errors.convert(source);
sources.add(convertedSource);
// Avoid all the extra work if we can.
if (state.parent() != State.NONE) {
Set<KeyAndSource> keyAndSources = evictionCache.getIfPresent(state);
if (keyAndSources == null) {
evictionCache.put(state, keyAndSources = Sets.newHashSet());
}
keyAndSources.add(new KeyAndSource(key, convertedSource));
}
}
示例8: convertSpecialCharacters
import com.google.common.collect.Multiset; //導入方法依賴的package包/類
private Multiset<Multiset<String>> convertSpecialCharacters(Multiset<Multiset<String>> answers) {
Multiset<Multiset<String>> modifiedAnswers = HashMultiset.create();
for (Multiset<String> multiset : answers) {
Multiset<String> modifiedSubSet = HashMultiset.create();
for (String string : multiset) {
String modifiedString = expressionAdapter.process(string);
modifiedSubSet.add(modifiedString);
}
modifiedAnswers.add(modifiedSubSet);
}
return modifiedAnswers;
}
示例9: findSetsAnsewerExpressionParts
import com.google.common.collect.Multiset; //導入方法依賴的package包/類
private Multiset<Multiset<String>> findSetsAnsewerExpressionParts(List<String> allExpressionParts, List<Response> responses,
Function<Response, String> answerFetcher) {
Multiset<Multiset<String>> result = HashMultiset.create();
for (String expressionPart : allExpressionParts) {
List<String> responseIdentifiers = identifiersFromExpressionExtractor.extractResponseIdentifiersFromTemplate(expressionPart);
List<String> answerValues = getCorectValues(responseIdentifiers, responses, answerFetcher);
Multiset<String> expressionPartMultiSet = HashMultiset.create(answerValues);
result.add(expressionPartMultiSet);
}
return result;
}
示例10: gatherEventTypesSeen
import com.google.common.collect.Multiset; //導入方法依賴的package包/類
static Multiset<Symbol> gatherEventTypesSeen(
final Iterable<EALScorer2015Style.Result> perDocResults) {
final Multiset<Symbol> eventTypesSeen = HashMultiset.create();
for (final EALScorer2015Style.Result perDocResult : perDocResults) {
for (final TypeRoleFillerRealis trfr : perDocResult.argResult().argumentScoringAlignment()
.allEquivalenceClassess()) {
eventTypesSeen.add(trfr.type());
}
}
return eventTypesSeen;
}
示例11: testEquals_differentElements
import com.google.common.collect.Multiset; //導入方法依賴的package包/類
@CollectionSize.Require(absent = ZERO)
public void testEquals_differentElements() {
Multiset<E> other = HashMultiset.create(getSampleElements());
other.remove(e0());
other.add(e3());
assertFalse("multiset equals a multiset with different elements", getMultiset().equals(other));
}
示例12: incrementingEvent
import com.google.common.collect.Multiset; //導入方法依賴的package包/類
private ListenerCallQueue.Event<Object> incrementingEvent(
final Multiset<Object> counters, final Multiset<Object> expected) {
return new ListenerCallQueue.Event<Object>() {
@Override
public void call(Object listener) {
counters.add(listener);
assertEquals(expected.count(listener), counters.count(listener));
}
@Override
public String toString() {
return "incrementing";
}
};
}
示例13: add
import com.google.common.collect.Multiset; //導入方法依賴的package包/類
public void add(String system, String gold, int count) {
Multiset<String> set = confusions.get(gold);
if (set == null) {
set = HashMultiset.create();
confusions.put(gold, set);
}
set.add(system, count);
}
示例14: generate
import com.google.common.collect.Multiset; //導入方法依賴的package包/類
@Disabled
@Test
public void generate() throws IOException {
List<String> messages = Arrays.asList(
"CEF:0|Security|threatmanager|1.0|100|worm successfully stopped|10|src=10.0.0.1 dst=2.1.2.2 spt=1232",
"CEF:0|security|threatmanager|1.0|100|detected a \\| in message|10|src=10.0.0.1 act=blocked a | dst=1.1.1.1",
"CEF:0|security|threatmanager|1.0|100|detected a \\ in packet|10|src=10.0.0.1 act=blocked a \\ dst=1.1.1.1",
"CEF:0|security|threatmanager|1.0|100|detected a = in message|10|src=10.0.0.1 act=blocked a \\= dst=1.1.1.1",
"CEF:0|ArcSight|Logger|5.0.0.5355.2|sensor:115|Logger Internal Event|1|cat=/Monitor/Sensor/Fan5 cs2=Current Value cnt=1 dvc=10.0.0.1 cs3=Ok cs1=null type=0 cs1Label=unit rt=1305034099211 cs3Label=Status cn1Label=value cs2Label=timeframe",
"CEF:0|Trend Micro Inc.|OSSEC HIDS|v2.5.1|5302|User missed the password to change UID to root.|9|dvc=ubuntusvr cs2=ubuntusvr->/var/log/auth.log cs2Label=Location src= suser=root msg=May 11 21:16:05 ubuntusvr su[24120]: - /dev/pts/1 xavier:root",
"CEF:0|security|threatmanager|1.0|100|Detected a threat. No action needed.|10|src=10.0.0.1 msg=Detected a threat.\\n No action needed.",
"CEF:0|security|threatmanager|1.0|100|Detected a threat. No action needed.|10",
"filterlog: 5,16777216,,1000000003,igb1,match,block,in,6,0x00,0x00000,255,ICMPv6,58,32,2605:6000:c00:96::1,ff02::1:ffac:f98,",
"dhcpd: DHCPACK on 10.10.0.10 to 00:26:ab:fb:27:dc via igb2",
"dhcpd: DHCPREQUEST for 10.10.0.10 from 00:26:ab:fb:27:dc via igb2",
"dhcpleases: Sending HUP signal to dns daemon(69876)"
);
Multiset<String> counts = HashMultiset.create();
for (String message : messages) {
TestCase testCase = new TestCase();
Struct valueInput = new Struct(VALUE_SCHEMA)
.put("date", new Date(1493195158000L))
.put("facility", 16)
.put("host", "filterlog")
.put("level", 6)
.put("message", message)
.put("charset", "utf-8")
.put("remote_address", "/10.10.0.1:514")
.put("hostname", "vpn.example.com");
testCase.input = new SourceRecord(
ImmutableMap.of(),
ImmutableMap.of(),
"syslog",
null,
null,
null,
valueInput.schema(),
valueInput,
1493195158000L
);
String fileNameFormat;
try {
testCase.expected = (SourceRecord) this.transformation.apply(testCase.input);
fileNameFormat = testCase.expected.topic().equals("syslog.cef") ? "CEF%04d.json" : "NotCEF%04d.json";
((Struct) testCase.expected.value()).validate();
// fileNameFormat = "CEF%04d.json";
} catch (IllegalStateException ex) {
fileNameFormat = "NotCEF%04d.json";
testCase.expected = testCase.input;
}
counts.add(fileNameFormat);
int testNumber = counts.count(fileNameFormat);
File root = new File("src/test/resources/com/github/jcustenborder/kafka/connect/transform/cef/records");
String filename = String.format(fileNameFormat, testNumber);
File file = new File(root, filename);
log.trace("Saving {}", filename);
ObjectMapperFactory.INSTANCE.writeValue(file, testCase);
}
}
示例15: importSystemOutputToAnnotationStore
import com.google.common.collect.Multiset; //導入方法依賴的package包/類
private static void importSystemOutputToAnnotationStore(Set<SystemOutputStore> argumentStores,
Set<AnnotationStore> annotationStores,
Function<DocumentSystemOutput, DocumentSystemOutput> filter, Predicate<Symbol> docIdFilter)
throws IOException {
log.info("Loading system outputs from {}", StringUtils.NewlineJoiner.join(argumentStores));
log.info("Using assessment stores at {}", StringUtils.NewlineJoiner.join(annotationStores));
final Multiset<AnnotationStore> totalNumAdded = HashMultiset.create();
final Multiset<AnnotationStore> totalAlreadyThere = HashMultiset.create();
for (final SystemOutputStore systemOutput : argumentStores) {
log.info("Processing system output from {}", systemOutput);
for (final Symbol docid : filter(systemOutput.docIDs(), docIdFilter)) {
final DocumentSystemOutput docOutput = filter.apply(systemOutput.read(docid));
log.info("Processing {} responses for document {}", docid, docOutput.arguments().size());
for (final AnnotationStore annStore : annotationStores) {
final AnswerKey currentAnnotation = annStore.readOrEmpty(docid);
final int numAnnotatedResponsesInCurrentAnnotation =
currentAnnotation.annotatedResponses().size();
final int numUnannotatedResponsesInCurrentAnnotation =
currentAnnotation.unannotatedResponses().size();
final AnswerKey newAnswerKey = currentAnnotation.copyAddingPossiblyUnannotated(
docOutput.arguments().responses());
final int numAdded =
newAnswerKey.unannotatedResponses().size() - numUnannotatedResponsesInCurrentAnnotation;
final int numAlreadyKnown = docOutput.arguments().responses().size() - numAdded;
log.info(
"Annotation store {} has {} annotated and {} unannotated; added {} for assessment",
annStore, numAnnotatedResponsesInCurrentAnnotation,
numUnannotatedResponsesInCurrentAnnotation, numAdded);
annStore.write(newAnswerKey);
totalNumAdded.add(annStore, numAdded);
totalAlreadyThere.add(annStore, numAlreadyKnown);
}
}
}
log.info("Total number of responses added: {}", totalNumAdded);
log.info("Total number of responses already known: {}", totalAlreadyThere);
}