本文整理汇总了Java中com.google.common.primitives.Doubles.compare方法的典型用法代码示例。如果您正苦于以下问题:Java Doubles.compare方法的具体用法?Java Doubles.compare怎么用?Java Doubles.compare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.primitives.Doubles
的用法示例。
在下文中一共展示了Doubles.compare方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compareTo
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
@Override
public int compareTo(PlanPath o) {
int res = -1*Doubles.compare(getCost(), o.getCost());
if(res==0)
res = getSelectTable().getName().compareTo(o.getSelectTable().getName());
return res;
}
示例2: equals
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof City)) return false;
City city = (City) o;
if (Doubles.compare(city.averageRainfall, averageRainfall) != 0) return false;
if (population != city.population) return false;
if (climate != city.climate) return false;
if (name != null ? !name.equals(city.name) : city.name != null) return false;
return zipCode != null ? zipCode.equals(city.zipCode) : city.zipCode == null;
}
示例3: equals
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Stock)) return false;
Stock stock = (Stock) o;
if (Doubles.compare(stock.price, price) != 0) return false;
return symbol != null ? symbol.equals(stock.symbol) : stock.symbol == null;
}
示例4: compare
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
@Override
public int compare(CapFloorIbor o1, CapFloorIbor o2) {
int a = Doubles.compare(o1.getStrike(), o2.getStrike());
if (a != 0) {
return a;
}
return Doubles.compare(o1.getFixingTime(), o2.getFixingTime());
}
示例5: verifyCandidates
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
private final Long2DoubleOpenHashMap verifyCandidates(final Vector v, Long2DoubleOpenHashMap accumulator) {
numSimilarities = numCandidates;
// add forgetting factor e^(-lambda*delta_T) and filter candidates < theta
for (Iterator<Long2DoubleMap.Entry> it = accumulator.long2DoubleEntrySet().iterator(); it.hasNext();) {
Long2DoubleMap.Entry e = it.next();
final long deltaT = v.timestamp() - e.getLongKey();
e.setValue(e.getDoubleValue() * forgettingFactor(lambda, deltaT));
if (Doubles.compare(e.getDoubleValue(), theta) < 0)
it.remove();
}
numMatches += accumulator.size();
return accumulator;
}
示例6: generateCandidates
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
private final void generateCandidates(final Vector v, final boolean addToIndex) {
for (Int2DoubleMap.Entry e : v.int2DoubleEntrySet()) {
final int dimension = e.getIntKey();
final double queryWeight = e.getDoubleValue();
StreamingPostingList list;
if ((list = idx.get(dimension)) != null) {
for (StreamingPostingListIterator listIter = list.reverseIterator(); listIter.hasPrevious();) {
final PostingEntry pe = listIter.previous();
final long targetID = pe.getID();
// time filtering
final long deltaT = v.timestamp() - targetID;
if (Doubles.compare(deltaT, tau) > 0) {
listIter.next(); // back off one position
size -= listIter.nextIndex(); // update index size before cutting
listIter.cutHead(); // prune the head
break;
}
numPostingEntries++;
final double targetWeight = pe.getWeight();
final double additionalSimilarity = queryWeight * targetWeight * forgettingFactor(lambda, deltaT);
accumulator.addTo(targetID, additionalSimilarity);
}
} else {
if (addToIndex) {
list = new StreamingPostingList();
idx.put(dimension, list);
}
}
if (addToIndex) {
list.add(v.timestamp(), queryWeight);
size++;
}
}
numCandidates += accumulator.size();
}
示例7: verifyCandidates
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
private final void verifyCandidates(final Vector v) {
numSimilarities = numCandidates;
// filter candidates < theta
for (Iterator<Long2DoubleMap.Entry> it = accumulator.long2DoubleEntrySet().iterator(); it.hasNext();)
if (Doubles.compare(it.next().getDoubleValue(), theta) < 0)
it.remove();
numMatches += accumulator.size();
}
示例8: initOrderingLng
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
/**
* Initializes the field {@link #orderingLng} if it is {@code null}.
*/
private void initOrderingLng() {
if (orderingLng == null) {
orderingLng = new Ordering<Node>() {
@Override
public int compare(Node left, Node right) {
return Doubles.compare(left.getLongitude(),
right.getLongitude());
}
};
}
}
示例9: initOrderingLat
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
/**
* Initializes the field {@link #orderingLat} if it is {@code null}.
*/
private void initOrderingLat() {
if (orderingLat == null) { // Lazy initialization
orderingLat = new Ordering<Node>() {
@Override
public int compare(Node left, Node right) {
return Doubles.compare(left.getLatitude(),
right.getLatitude());
}
};
}
}
示例10: findNearestNode
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
/**
* Recursive Nearest Node Search on kd-tree.
*
* @param current the current
* @param search the search
* @param depth the depth
* @return the node
*/
private Node findNearestNode(Node current, Node search, int depth) {
// Go down tree
int direction;
if (depth % 2 == 0) {
direction = Doubles.compare(search.latitude, current.latitude);
} else {
direction = Doubles.compare(search.longitude, current.longitude);
}
int next = direction < 0 ? kdLeft[current.id - 1]
: kdRight[current.id - 1];
int other = direction < 0 ? kdRight[current.id - 1]
: kdLeft[current.id - 1];
// Go to a leaf node and mark it as best!
Node best = next == NULL_NODE ? current : findNearestNode(
nodeArray[next - 1], search, depth + 1);
// Compare current node to best node
if (current.squaredDistance(search) < best.squaredDistance(search)) {
best = current; // Set best as required
}
if (other != NULL_NODE) {
if (current.axisSquaredDistance(search, depth % 2) < best
.axisSquaredDistance(search, depth % 2)) {
Node possibleBest = findNearestNode(nodeArray[other - 1],
search, depth + 1);
if (possibleBest.squaredDistance(search) < best
.squaredDistance(search)) {
best = possibleBest;
}
}
}
// Go up tree.
return best;
}
示例11: compareTo
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
public int compareTo(ChunkRenderDispatcher.PendingUpload p_compareTo_1_)
{
return Doubles.compare(this.distanceSq, p_compareTo_1_.distanceSq);
}
示例12: compareTo
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
public int compareTo(ChunkCompileTaskGenerator p_compareTo_1_)
{
return Doubles.compare(this.distanceSq, p_compareTo_1_.distanceSq);
}
示例13: compare
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
@Override
public int compare(Object o, Object o1)
{
return Doubles.compare(((Number) o).doubleValue(), ((Number) o1).doubleValue());
}
示例14: compareTo
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public int compareTo(Literal o) {
Object that = o.getValue();
// Sort nulls first
if (_value == null) {
return that == null ? 0 : -1;
} else if (that == null) {
return 1;
}
// Optimize for common case where values being compared are of the same type
Class<?> thisClass = _value.getClass();
Class<?> thatClass = that.getClass();
if (!areClassesEqual(thisClass, thatClass)) {
// Values are of different types
// If both values are numeric then use numeric comparison regardless of the underlying type (int, double, and so on)
if (isNumber(thisClass) && isNumber(thatClass)) {
if (isDouble((Class<? extends Number>) thisClass) || isDouble((Class<? extends Number>) thatClass)) {
return Doubles.compare(((Number) _value).doubleValue(), ((Number) that).doubleValue());
} else {
return Longs.compare(((Number) _value).longValue(), ((Number) that).longValue());
}
}
// Sort by simple class name
return getComparisonClassName(thisClass).compareTo(getComparisonClassName(thatClass));
}
if (Comparable.class.isAssignableFrom(thisClass)) {
return ((Comparable) _value).compareTo(that);
}
// When not comparable, compare the string representations
try {
StringBuilder thisStr = new StringBuilder();
StringBuilder thatStr = new StringBuilder();
this.appendTo(thisStr);
o.appendTo(thatStr);
return thisStr.toString().compareTo(thatStr.toString());
} catch (IOException e) {
// Should never happen
throw Throwables.propagate(e);
}
}
示例15: compare
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
@Override
public int compare(City city1, City city2) {
return Doubles.compare(city1.getAverageRainfall(), city2.getAverageRainfall());
}