no właśnie, wydawało się ;]
jakieś pomysły jak takie coś zrobić?
wskazówki/cokolwiek ;p
wersja dla ludzi nielubiących tagów php
http://pastebin.com/pBFeGBj6
oczywiście implementuje interface
Kod PHP:
import java.util.List;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Collections;
class SortujWgDZrodla implements Comparator<Accounting>{
public int compare(Accounting x, Accounting y){
return x.zrodlo.compareTo(y.zrodlo);
}
}
class SortujWgDanych implements Comparator<Accounting>{
public int compare(Accounting x, Accounting y){
int wart1=x.przesyl;
int wart2=y.przesyl;
if(wart1<wart2) return -1;
if(wart1>wart2) return 1;
else return 0;
}
}
class Accounting implements AccountingInterface{
String zrodlo = new String();
String cel = new String();
int przesyl=0;
int sum=0;
List<String> acc=new ArrayList<String>();
List<Integer> acc2=new ArrayList<Integer>();
List<Accounting> acc3=new ArrayList<Accounting>();
Accounting() {}
public void count(String source, String destination, int amount){
zrodlo= source;
cel = destination;
przesyl= amount;
System.out.println("Zrodlo: "+zrodlo + " Cel "+ cel + " Ilosc " +przesyl);
acc.add(zrodlo);
acc2.add(przesyl);
acc3.add(new Accounting());
sum+=amount;
System.out.println("Przeslano w sumie: "+sum);
}
private void sortList(List<String> aItems){
Collections.sort(aItems, String.CASE_INSENSITIVE_ORDER);
}
public List<String> theMostActiveSources(int amount){
int wielkosc = amount;
sortList(acc);
List<String> small=acc.subList(0,wielkosc);
//sortList(small);
Collections.sort(acc2);
for(int i: acc2)
System.out.println(i);
return small;
}
//List<String> theMostActiveDestinations(int amount){}
}
class Start{
public static void main(String[] args){
List<Accounting> acc=new ArrayList<Accounting>();
Accounting o=new Accounting();
o.count( "adam","g1",1);
o.count("wacek","g2",1);
o.count("eka","g3",1);
o.count("robek","g3",4);
o.count("trup","g3",5);
o.count("yafud","g3",0);
o.count("ula","g3",1000);
o.count("iga","g3",6);
o.count("ola","g3",9);
System.out.println(o.theMostActiveSources(9));
for(Accounting dos:acc ) System.out.println(o);
}}
Zakładki