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