1212import org .apache .lucene .util .BytesRef ;
1313import org .elasticsearch .common .bytes .BytesReference ;
1414import org .elasticsearch .common .io .stream .BytesStreamOutput ;
15- import org .elasticsearch .common .io .stream .StreamOutput ;
1615import org .elasticsearch .common .recycler .Recycler ;
1716import org .elasticsearch .transport .BytesRefRecycler ;
1817import org .elasticsearch .xcontent .ToXContent ;
@@ -184,29 +183,26 @@ public enum ValueType {
184183 BINARY
185184 }
186185
187- public interface KeyEntry {
186+ public abstract static class KeyEntry {
188187
189- String key ();
190-
191- default void writeTo (StreamOutput out ) throws IOException {
188+ private final String key ;
192189
190+ KeyEntry (String key ) {
191+ this .key = key ;
193192 }
194193
194+ public String key () {
195+ return key ;
196+ }
195197 }
196198
197- public static class ObjectEntry implements KeyEntry {
199+ public static class ObjectEntry extends KeyEntry {
198200
199- private final String key ;
200201 public int fieldCount = 0 ;
201202 private Map <String , Type > mutationMap = null ;
202203
203204 public ObjectEntry (String key ) {
204- this .key = key ;
205- }
206-
207- @ Override
208- public String key () {
209- return key ;
205+ super (key );
210206 }
211207
212208 public boolean hasMutations () {
@@ -215,23 +211,17 @@ public boolean hasMutations() {
215211
216212 @ Override
217213 public String toString () {
218- return "ObjectEntry{" + "key='" + key + '\'' + ", fieldCount=" + fieldCount + ", hasMutations=" + hasMutations () + '}' ;
214+ return "ObjectEntry{" + "key='" + key () + '\'' + ", fieldCount=" + fieldCount + ", hasMutations=" + hasMutations () + '}' ;
219215 }
220216 }
221217
222- public static class ArrayEntry implements KeyEntry {
218+ public static class ArrayEntry extends KeyEntry {
223219
224- private final String key ;
225220 public int elementCount = 0 ;
226221 private List <Type > mutationArray = null ;
227222
228223 public ArrayEntry (String key ) {
229- this .key = key ;
230- }
231-
232- @ Override
233- public String key () {
234- return key ;
224+ super (key );
235225 }
236226
237227 public boolean hasMutations () {
@@ -240,27 +230,21 @@ public boolean hasMutations() {
240230
241231 @ Override
242232 public String toString () {
243- return "ArrayEntry{" + "key='" + key + '\'' + ", elementCount=" + elementCount + ", hasMutations=" + hasMutations () + '}' ;
233+ return "ArrayEntry{" + "key='" + key () + '\'' + ", elementCount=" + elementCount + ", hasMutations=" + hasMutations () + '}' ;
244234 }
245235 }
246236
247- public static class FieldEntry implements KeyEntry {
248- public final String key ;
237+ public static class FieldEntry extends KeyEntry {
249238 public final Type type ;
250239
251240 public FieldEntry (String key , Type type ) {
252- this . key = key ;
241+ super ( key ) ;
253242 this .type = type ;
254243 }
255244
256- @ Override
257- public String key () {
258- return key ;
259- }
260-
261245 @ Override
262246 public String toString () {
263- return "FieldEntry{" + "key='" + key + '\'' + ", type=" + type + '}' ;
247+ return "FieldEntry{" + "key='" + key () + '\'' + ", type=" + type + '}' ;
264248 }
265249 }
266250
@@ -397,7 +381,7 @@ private void ensureMaterializedMap() {
397381 for (int i = 0 ; i < objEntry .fieldCount ; i ++) {
398382 KeyEntry entry = keyArray .get (currentIndex );
399383 if (entry instanceof FieldEntry fieldEntry ) {
400- materializedMap .put (fieldEntry .key , fieldEntry .type );
384+ materializedMap .put (fieldEntry .key () , fieldEntry .type );
401385 currentIndex ++;
402386 } else {
403387 if (entry instanceof ObjectEntry ) {
@@ -1056,23 +1040,4 @@ private static void flattenArray(ESONArray arr, String arrayFieldName, List<KeyE
10561040 newArrEntry .elementCount = elementCount ;
10571041 }
10581042 }
1059-
1060- public void writeToStream (ESONObject object , StreamOutput out ) throws IOException {
1061- out .writeByte ((byte ) 'E' );
1062- out .writeByte ((byte ) 'S' );
1063- out .writeByte ((byte ) 'O' );
1064- out .writeByte ((byte ) 'N' );
1065- // TODO: How to write size
1066- // TODO: Assert flattened or support transition to flattened
1067- for (KeyEntry entry : object .getKeyArray ()) {
1068- if (entry instanceof ObjectEntry ) {
1069-
1070- } else if (entry instanceof ArrayEntry ) {
1071-
1072- } else {
1073-
1074- }
1075- entry .writeTo (out );
1076- }
1077- }
10781043}
0 commit comments