Skip to content

Commit 8af6b01

Browse files
Code Improvement with a new method
Signed-off-by: Prudhvi Godithi <[email protected]>
1 parent c96953b commit 8af6b01

File tree

1 file changed

+12
-15
lines changed
  • server/src/main/java/org/opensearch/common/lucene

1 file changed

+12
-15
lines changed

server/src/main/java/org/opensearch/common/lucene/Lucene.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -357,26 +357,23 @@ 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-
cFields[j] = switch (type) {
362-
case 0 -> null;
363-
case 1 -> in.readString();
364-
case 2 -> in.readInt();
365-
case 3 -> in.readLong();
366-
case 4 -> in.readFloat();
367-
case 5 -> in.readDouble();
368-
case 6 -> in.readByte();
369-
case 7 -> in.readShort();
370-
case 8 -> in.readBoolean();
371-
case 9 -> in.readBytesRef();
372-
case 10 -> new BigInteger(in.readString());
373-
default -> throw new IOException("Can't match type [" + type + "]");
374-
};
360+
cFields[j] = readTypedValue(in);
375361
}
376362
return new FieldDoc(in.readVInt(), in.readFloat(), cFields);
377363
}
378364

379365
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 {
380377
byte type = in.readByte();
381378
return switch (type) {
382379
case 0 -> null;

0 commit comments

Comments
 (0)