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.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
public class Konto implements Serializable { public class Konto implements Serializable, Comparable{
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@ -83,5 +83,13 @@ public class Konto implements Serializable {
return stand; 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.io.IOException;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.TreeSet;
import de.hs_mannheim.informatik.bank.domain.Bank; import de.hs_mannheim.informatik.bank.domain.Bank;
import de.hs_mannheim.informatik.bank.domain.Depot; import de.hs_mannheim.informatik.bank.domain.Depot;
@ -61,12 +62,14 @@ public class Banksystem {
public String[] getKontenlisteForKunde(){ public String[] getKontenlisteForKunde(){
Collection<Konto> konten = bank.getKundenKonto(currentKunde); Collection<Konto> konten = bank.getKundenKonto(currentKunde);
String[] liste = new String[konten.size()];
int i = 0; TreeSet<Konto> ts = new TreeSet<Konto>(konten);
for (Konto k : konten) {
liste[i++] = k.toString(); String[] liste = new String[konten.size()];
}
ts.stream().forEach(konto -> {
liste[ts.headSet(konto).size()] = konto.toString();
});
return liste; return liste;