Skip to content

Commit be7b2d3

Browse files
committed
begins with char and sorted by name
1 parent c512e96 commit be7b2d3

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

src/main/java/com/lambdaschool/countries/demo/CountryNameController.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.lambdaschool.countries.demo;
22

33
import org.springframework.web.bind.annotation.RequestMapping;
4+
import org.springframework.web.bind.annotation.RequestParam;
45
import org.springframework.web.bind.annotation.RestController;
56

67
import java.util.ArrayList;
@@ -9,8 +10,24 @@
910
@RequestMapping("/names")
1011

1112
public class CountryNameController {
13+
@RequestMapping("/begin")
14+
public ArrayList<Country> filteredCountry(@RequestParam(value="letter")String letter){
15+
ArrayList<Country> filtered = new ArrayList<>();
16+
for(Country a : CountriesApplication.countryList.countryList) {
17+
String name = a.getName();
18+
String firstLetter = "";
19+
firstLetter = String.valueOf(name.charAt(0));
20+
if(firstLetter.equals(letter.toUpperCase())){
21+
filtered.add(a);
22+
}
23+
}
24+
25+
return filtered;
26+
}
27+
28+
1229
@RequestMapping("/all")
13-
public ArrayList<Country> getCountryDetails() {
30+
public ArrayList<Country> getAllCountry() {
1431
CountriesApplication.countryList.countryList.sort((c1, c2)-> c1.getName().compareToIgnoreCase(c2.getName()));
1532
return CountriesApplication.countryList.countryList;
1633
}

0 commit comments

Comments
 (0)