01: /*
02: * CaseInsensitiveComparator.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.util;
13:
14: import java.util.Comparator;
15: import workbench.util.StringUtil;
16:
17: /**
18: * A case-insensitive Comparator for String which
19: * can handle null values as well (as opposed to String.CASE_INSENSITIVE_ORDER)
20: *
21: * @author support@sql-workbench.net
22: */
23: public class CaseInsensitiveComparator implements Comparator<String> {
24: /**
25: * Compares to two strings.
26: * null values are "sorted" after non-null values.
27: * i.e. compare(null, "something") returns -1
28: * and compare("something", null) returns 1
29: *
30: * @param value1 the first String, maybe null
31: * @param value2 the second String, maybe null
32: * @return 0 if both are null or compareToIgnoreCase() returns 0
33: * @see workbench.util.StringUtil#compareStrings(String, String, boolean);
34: */
35: public int compare(String value1, String value2) {
36: return StringUtil.compareStrings(value1, value2, true);
37: }
38: }
|