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);
TreeSet<Konto> ts = new TreeSet<Konto>(konten);
String[] liste = new String[konten.size()]; String[] liste = new String[konten.size()];
int i = 0; ts.stream().forEach(konto -> {
for (Konto k : konten) { liste[ts.headSet(konto).size()] = konto.toString();
liste[i++] = k.toString(); });
}
return liste; return liste;