@@ -357,63 +357,38 @@ public static TopDocsAndMaxScore readTopDocs(StreamInput in) throws IOException
357357 public static FieldDoc readFieldDoc (StreamInput in ) throws IOException {
358358 Comparable [] cFields = new Comparable [in .readVInt ()];
359359 for (int j = 0 ; j < cFields .length ; j ++) {
360- byte type = in .readByte ();
361- if (type == 0 ) {
362- cFields [j ] = null ;
363- } else if (type == 1 ) {
364- cFields [j ] = in .readString ();
365- } else if (type == 2 ) {
366- cFields [j ] = in .readInt ();
367- } else if (type == 3 ) {
368- cFields [j ] = in .readLong ();
369- } else if (type == 4 ) {
370- cFields [j ] = in .readFloat ();
371- } else if (type == 5 ) {
372- cFields [j ] = in .readDouble ();
373- } else if (type == 6 ) {
374- cFields [j ] = in .readByte ();
375- } else if (type == 7 ) {
376- cFields [j ] = in .readShort ();
377- } else if (type == 8 ) {
378- cFields [j ] = in .readBoolean ();
379- } else if (type == 9 ) {
380- cFields [j ] = in .readBytesRef ();
381- } else if (type == 10 ) {
382- cFields [j ] = new BigInteger (in .readString ());
383- } else {
384- throw new IOException ("Can't match type [" + type + "]" );
385- }
360+ cFields [j ] = readTypedValue (in );
386361 }
387362 return new FieldDoc (in .readVInt (), in .readFloat (), cFields );
388363 }
389364
390365 public static Comparable readSortValue (StreamInput in ) throws IOException {
366+ return readTypedValue (in );
367+ }
368+
369+ /**
370+ * Reads a typed value from the stream based on a type byte prefix.
371+ *
372+ * @param in the input stream
373+ * @return the deserialized Comparable value
374+ * @throws IOException if reading fails or type is unknown
375+ */
376+ private static Comparable readTypedValue (StreamInput in ) throws IOException {
391377 byte type = in .readByte ();
392- if (type == 0 ) {
393- return null ;
394- } else if (type == 1 ) {
395- return in .readString ();
396- } else if (type == 2 ) {
397- return in .readInt ();
398- } else if (type == 3 ) {
399- return in .readLong ();
400- } else if (type == 4 ) {
401- return in .readFloat ();
402- } else if (type == 5 ) {
403- return in .readDouble ();
404- } else if (type == 6 ) {
405- return in .readByte ();
406- } else if (type == 7 ) {
407- return in .readShort ();
408- } else if (type == 8 ) {
409- return in .readBoolean ();
410- } else if (type == 9 ) {
411- return in .readBytesRef ();
412- } else if (type == 10 ) {
413- return new BigInteger (in .readString ());
414- } else {
415- throw new IOException ("Can't match type [" + type + "]" );
416- }
378+ return switch (type ) {
379+ case 0 -> null ;
380+ case 1 -> in .readString ();
381+ case 2 -> in .readInt ();
382+ case 3 -> in .readLong ();
383+ case 4 -> in .readFloat ();
384+ case 5 -> in .readDouble ();
385+ case 6 -> in .readByte ();
386+ case 7 -> in .readShort ();
387+ case 8 -> in .readBoolean ();
388+ case 9 -> in .readBytesRef ();
389+ case 10 -> new BigInteger (in .readString ());
390+ default -> throw new IOException ("Can't match type [" + type + "]" );
391+ };
417392 }
418393
419394 public static ScoreDoc readScoreDoc (StreamInput in ) throws IOException {
0 commit comments