funcionality that reads available cities and prints them prepared
This commit is contained in:
parent
f5ab4e64be
commit
bc5ea0bd76
31
src/main/java/model/CityNames.java
Normal file
31
src/main/java/model/CityNames.java
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package model;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
// WYKORZYSTANIE STRUMIENIA
|
||||||
|
public class CityNames {
|
||||||
|
public static void cityNamesRead(String filePath) {
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
|
try {
|
||||||
|
JsonNode jsonArray = objectMapper.readTree(new File(filePath));
|
||||||
|
|
||||||
|
List<String> cityNames = jsonArray
|
||||||
|
.findValuesAsText("name")
|
||||||
|
.stream()
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
System.out.println("Dostępne miasta:");
|
||||||
|
cityNames.forEach(System.out::println);
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user