I turned it into a list...
But cant get the Collection.Sort good
this is the code:
package nl.wag.webarm.utils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import nl.wag.webarm.model.FactuurOnderdeel;
public class FactuurUtils {
public static void createFactuur (Set onderdelen){
if (onderdelen != null){
List onderdelenlijst = new ArrayList();
Iterator it = onderdelen.iterator();
while ( it.hasNext()){
FactuurOnderdeel fo = (FactuurOnderdeel) it.next();
onderdelenlijst.add(fo);
}
Collections.sort(onderdelenlijst,new OdComparator()); // this is where eclipse shows the warnings.. warnings are on the bottom of this post..
}
}
public class OdComparator implements Comparator{
public int compare(Object arg0, Object arg1) {
String s1 = ((FactuurOnderdeel) arg0).getId();
String s2 = ((FactuurOnderdeel) arg1).getId();
return s1.compareTo(s2);
}
}
}
And this is the warings eclipse gives:
Multiple markers at this line
- Type safety: The expression of type FactuurUtils.OdComparator needs unchecked
conversion to conform to Comparator<? super T>
- No enclosing instance of type FactuurUtils is accessible. Must qualify the allocation with
an enclosing instance of type FactuurUtils (e.g. x.new A() where x is an instance of FactuurUtils).
- Type safety: Unchecked invocation sort(List, Comparator) of the generic method sort
(List<T>, Comparator<? super T>) of type Collections
- Type safety: The expression of type List needs unchecked conversion to conform to
List<T>
> public static void createFactuur (Set<FactuurOnderdeel> onderdelen){
public static void createFactuur (Set onderdelen){
> if (onderdelen != null){
> List onderdelenlijst = new ArrayList();
List<FactuurOnderdeel> onderdelenlijst = new ArrayList<FactuurOnderdeel>(onderdelen);
and remove the iterator copy-loop following.
> public class OdComparator implements Comparator{
public static class OdComparator implements Comparator<FactuurOnderdeel>{
> public int compare(Object arg0, Object arg1) {
> String s1 = ((FactuurOnderdeel) arg0).getId();
> String s2 = ((FactuurOnderdeel) arg1).getId();
public int compare(FactuurOnderdeel arg0, FactuurOnderdeel arg1) {
String s1 = arg0.getId();
String s2 = arg1.getId();