BAEL-4323: Rename getters to follow Java Beans convention (#9569)
This commit is contained in:
parent
ef41e8caa1
commit
96e48fed81
@ -22,15 +22,15 @@ public class PersonWithEquals {
|
||||
this.birthDate = birthDate;
|
||||
}
|
||||
|
||||
public String firstName() {
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public String lastName() {
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public LocalDate birthDate() {
|
||||
public LocalDate getBirthDate() {
|
||||
return birthDate;
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,18 @@ public class PersonWithEqualsAndComparable implements Comparable<PersonWithEqual
|
||||
this.birthDate = birthDate;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public LocalDate getBirthDate() {
|
||||
return birthDate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
@ -23,15 +23,15 @@ public class PersonWithEqualsAndComparableUsingComparator implements Comparable<
|
||||
this.birthDate = birthDate;
|
||||
}
|
||||
|
||||
public String firstName() {
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public String lastName() {
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public LocalDate birthDate() {
|
||||
public LocalDate getBirthDate() {
|
||||
return birthDate;
|
||||
}
|
||||
|
||||
@ -52,9 +52,9 @@ public class PersonWithEqualsAndComparableUsingComparator implements Comparable<
|
||||
|
||||
@Override
|
||||
public int compareTo(PersonWithEqualsAndComparableUsingComparator o) {
|
||||
return Comparator.comparing(PersonWithEqualsAndComparableUsingComparator::lastName)
|
||||
.thenComparing(PersonWithEqualsAndComparableUsingComparator::firstName)
|
||||
.thenComparing(PersonWithEqualsAndComparableUsingComparator::birthDate, Comparator.nullsLast(Comparator.naturalOrder()))
|
||||
return Comparator.comparing(PersonWithEqualsAndComparableUsingComparator::getLastName)
|
||||
.thenComparing(PersonWithEqualsAndComparableUsingComparator::getFirstName)
|
||||
.thenComparing(PersonWithEqualsAndComparableUsingComparator::getBirthDate, Comparator.nullsLast(Comparator.naturalOrder()))
|
||||
.compare(this, o);
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,18 @@ public class PersonWithEqualsAndWrongComparable implements Comparable<PersonWith
|
||||
this.birthDate = birthDate;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public LocalDate getBirthDate() {
|
||||
return birthDate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
@ -8,4 +8,12 @@ public class PersonWithoutEquals {
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ class ComparatorInterfaceUnitTest {
|
||||
Comparator<PersonWithEquals> compareByFirstNames = new Comparator<PersonWithEquals>() {
|
||||
@Override
|
||||
public int compare(PersonWithEquals o1, PersonWithEquals o2) {
|
||||
return o1.firstName().compareTo(o2.firstName());
|
||||
return o1.getFirstName().compareTo(o2.getFirstName());
|
||||
}
|
||||
};
|
||||
people.sort(compareByFirstNames);
|
||||
@ -37,7 +37,7 @@ class ComparatorInterfaceUnitTest {
|
||||
people.add(joe);
|
||||
people.add(allan);
|
||||
|
||||
Comparator<PersonWithEquals> compareByFirstNames = Comparator.comparing(PersonWithEquals::firstName);
|
||||
Comparator<PersonWithEquals> compareByFirstNames = Comparator.comparing(PersonWithEquals::getFirstName);
|
||||
people.sort(compareByFirstNames);
|
||||
|
||||
assertThat(people).containsExactly(allan, joe);
|
||||
|
@ -63,8 +63,8 @@ class GuavaUnitTest {
|
||||
PersonWithEquals joe = new PersonWithEquals("Joe", "Portman");
|
||||
|
||||
int comparisonResult = ComparisonChain.start()
|
||||
.compare(natalie.lastName(), joe.lastName())
|
||||
.compare(natalie.firstName(), joe.firstName())
|
||||
.compare(natalie.getLastName(), joe.getLastName())
|
||||
.compare(natalie.getFirstName(), joe.getFirstName())
|
||||
.result();
|
||||
|
||||
assertThat(comparisonResult).isPositive();
|
||||
|
Loading…
x
Reference in New Issue
Block a user