File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed
main/java/com/google/firebase/database/core/utilities
test/java/com/google/firebase/database Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -71,7 +71,7 @@ public static final String predecessor(String key) {
71
71
Validation .validateNullableKey (key );
72
72
Integer num = tryParseInt (key );
73
73
if (num != null ) {
74
- if (Long . valueOf ( num ) - 1 < Integer .MIN_VALUE ) {
74
+ if (num == Integer .MIN_VALUE ) {
75
75
return ChildKey .MIN_KEY_NAME ;
76
76
}
77
77
return String .valueOf (num - 1 );
@@ -98,7 +98,7 @@ public static final String successor(String key) {
98
98
Validation .validateNullableKey (key );
99
99
Integer num = tryParseInt (key );
100
100
if (num != null ) {
101
- if (num + 1L > Integer .MAX_VALUE ) {
101
+ if (num == Integer .MAX_VALUE ) {
102
102
// See https://firebase.google.com/docs/database/web/lists-of-data#data-order
103
103
return String .valueOf (MIN_PUSH_CHAR );
104
104
}
Original file line number Diff line number Diff line change 15
15
package com .google .firebase .database ;
16
16
17
17
import static com .google .firebase .database .snapshot .ChildKey .MAX_KEY_NAME ;
18
+ import static com .google .firebase .database .snapshot .ChildKey .MIN_KEY_NAME ;
18
19
import static org .junit .Assert .assertEquals ;
19
20
20
21
import com .google .firebase .database .core .utilities .PushIdGenerator ;
@@ -56,4 +57,21 @@ public void testSuccessorBasic() {
56
57
assertEquals (
57
58
PushIdGenerator .successor ("abc" + MIN_PUSH_CHAR ), "abc" + MIN_PUSH_CHAR + MIN_PUSH_CHAR );
58
59
}
60
+
61
+ @ Test
62
+ public void testPredecessorSpecialValue () {
63
+ assertEquals (
64
+ PushIdGenerator .predecessor (String .valueOf (MIN_PUSH_CHAR )),
65
+ String .valueOf (Integer .MAX_VALUE ));
66
+ assertEquals (PushIdGenerator .predecessor (String .valueOf (Integer .MIN_VALUE )), MIN_KEY_NAME );
67
+ }
68
+
69
+ @ Test
70
+ public void testPredecessorBasicValue () {
71
+ assertEquals (
72
+ PushIdGenerator .predecessor ("abc" ),
73
+ "abb"
74
+ + StringUtils .repeat (Character .toString (MAX_PUSH_CHAR ), MAX_KEY_LEN - "abc" .length ()));
75
+ assertEquals (PushIdGenerator .predecessor ("abc" + MIN_PUSH_CHAR ), "abc" );
76
+ }
59
77
}
You can’t perform that action at this time.
0 commit comments