本文整理匯總了Java中com.google.common.collect.Multiset.size方法的典型用法代碼示例。如果您正苦於以下問題:Java Multiset.size方法的具體用法?Java Multiset.size怎麽用?Java Multiset.size使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.collect.Multiset
的用法示例。
在下文中一共展示了Multiset.size方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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;
}
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);
}
示例2: union
import com.google.common.collect.Multiset; //導入方法依賴的package包/類
static <T> Multiset<T> union(Multiset<T> a, Multiset<T> b) {
// Lager set first for performance improvement.
// See: MathCaliper
if (a.size() < b.size()) {
return Multisets.union(b, a);
}
return Multisets.union(a, b);
}
示例3: intersection
import com.google.common.collect.Multiset; //導入方法依賴的package包/類
static <T> Multiset<T> intersection(Multiset<T> a, Multiset<T> b) {
// Smaller set first for performance improvement.
// See: MathCaliper
if (a.size() < b.size()) {
return Multisets.intersection(a, b);
}
return Multisets.intersection(b, a);
}
示例4: 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;
}
// 2 * ∣a ∩ b∣ / (∣a∣ + ∣b∣)
return (2.0f * intersection(a, b).size()) / (a.size() + b.size());
}
示例5: 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;
}
return 1.0f - distance(a, b) / (a.size() + b.size());
}