Im totaly new to java programing, and I have been stuck with this problem for 2 weeks now! Im not really sure how to even describe the problem, so I've added the whole code basicly. What I want to do is basicly sort the li.Poeng by value.
String getYear = yearFrom.getSelectedItem().toString();
String leFile = "http://www.it.hiof.no/~borres/commondata/fotballstatistikk/CSV/data" + getYear + ".txt".trim();
List<Functions> filData = Functions.setupList(leFile);
String fra = yearFrom.getSelectedItem().toString() + ":" + monthFrom.getSelectedItem().toString() + ":" + dayFrom.getSelectedItem().toString();
String til = yearTo.getSelectedItem().toString() + ":" + monthTo.getSelectedItem().toString() + ":" + dayTo.getSelectedItem().toString();
String[] fraDat = fra.split(":");
int fraDag = Integer.parseInt(fraDat[2]);
int fraMaan = Integer.parseInt(fraDat[1]);
int fraYear = Integer.parseInt(fraDat[0]);
int fraDato = fraYear * 10000 + fraMaan * 100 + fraDag;
String[] tilDat = til.split(":");
int tilDag = Integer.parseInt(tilDat[2]);
int tilMaan = Integer.parseInt(tilDat[1]);
int tilYear = Integer.parseInt(tilDat[0]);
int tilDato = tilYear * 10000 + tilMaan * 100 + tilDag;
HashMap<String, TabellLinje> tabell = new HashMap<>();
//----------------------------------------------------------------------------------------------
for (int i = 0; i < filData.size(); i++) {
String[] kampdat = filData.get(i).getdato().split(":");
int dag = Integer.parseInt(kampdat[2]);
int maan = Integer.parseInt(kampdat[1]);
int year = Integer.parseInt(kampdat[0]);
int filDato = year * 10000 + maan * 100 + dag;
if (fraDato < tilDato) {
if (tilDato >= filDato) {
// Calculate points
int hMaal = Integer.parseInt(filData.get(i).gethMaal());
int bMaal = Integer.parseInt(filData.get(i).getbMaal());
String hLag = filData.get(i).gethLag();
String bLag = filData.get(i).getbLag();
TabellLinje hjemmelag;
TabellLinje bortelag;
if (tabell.containsKey(hLag))
{
hjemmelag = tabell.get(hLag);
} else {
hjemmelag = new TabellLinje();
hjemmelag.Navn = hLag;
tabell.put(hjemmelag.Navn, hjemmelag);
}
if (tabell.containsKey(bLag)) {
bortelag = tabell.get(bLag);
} else {
bortelag = new TabellLinje();
bortelag.Navn = bLag;
tabell.put(bortelag.Navn, bortelag);
}
if (hMaal > bMaal) {
hjemmelag.Poeng += 3;
hjemmelag.Matches++;
bortelag.Matches++;
} else if (hMaal == bMaal) {
hjemmelag.Poeng++;
bortelag.Poeng++;
hjemmelag.Matches++;
bortelag.Matches++;
} else if (bMaal > hMaal) {
bortelag.Poeng += 3;
hjemmelag.Matches++;
bortelag.Matches++;
}
hjemmelag.GoalsAgainst += bMaal;
hjemmelag.GoalsFor += hMaal;
bortelag.GoalsAgainst += hMaal;
bortelag.GoalsFor += bMaal;
}
}
}
// Output to GUI
textArea.removeAll();
List<TabellLinje> tabellListe = new ArrayList(tabell.values());
for (int i = 0; i < tabellListe.size(); i++) {
TabellLinje li = tabellListe.get(i);
textArea.add(li.Navn + " " + li.GoalsFor + " " + li.GoalsAgainst + " " + li.Poeng + " " + li.Matches);
}
}
The code work the way it should, expect i need an additional code to sort the li.Poeng variable wich is an object in the TabellLinje list.
Sorry for horrible description, and for messy code. Gratitude to the white knight who could help me out! :D