本文整理匯總了Java中com.google.common.collect.Multiset.count方法的典型用法代碼示例。如果您正苦於以下問題:Java Multiset.count方法的具體用法?Java Multiset.count怎麽用?Java Multiset.count使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.collect.Multiset
的用法示例。
在下文中一共展示了Multiset.count方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: toString
import com.google.common.collect.Multiset; //導入方法依賴的package包/類
public static <T> String toString(Collection<T> ts) {
if (ts instanceof Multiset<?>) {
StringBuilder sb = new StringBuilder();
Multiset<T> es = (Multiset<T>) ts;
for (T e : es.elementSet()) {
int count = es.count(e);
sb.append(e + ", " + count + "\n");
}
return sb.toString();
}
return toString(ts, ",");
}
示例2: compare
import com.google.common.collect.Multiset; //導入方法依賴的package包/類
@Override
public float compare(Multiset<T> a, Multiset<T> b) {
if (a.isEmpty() && b.isEmpty()) {
return 1.0f;
}
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;
}
// a·b / (||a|| * ||b||)
return (float) (dotProduct / (sqrt(magnitudeA) * sqrt(magnitudeB)));
}
示例3: getCount
import com.google.common.collect.Multiset; //導入方法依賴的package包/類
public int getCount(String system, String gold) {
Multiset<String> set = confusions.get(gold);
if (set == null) {
return 0;
}
return set.count(system);
}
示例4: 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);
}
}