Skip to content

Commit 7e685f7

Browse files
committed
More expression work
1 parent c324298 commit 7e685f7

File tree

1 file changed

+186
-6
lines changed
  • firebase-firestore/src/main/java/com/google/firebase/firestore/pipeline

1 file changed

+186
-6
lines changed

firebase-firestore/src/main/java/com/google/firebase/firestore/pipeline/expressions.kt

Lines changed: 186 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -570,51 +570,175 @@ abstract class Expr internal constructor() {
570570
fun bitRightShift(bitsFieldName: String, number: Int): Expr =
571571
FunctionExpr("bit_right_shift", bitsFieldName, number)
572572

573+
/**
574+
* Creates an expression that rounds [numericExpr] to nearest integer.
575+
*
576+
* Rounds away from zero in halfway cases.
577+
*
578+
* @param numericExpr An expression that returns number when evaluated.
579+
* @return A new [Expr] representing an integer result from the round operation.
580+
*/
581+
@JvmStatic fun round(numericExpr: Expr): Expr = FunctionExpr("round", numericExpr)
582+
583+
/**
584+
* Creates an expression that rounds [numericField] to nearest integer.
585+
*
586+
* Rounds away from zero in halfway cases.
587+
*
588+
* @param numericField Name of field that returns number when evaluated.
589+
* @return A new [Expr] representing an integer result from the round operation.
590+
*/
591+
@JvmStatic fun round(numericField: String): Expr = FunctionExpr("round", numericField)
592+
593+
/**
594+
* Creates an expression that rounds off [numericExpr] to [decimalPlace] decimal places if
595+
* [decimalPlace] is positive, rounds off digits to the left of the decimal point if
596+
* [decimalPlace] is negative. Rounds away from zero in halfway cases.
597+
*
598+
* @param numericExpr An expression that returns number when evaluated.
599+
* @param decimalPlace The number of decimal places to round.
600+
* @return A new [Expr] representing the round operation.
601+
*/
573602
@JvmStatic
574603
fun round(numericExpr: Expr, decimalPlace: Int): Expr =
575604
FunctionExpr("round", numericExpr, constant(decimalPlace))
576605

606+
/**
607+
* Creates an expression that rounds off [numericField] to [decimalPlace] decimal places if
608+
* [decimalPlace] is positive, rounds off digits to the left of the decimal point if
609+
* [decimalPlace] is negative. Rounds away from zero in halfway cases.
610+
*
611+
* @param numericField Name of field that returns number when evaluated.
612+
* @param decimalPlace The number of decimal places to round.
613+
* @return A new [Expr] representing the round operation.
614+
*/
577615
@JvmStatic
578616
fun round(numericField: String, decimalPlace: Int): Expr =
579617
FunctionExpr("round", numericField, constant(decimalPlace))
580618

581-
@JvmStatic fun round(numericExpr: Expr): Expr = FunctionExpr("round", numericExpr)
582-
583-
@JvmStatic fun round(numericField: String): Expr = FunctionExpr("round", numericField)
584-
619+
/**
620+
* Creates an expression that rounds off [numericExpr] to [decimalPlace] decimal places if
621+
* [decimalPlace] is positive, rounds off digits to the left of the decimal point if
622+
* [decimalPlace] is negative. Rounds away from zero in halfway cases.
623+
*
624+
* @param numericExpr An expression that returns number when evaluated.
625+
* @param decimalPlace The number of decimal places to round.
626+
* @return A new [Expr] representing the round operation.
627+
*/
585628
@JvmStatic
586629
fun round(numericExpr: Expr, decimalPlace: Expr): Expr =
587630
FunctionExpr("round", numericExpr, decimalPlace)
588631

632+
/**
633+
* Creates an expression that rounds off [numericField] to [decimalPlace] decimal places if
634+
* [decimalPlace] is positive, rounds off digits to the left of the decimal point if
635+
* [decimalPlace] is negative. Rounds away from zero in halfway cases.
636+
*
637+
* @param numericField Name of field that returns number when evaluated.
638+
* @param decimalPlace The number of decimal places to round.
639+
* @return A new [Expr] representing the round operation.
640+
*/
589641
@JvmStatic
590642
fun round(numericField: String, decimalPlace: Expr): Expr =
591643
FunctionExpr("round", numericField, decimalPlace)
592644

645+
/**
646+
* Creates an expression that returns the smalled integer that isn't less than [numericExpr].
647+
*
648+
* @param numericExpr An expression that returns number when evaluated.
649+
* @return A new [Expr] representing an integer result from the ceil operation.
650+
*/
593651
@JvmStatic fun ceil(numericExpr: Expr): Expr = FunctionExpr("ceil", numericExpr)
594652

653+
/**
654+
* Creates an expression that returns the smalled integer that isn't less than [numericField].
655+
*
656+
* @param numericField Name of field that returns number when evaluated.
657+
* @return A new [Expr] representing an integer result from the ceil operation.
658+
*/
595659
@JvmStatic fun ceil(numericField: String): Expr = FunctionExpr("ceil", numericField)
596660

661+
/**
662+
* Creates an expression that returns the largest integer that isn't less than [numericExpr].
663+
*
664+
* @param numericExpr An expression that returns number when evaluated.
665+
* @return A new [Expr] representing an integer result from the floor operation.
666+
*/
597667
@JvmStatic fun floor(numericExpr: Expr): Expr = FunctionExpr("floor", numericExpr)
598668

669+
/**
670+
* Creates an expression that returns the largest integer that isn't less than [numericField].
671+
*
672+
* @param numericField Name of field that returns number when evaluated.
673+
* @return A new [Expr] representing an integer result from the floor operation.
674+
*/
599675
@JvmStatic fun floor(numericField: String): Expr = FunctionExpr("floor", numericField)
600676

677+
/**
678+
* Creates an expression that returns the [numericExpr] raised to the power of the [exponent].
679+
* Returns infinity on overflow and zero on underflow.
680+
*
681+
* @param numericExpr An expression that returns number when evaluated.
682+
* @param exponent The numeric power to raise the [numericExpr].
683+
* @return A new [Expr] representing a numeric result from raising [numericExpr] to the power of
684+
* [exponent].
685+
*/
601686
@JvmStatic
602687
fun pow(numericExpr: Expr, exponent: Number): Expr =
603688
FunctionExpr("pow", numericExpr, constant(exponent))
604689

690+
/**
691+
* Creates an expression that returns the [numericField] raised to the power of the [exponent].
692+
* Returns infinity on overflow and zero on underflow.
693+
*
694+
* @param numericField Name of field that returns number when evaluated.
695+
* @param exponent The numeric power to raise the [numericField].
696+
* @return A new [Expr] representing a numeric result from raising [numericField] to the power
697+
* of [exponent].
698+
*/
605699
@JvmStatic
606700
fun pow(numericField: String, exponent: Number): Expr =
607701
FunctionExpr("pow", numericField, constant(exponent))
608702

703+
/**
704+
* Creates an expression that returns the [numericExpr] raised to the power of the [exponent].
705+
* Returns infinity on overflow and zero on underflow.
706+
*
707+
* @param numericExpr An expression that returns number when evaluated.
708+
* @param exponent The numeric power to raise the [numericExpr].
709+
* @return A new [Expr] representing a numeric result from raising [numericExpr] to the power of
710+
* [exponent].
711+
*/
609712
@JvmStatic
610713
fun pow(numericExpr: Expr, exponent: Expr): Expr = FunctionExpr("pow", numericExpr, exponent)
611714

715+
/**
716+
* Creates an expression that returns the [numericField] raised to the power of the [exponent].
717+
* Returns infinity on overflow and zero on underflow.
718+
*
719+
* @param numericField Name of field that returns number when evaluated.
720+
* @param exponent The numeric power to raise the [numericField].
721+
* @return A new [Expr] representing a numeric result from raising [numericField] to the power
722+
* of [exponent].
723+
*/
612724
@JvmStatic
613725
fun pow(numericField: String, exponent: Expr): Expr =
614726
FunctionExpr("pow", numericField, exponent)
615727

728+
/**
729+
* Creates an expression that returns the square root of [numericExpr].
730+
*
731+
* @param numericExpr An expression that returns number when evaluated.
732+
* @return A new [Expr] representing the numeric result of the square root operation.
733+
*/
616734
@JvmStatic fun sqrt(numericExpr: Expr): Expr = FunctionExpr("sqrt", numericExpr)
617735

736+
/**
737+
* Creates an expression that returns the square root of [numericField].
738+
*
739+
* @param numericField Name of field that returns number when evaluated.
740+
* @return A new [Expr] representing the numeric result of the square root operation.
741+
*/
618742
@JvmStatic fun sqrt(numericField: String): Expr = FunctionExpr("sqrt", numericField)
619743

620744
/**
@@ -2429,20 +2553,76 @@ abstract class Expr internal constructor() {
24292553
*/
24302554
fun mod(other: Any) = Companion.mod(this, other)
24312555

2556+
/**
2557+
* Creates an expression that rounds this numeric expression to nearest integer.
2558+
*
2559+
* Rounds away from zero in halfway cases.
2560+
*
2561+
* @return A new [Expr] representing an integer result from the round operation.
2562+
*/
24322563
fun round() = Companion.round(this)
24332564

2565+
/**
2566+
* Creates an expression that rounds off this numeric expression to [decimalPlace] decimal places
2567+
* if [decimalPlace] is positive, rounds off digits to the left of the decimal point if
2568+
* [decimalPlace] is negative. Rounds away from zero in halfway cases.
2569+
*
2570+
* @param decimalPlace The number of decimal places to round.
2571+
* @return A new [Expr] representing the round operation.
2572+
*/
24342573
fun round(decimalPlace: Int) = Companion.round(this, decimalPlace)
24352574

2575+
/**
2576+
* Creates an expression that rounds off this numeric expression to [decimalPlace] decimal places
2577+
* if [decimalPlace] is positive, rounds off digits to the left of the decimal point if
2578+
* [decimalPlace] is negative. Rounds away from zero in halfway cases.
2579+
*
2580+
* @param decimalPlace The number of decimal places to round.
2581+
* @return A new [Expr] representing the round operation.
2582+
*/
24362583
fun round(decimalPlace: Expr) = Companion.round(this, decimalPlace)
24372584

2585+
/**
2586+
* Creates an expression that returns the smalled integer that isn't less than this numeric
2587+
* expression.
2588+
*
2589+
* @return A new [Expr] representing an integer result from the ceil operation.
2590+
*/
24382591
fun ceil() = Companion.ceil(this)
24392592

2593+
/**
2594+
* Creates an expression that returns the largest integer that isn't less than this numeric
2595+
* expression.
2596+
*
2597+
* @return A new [Expr] representing an integer result from the floor operation.
2598+
*/
24402599
fun floor() = Companion.floor(this)
24412600

2442-
fun pow(exponentExpr: Number) = Companion.pow(this, exponentExpr)
2601+
/**
2602+
* Creates an expression that returns this numeric expression raised to the power of the
2603+
* [exponent]. Returns infinity on overflow and zero on underflow.
2604+
*
2605+
* @param exponent The numeric power to raise this numeric expression.
2606+
* @return A new [Expr] representing a numeric result from raising this numeric expression to the
2607+
* power of [exponent].
2608+
*/
2609+
fun pow(exponent: Number) = Companion.pow(this, exponent)
24432610

2444-
fun pow(exponentExpr: Expr) = Companion.pow(this, exponentExpr)
2611+
/**
2612+
* Creates an expression that returns this numeric expression raised to the power of the
2613+
* [exponent]. Returns infinity on overflow and zero on underflow.
2614+
*
2615+
* @param exponent The numeric power to raise this numeric expression.
2616+
* @return A new [Expr] representing a numeric result from raising this numeric expression to the
2617+
* power of [exponent].
2618+
*/
2619+
fun pow(exponent: Expr) = Companion.pow(this, exponent)
24452620

2621+
/**
2622+
* Creates an expression that returns the square root of this numeric expression.
2623+
*
2624+
* @return A new [Expr] representing the numeric result of the square root operation.
2625+
*/
24462626
fun sqrt() = Companion.sqrt(this)
24472627

24482628
/**

0 commit comments

Comments
 (0)