ctubbsii commented on code in PR #5876:
URL: https://github.com/apache/accumulo/pull/5876#discussion_r2342002451
##########
core/src/main/java/org/apache/accumulo/core/clientImpl/TabletAvailabilityUtil.java:
##########
@@ -25,55 +25,37 @@
public class TabletAvailabilityUtil {
public static TabletAvailability fromThrift(TTabletAvailability
tAvailability) {
- switch (tAvailability) {
- case HOSTED:
- return TabletAvailability.HOSTED;
- case UNHOSTED:
- return TabletAvailability.UNHOSTED;
- case ONDEMAND:
- return TabletAvailability.ONDEMAND;
- default:
- throw new IllegalArgumentException("Unhandled value for TAvailability:
" + tAvailability);
- }
+ return switch (tAvailability) {
+ case HOSTED -> TabletAvailability.HOSTED;
+ case UNHOSTED -> TabletAvailability.UNHOSTED;
+ case ONDEMAND -> TabletAvailability.ONDEMAND;
+ };
Review Comment:
These lost a default case. What happens if the value is null or some other
enum (if the code evolves)?
##########
core/src/main/java/org/apache/accumulo/core/file/rfile/bcfile/Utils.java:
##########
@@ -185,41 +185,25 @@ public static long readVLong(DataInput in) throws
IOException {
return firstByte;
}
- switch ((firstByte + 128) / 8) {
- case 11:
- case 10:
- case 9:
- case 8:
- case 7:
- return ((firstByte + 52L) << 8) | in.readUnsignedByte();
- case 6:
- case 5:
- case 4:
- case 3:
- return ((firstByte + 88L) << 16) | in.readUnsignedShort();
- case 2:
- case 1:
- return ((firstByte + 112L) << 24) | (in.readUnsignedShort() << 8) |
in.readUnsignedByte();
- case 0:
+ return switch ((firstByte + 128) / 8) {
+ case 11, 10, 9, 8, 7 -> ((firstByte + 52L) << 8) | in.readUnsignedByte();
+ case 6, 5, 4, 3 -> ((firstByte + 88L) << 16) | in.readUnsignedShort();
+ case 2, 1 ->
+ ((firstByte + 112L) << 24) | (in.readUnsignedShort() << 8) |
in.readUnsignedByte();
+ case 0 -> {
int len = firstByte + 129;
- switch (len) {
- case 4:
- return in.readInt();
- case 5:
- return ((long) in.readInt()) << 8 | in.readUnsignedByte();
- case 6:
- return ((long) in.readInt()) << 16 | in.readUnsignedShort();
- case 7:
- return ((long) in.readInt()) << 24 | (in.readUnsignedShort() << 8)
- | in.readUnsignedByte();
- case 8:
- return in.readLong();
- default:
- throw new IOException("Corrupted VLong encoding");
- }
- default:
- throw new IllegalStateException("Internal error");
- }
+ yield switch (len) {
Review Comment:
yield on nested switch statements is a bit confusing to me still, and less
readable than what was there before... but the brevity of the other lines make
it worth it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]