Skip to content

Commit c96953b

Browse files
Code Improvement
Signed-off-by: Prudhvi Godithi <[email protected]>
1 parent efc3e5d commit c96953b

File tree

1 file changed

+28
-50
lines changed
  • server/src/main/java/org/opensearch/common/lucene

1 file changed

+28
-50
lines changed

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

Lines changed: 28 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -358,62 +358,40 @@ public static FieldDoc readFieldDoc(StreamInput in) throws IOException {
358358
Comparable[] cFields = new Comparable[in.readVInt()];
359359
for (int j = 0; j < cFields.length; j++) {
360360
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-
}
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+
};
386375
}
387376
return new FieldDoc(in.readVInt(), in.readFloat(), cFields);
388377
}
389378

390379
public static Comparable readSortValue(StreamInput in) throws IOException {
391380
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-
}
381+
return switch (type) {
382+
case 0 -> null;
383+
case 1 -> in.readString();
384+
case 2 -> in.readInt();
385+
case 3 -> in.readLong();
386+
case 4 -> in.readFloat();
387+
case 5 -> in.readDouble();
388+
case 6 -> in.readByte();
389+
case 7 -> in.readShort();
390+
case 8 -> in.readBoolean();
391+
case 9 -> in.readBytesRef();
392+
case 10 -> new BigInteger(in.readString());
393+
default -> throw new IOException("Can't match type [" + type + "]");
394+
};
417395
}
418396

419397
public static ScoreDoc readScoreDoc(StreamInput in) throws IOException {

0 commit comments

Comments
 (0)