Leverage basic Java 17 features (#451)

- Refactor code to use the following basic Java 17 features:
  - pattern matching for instanceof
  - @Serial annotation
  - switch expressions
  - enhanced switch statements
  - StringBuilder.isEmpty()
- Replace two switch statements with simpler if statements.
- Rename a few local variables.
This commit is contained in:
translatenix
2024-04-25 12:52:28 -07:00
committed by GitHub
parent 3ab9e4184e
commit a7c7e51180
142 changed files with 1333 additions and 1798 deletions

View File

@@ -91,9 +91,7 @@ public class PObjectToDataObjectJavaxInjectTest {
@Override
public boolean equals(@Nullable Object obj) {
if (this == obj) return true;
if (!(obj instanceof Person)) return false;
var other = (Person) obj;
if (!(obj instanceof Person other)) return false;
return name.equals(other.name)
&& age == other.age
&& hobbies.equals(other.hobbies)
@@ -118,9 +116,7 @@ public class PObjectToDataObjectJavaxInjectTest {
@Override
public boolean equals(@Nullable Object obj) {
if (this == obj) return true;
if (!(obj instanceof Address)) return false;
var other = (Address) obj;
if (!(obj instanceof Address other)) return false;
return street.equals(other.street) && zip == other.zip;
}
@@ -148,9 +144,7 @@ public class PObjectToDataObjectJavaxInjectTest {
@Override
public boolean equals(@Nullable Object obj) {
if (this == obj) return true;
if (!(obj instanceof Pair)) return false;
var other = (Pair<?, ?>) obj;
if (!(obj instanceof Pair<?, ?> other)) return false;
return first.equals(other.first) && second.equals(other.second);
}

View File

@@ -136,9 +136,7 @@ public class PObjectToDataObjectTest {
@Override
public boolean equals(@Nullable Object obj) {
if (this == obj) return true;
if (!(obj instanceof Person)) return false;
var other = (Person) obj;
if (!(obj instanceof Person other)) return false;
return name.equals(other.name)
&& age == other.age
&& hobbies.equals(other.hobbies)
@@ -168,9 +166,7 @@ public class PObjectToDataObjectTest {
@Override
public boolean equals(@Nullable Object obj) {
if (this == obj) return true;
if (!(obj instanceof PersonConstructoProperties)) return false;
var other = (PersonConstructoProperties) obj;
if (!(obj instanceof PersonConstructoProperties other)) return false;
return name.equals(other.name)
&& age == other.age
&& hobbies.equals(other.hobbies)
@@ -195,9 +191,7 @@ public class PObjectToDataObjectTest {
@Override
public boolean equals(@Nullable Object obj) {
if (this == obj) return true;
if (!(obj instanceof Address)) return false;
var other = (Address) obj;
if (!(obj instanceof Address other)) return false;
return street.equals(other.street) && zip == other.zip;
}
@@ -225,9 +219,7 @@ public class PObjectToDataObjectTest {
@Override
public boolean equals(@Nullable Object obj) {
if (this == obj) return true;
if (!(obj instanceof Pair)) return false;
var other = (Pair<?, ?>) obj;
if (!(obj instanceof Pair<?, ?> other)) return false;
return first.equals(other.first) && second.equals(other.second);
}

View File

@@ -29,9 +29,7 @@ public class Person {
@Override
public boolean equals(@Nullable Object obj) {
if (this == obj) return true;
if (!(obj instanceof Person)) return false;
var other = (Person) obj;
if (!(obj instanceof Person other)) return false;
return name.equals(other.name) && age == other.age;
}