import
java.util.Comparator;
public
class CountyDTO {
private
String
state;
private
String
country;
public
void setState(String state) {
this
.
state = state;
}
public
void setCountry(String country) {
this
.
country = country;
}
public
String getState() {
return
state;
}
public
String getCountry() {
return
country;
}
/**
*
@author BM54284
* Comparater for sorting the States for Task 2
*/
public
static enum CountyComparator
implements Comparator<CountyDTO> {
STATE_SORT
{
public
int compare(CountyDTO o1, CountyDTO o2) {
if
((
null != o1 &&
null != o1.getState())
&& (null
!= o2 &&
null != o2.getState())) {
return
o1.getState().compareTo(o2.getState());
} else
{
return
0;
}
}
},
COUNTRY_SORT
{
public
int compare(CountyDTO o1, CountyDTO o2) {
if
((
null != o1 &&
null != o1.getCountry())
&& (null
!= o2 &&
null != o2.getCountry())) {
return
o1.getCountry().compareToIgnoreCase(o2.getCountry());
} else
{
return
0;
}
}
};
public
static Comparator<CountyDTO> getComparator(
final
CountyComparator... multipleOptions) {
return
new Comparator<CountyDTO>() {
public
int compare(CountyDTO o1, CountyDTO o2) {
for
(CountyComparator option : multipleOptions) {
int
result = option.compare(o1, o2);
if
(result != 0) {
return
result;
}
}
return
0;
}
};
}
}
}
//Call to that comparater
List<CountyDTO> contryandstate = getCountyFinder().getState();
contryandstate.addAll(getAdditionalCounty());
Collections.
sort(contryandstate, CountyComparator.
getComparator(CountyComparator.
COUNTRY_SORT
,CountyComparator.
STATE_SORT));