New: treeset & lambda

main
Caner 2022-12-05 15:38:23 +01:00
parent 9ad8c5760b
commit 2563d419e6
2 changed files with 17 additions and 6 deletions

View File

@ -3,7 +3,7 @@ package de.hs_mannheim.informatik.bank.domain;
import java.io.Serializable;
import java.util.ArrayList;
public class Konto implements Serializable {
public class Konto implements Serializable, Comparable{
private static final long serialVersionUID = 1L;
@ -83,5 +83,13 @@ public class Konto implements Serializable {
return stand;
}
@Override
public int compareTo(Object o) {
Konto k = (Konto) o;
return (int) (k.getKontostand() - this.getKontostand());
}
}

View File

@ -3,6 +3,7 @@ package de.hs_mannheim.informatik.bank.facade;
import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.TreeSet;
import de.hs_mannheim.informatik.bank.domain.Bank;
import de.hs_mannheim.informatik.bank.domain.Depot;
@ -61,12 +62,14 @@ public class Banksystem {
public String[] getKontenlisteForKunde(){
Collection<Konto> konten = bank.getKundenKonto(currentKunde);
String[] liste = new String[konten.size()];
int i = 0;
for (Konto k : konten) {
liste[i++] = k.toString();
}
TreeSet<Konto> ts = new TreeSet<Konto>(konten);
String[] liste = new String[konten.size()];
ts.stream().forEach(konto -> {
liste[ts.headSet(konto).size()] = konto.toString();
});
return liste;