KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > store > SizeComparator


1 /*
2  * Created on May 26, 2004
3  */

4 package com.openedit.store;
5
6 import java.util.ArrayList JavaDoc;
7 import java.util.Comparator JavaDoc;
8 import java.util.List JavaDoc;
9
10 /**
11  * @author cburkey
12  *
13  */

14 public class SizeComparator implements Comparator JavaDoc {
15     protected List JavaDoc fieldSortedSizes;
16     
17     /* (non-javadoc)
18      * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
19      */

20     public int compare(Object JavaDoc in01, Object JavaDoc in02) {
21         String JavaDoc first = (String JavaDoc)in01;
22         String JavaDoc second = (String JavaDoc)in02;
23         int firstIndex = getSortedSizes().indexOf(first);
24         int secondIndex = getSortedSizes().indexOf(second);
25         if ( firstIndex == secondIndex)
26         {
27             return 0;
28         }
29         if ( firstIndex > secondIndex)
30         {
31             return 1;
32         }
33         return -1;
34     }
35
36     public List JavaDoc getSortedSizes() {
37         if (fieldSortedSizes == null) {
38             fieldSortedSizes = new ArrayList JavaDoc();
39             fieldSortedSizes.add("P");
40             fieldSortedSizes.add("NB");
41             fieldSortedSizes.add("0M");
42             fieldSortedSizes.add("3M");
43             fieldSortedSizes.add("6M");
44             fieldSortedSizes.add("9M");
45             fieldSortedSizes.add("12M");
46             fieldSortedSizes.add("18M");
47             fieldSortedSizes.add("24M");
48             fieldSortedSizes.add("2T");
49             fieldSortedSizes.add("3T");
50             fieldSortedSizes.add("4T");
51             fieldSortedSizes.add("4");
52             fieldSortedSizes.add("5");
53             fieldSortedSizes.add("6");
54             fieldSortedSizes.add("6X");
55             fieldSortedSizes.add("7");
56             fieldSortedSizes.add("8");
57             fieldSortedSizes.add("10");
58             fieldSortedSizes.add("12");
59             fieldSortedSizes.add("14");
60             fieldSortedSizes.add("16");
61             fieldSortedSizes.add("N/A");
62
63         }
64         return fieldSortedSizes;
65     }
66     public void setSortedSizes(List JavaDoc inSortedSizes) {
67         fieldSortedSizes = inSortedSizes;
68     }
69 }
70
Popular Tags