1
2
3
4
5
6
7
8
9 package com.atlassian.core.ofbiz.comparators;
10
11 import org.ofbiz.core.entity.GenericValue;
12 import org.apache.log4j.Category;
13
14 public class OFBizFieldComparator implements java.util.Comparator
15 {
16 private static final Category log = Category.getInstance(OFBizFieldComparator.class);
17
18 String fieldname;
19
20 public OFBizFieldComparator(String fieldname)
21 {
22 this.fieldname = fieldname;
23 }
24
25 public int compare(Object o1, Object o2)
26 {
27 try
28 {
29 GenericValue i1 = (GenericValue) o1;
30 GenericValue i2 = (GenericValue) o2;
31
32 if (i1 == null && i2 == null)
33 return 0;
34 else if (i2 == null)
35 return -1;
36 else if (i1 == null)
37 return 1;
38
39 String s1 = i1.getString(fieldname);
40 String s2 = i2.getString(fieldname);
41
42 if (s1 == null && s2 == null)
43 return 0;
44 else if (s2 == null)
45 return -1;
46 else if (s1 == null)
47 return 1;
48 else
49 return s1.compareToIgnoreCase(s2);
50 }
51 catch (Exception e)
52 {
53 log.error("Exception: " + e, e);
54 }
55 return 0;
56 }
57 }