本文整理汇总了Java中com.google.common.collect.Multiset.isEmpty方法的典型用法代码示例。如果您正苦于以下问题:Java Multiset.isEmpty方法的具体用法?Java Multiset.isEmpty怎么用?Java Multiset.isEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.collect.Multiset
的用法示例。
在下文中一共展示了Multiset.isEmpty方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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;
}
// ∣q ∩ r∣ / min{∣q∣, ∣r∣}
return intersection(a, b).size() / (float) min(a.size(), b.size());
}
示例3: 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;
}
float maxDistance = (float) sqrt((a.size() * a.size()) + (b.size() * b.size()));
return 1.0f - distance(a, b) / maxDistance;
}
示例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());
}
示例6: 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)));
}
示例7: cleanUpForCollectedState
import com.google.common.collect.Multiset; //导入方法依赖的package包/类
/**
* There may be multiple child injectors blacklisting a certain key so only remove the source
* that's relevant.
*/
private void cleanUpForCollectedState(Set<KeyAndSource> keysAndSources) {
synchronized (lock) {
for (KeyAndSource keyAndSource : keysAndSources) {
Multiset<Object> set = backingMap.get(keyAndSource.key);
if (set != null) {
set.remove(keyAndSource.source);
if (set.isEmpty()) {
backingMap.remove(keyAndSource.key);
}
}
}
}
}