Skip to content

Instantly share code, notes, and snippets.

@rschumm
Created December 2, 2016 14:21
Show Gist options
  • Save rschumm/a9f77a0288132b010b7d9e418259e411 to your computer and use it in GitHub Desktop.
Save rschumm/a9f77a0288132b010b7d9e418259e411 to your computer and use it in GitHub Desktop.
Java 8 Stream sort
@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