本文整理汇总了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());
}