Created
December 2, 2016 14:21
-
-
Save rschumm/a9f77a0288132b010b7d9e418259e411 to your computer and use it in GitHub Desktop.
Java 8 Stream sort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void testSortAgentur() { | |
InputStream xml = this.getClass().getClassLoader().getResourceAsStream("devmodel/2/sfgsfgsfdg.XML"); | |
AgenturenType agenturenType = JAXB.unmarshal(xml, AgenturenType.class); | |
List<AgencyType> agenturenListe = agenturenType.getAgency(); | |
//Sortiert nach City, dann nach Typ umgekehrt | |
List<AgencyType> sortiert = agenturenListe.stream() | |
.sorted(Comparator.comparing(AgencyType::getAgencyType).reversed()) | |
.sorted(Comparator.comparing(AgencyType::getCity)) | |
.collect(Collectors.toList()); | |
assertEquals("Aadorf", sortiert.get(0).getCity()); | |
assertEquals("Aarau", sortiert.get(1).getCity()); | |
assertEquals("Aarau", sortiert.get(2).getCity()); | |
assertEquals("nummer1", sortiert.get(2).getAgencyID()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment