mirror of
https://github.com/apple/pkl.git
synced 2026-04-29 19:57:26 +02:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user