16
16
17
17
import androidx .annotation .NonNull ;
18
18
import com .google .auto .value .AutoValue ;
19
- import com .google .firebase .Timestamp ;
20
19
import java .util .ArrayList ;
21
20
import java .util .Iterator ;
22
21
import java .util .List ;
@@ -60,24 +59,24 @@ public String toString() {
60
59
private final String collectionGroup ;
61
60
private final int indexId ;
62
61
private final List <Segment > segments ;
63
- private final Timestamp updateTime ;
62
+ private final SnapshotVersion version ;
64
63
65
64
public FieldIndex (String collectionGroup , int indexId ) {
66
65
this .collectionGroup = collectionGroup ;
67
66
this .segments = new ArrayList <>();
68
67
this .indexId = indexId ;
69
- this .updateTime = new Timestamp ( 0L , 0 ) ;
68
+ this .version = SnapshotVersion . NONE ;
70
69
}
71
70
72
71
public FieldIndex (String collectionId ) {
73
72
this (collectionId , -1 );
74
73
}
75
74
76
- FieldIndex (String collectionGroup , int indexId , List <Segment > segments , Timestamp updateTime ) {
75
+ FieldIndex (String collectionGroup , int indexId , List <Segment > segments , SnapshotVersion version ) {
77
76
this .collectionGroup = collectionGroup ;
78
77
this .segments = segments ;
79
78
this .indexId = indexId ;
80
- this .updateTime = updateTime ;
79
+ this .version = version ;
81
80
}
82
81
83
82
/** The collection ID this index applies to. */
@@ -101,8 +100,8 @@ public int segmentCount() {
101
100
return segments .size ();
102
101
}
103
102
104
- public Timestamp getUpdateTime () {
105
- return updateTime ;
103
+ public SnapshotVersion getVersion () {
104
+ return version ;
106
105
}
107
106
108
107
@ NonNull
@@ -115,12 +114,12 @@ public Iterator<Segment> iterator() {
115
114
public FieldIndex withAddedField (FieldPath fieldPath , Segment .Kind kind ) {
116
115
List <Segment > newSegments = new ArrayList <>(segments );
117
116
newSegments .add (new AutoValue_FieldIndex_Segment (fieldPath , kind ));
118
- return new FieldIndex (collectionGroup , indexId , newSegments , updateTime );
117
+ return new FieldIndex (collectionGroup , indexId , newSegments , version );
119
118
}
120
119
121
- /** Returns a new field index with the updated updateTime . */
122
- public FieldIndex withUpdateTime ( Timestamp updateTime ) {
123
- return new FieldIndex (collectionGroup , indexId , segments , updateTime );
120
+ /** Returns a new field index with the updated version . */
121
+ public FieldIndex withVersion ( SnapshotVersion version ) {
122
+ return new FieldIndex (collectionGroup , indexId , segments , version );
124
123
}
125
124
126
125
@ Override
@@ -131,19 +130,22 @@ public boolean equals(Object o) {
131
130
FieldIndex fieldIndex = (FieldIndex ) o ;
132
131
133
132
if (!segments .equals (fieldIndex .segments )) return false ;
133
+ if (!version .equals (fieldIndex .version )) return false ;
134
134
return collectionGroup .equals (fieldIndex .collectionGroup );
135
135
}
136
136
137
137
@ Override
138
138
public int hashCode () {
139
139
int result = collectionGroup .hashCode ();
140
140
result = 31 * result + segments .hashCode ();
141
+ result = 31 * result + version .hashCode ();
141
142
return result ;
142
143
}
143
144
144
145
@ Override
145
146
public String toString () {
146
147
return String .format (
147
- "FieldIndex{collectionGroup='%s', segments=%s}" , collectionGroup , segments );
148
+ "FieldIndex{collectionGroup='%s', segments=%s, version=%s}" ,
149
+ collectionGroup , segments , version );
148
150
}
149
151
}
0 commit comments