Skip to content

Project import generated by Copybara. #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@

package com.google.cloud.datastore.core.number;

/**
* A utility class for comparing numbers.
*
* @hide
*/
/** A utility class for comparing numbers. */
public final class NumberComparisonHelper {

// Long.MIN_VALUE has an exact representation as double, so the long lower bound is inclusive.
Expand All @@ -33,10 +29,10 @@ public final class NumberComparisonHelper {
public static final long MIN_SAFE_LONG = -MAX_SAFE_LONG;

/**
* Compares a double and a long. Firestore ordering: NaN precedes all other numbers and equals
* itself, all zeroes are equal.
* Compares a double and a with Firestore query semantics: NaN precedes all other numbers and
* equals itself, all zeroes are equal.
*/
public static int compareDoubleWithLong(double doubleValue, long longValue) {
public static int firestoreCompareDoubleWithLong(double doubleValue, long longValue) {
// In Firestore NaN is defined to compare before all other numbers.
if (Double.isNaN(doubleValue)) {
return -1;
Expand All @@ -60,7 +56,7 @@ public static int compareDoubleWithLong(double doubleValue, long longValue) {

// At this point the long representations are equal but this could be due to rounding.
double longAsDouble = (double) longValue;
return compareDoubles(doubleValue, longAsDouble);
return firestoreCompareDoubles(doubleValue, longAsDouble);
}

/**
Expand All @@ -77,25 +73,14 @@ public static int compareLongs(long leftLong, long rightLong) {
}
}

/** Compares ints. See the comment to {@link #compareLongs} for rationale. */
public static int compareInts(int leftInt, int rightInt) {
if (leftInt < rightInt) {
return -1;
} else if (leftInt > rightInt) {
return 1;
} else {
return 0;
}
}

/**
* Compares doubles. Firestore ordering: NaN precedes all other numbers and equals itself, all
* zeroes are equal.
* Compares doubles with Firestore query semantics: NaN precedes all other numbers and equals
* itself, all zeroes are equal.
*
* @return a negative integer, zero, or a positive integer as the first argument is less than,
* equal to, or greater than the second.
*/
public static int compareDoubles(double leftDouble, double rightDouble) {
public static int firestoreCompareDoubles(double leftDouble, double rightDouble) {
// NaN sorts equal to itself and before any other number.
if (leftDouble < rightDouble) {
return -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
* <p>Implementation conforms to the UTF Style Encoding section of "Number Index Entry Encoding".
*
* @see "https://docs.google.com/document/d/1QX32BCTFWFS_4BneQHFRDnPb2ts04fYrm4Vgy0HLSBg/edit#"
* @hide
*/
public class NumberIndexEncoder {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
/**
* The representation of a number that can accommodate the range of doubles and longs without loss
* of precision.
*
* @hide
*/
public final class NumberParts {

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,17 @@ public static int compareLongs(long i1, long i2) {

/** Utility function to compare ints. See {@link #compareLongs} for rationale. */
public static int compareInts(int i1, int i2) {
return NumberComparisonHelper.compareInts(i1, i2);
return NumberComparisonHelper.compareLongs(i1, i2);
}

/** Utility function to compare doubles (using Firestore semantics for NaN). */
public static int compareDoubles(double i1, double i2) {
return NumberComparisonHelper.compareDoubles(i1, i2);
return NumberComparisonHelper.firestoreCompareDoubles(i1, i2);
}

/** Compares a double and a long (using Firestore semantics for NaN). */
public static int compareMixed(double doubleValue, long longValue) {
return NumberComparisonHelper.compareDoubleWithLong(doubleValue, longValue);
return NumberComparisonHelper.firestoreCompareDoubleWithLong(doubleValue, longValue);
}

@SuppressWarnings("unchecked")
Expand Down