KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > sql99 > ddl > descriptors > StringArrayComparator


1 package com.daffodilwoods.daffodildb.server.sql99.ddl.descriptors;
2
3 import java.util.*;
4
5 public class StringArrayComparator implements Comparator {
6
7    public StringArrayComparator() {
8    }
9
10    public int compare(Object JavaDoc key1, Object JavaDoc key2) {
11       String JavaDoc[] values1 = (String JavaDoc[]) key1;
12       String JavaDoc[] values2 = (String JavaDoc[]) key2;
13       if (values1 == null && values2 == null) {
14          return 0;
15       }
16       if (values1 == null && values2 != null) {
17          return -1;
18       }
19       if (values2 == null && values1 != null) {
20          return 1;
21       }
22       int len1 = values1.length;
23       int len2 = values2.length;
24       int len = len1 < len2 ? len1 : len2;
25       int comp = 0;
26       for (int i = 0; i < len; i++) {
27          comp = values1[i].compareToIgnoreCase(values2[i]);
28          if (comp != 0) {
29             return comp;
30          }
31       }
32       return len1 - len2;
33
34    }
35
36 }
37
Popular Tags