1 import java
.util
.ArrayList
;
2 import java
.util
.Arrays
;
4 public class Origin
implements Comparable
<Origin
> {
5 private String continent
= "Unknown";
6 private String country
;
7 private String
[] continents
= {"Africa", "Americas", "Asia", "Europe", "Oceania"};
8 private String
[][] content2DArray
= {
10 {"United States of America", "Brasil", "Mexico"}, /* Americas */
12 {"France", "Germany", "United Kingdom", "Belgium", "Norway"}, /* Europe */
13 {"Australia"} /* Oceania */
19 Origin(String country
) {
21 setContinent(this.getContinentFromCountry(country
));
24 public String
getContinent() {
28 public void setContinent(String continent
) {
29 this.continent
= continent
;
32 public String
getCountry() {
36 public void setCountry(String country
) {
37 this.country
= country
;
40 public String
[] getCountriesArray() {
41 ArrayList
<String
> stringArrayList
= new ArrayList
<>();
42 for (int i
= 0; i
< this.content2DArray
.length
; i
++) {
43 for (int j
= 0; j
< this.content2DArray
[i
].length
; j
++) {
44 stringArrayList
.add(this.content2DArray
[i
][j
]);
47 stringArrayList
.sort(String
::compareToIgnoreCase
);
48 String
[] rtArray
= new String
[stringArrayList
.size()];
49 return stringArrayList
.toArray(rtArray
);
52 public String
getContinentFromCountry(String country
) {
53 int continentKey
= -1;
54 for (int i
= 0; i
< content2DArray
.length
; i
++) {
55 if (Arrays
.asList(content2DArray
[i
]).indexOf(country
) != -1) {
59 if (continentKey
!= -1)
60 return this.continents
[continentKey
];
66 public int compareTo(Origin origin
) {