Use CollationKeys when sorting text. Fixes issue 738

This commit is contained in:
Tom Morris 2013-06-17 15:51:29 -04:00
parent 678375915a
commit b91fc8a2b1
2 changed files with 10 additions and 2 deletions

View File

@ -75,6 +75,13 @@ abstract public class Criterion {
} }
} }
// TODO: We'd like things to be more strongly typed a la the following, but
// it's too involved to change right now
// abstract public class Key implements Comparable<Key> {
// abstract public int compareTo(Key key);
// }
abstract public class KeyMaker { abstract public class KeyMaker {
public Object makeKey(Project project, Record record) { public Object makeKey(Project project, Record record) {
Object error = null; Object error = null;

View File

@ -33,6 +33,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.google.refine.sorting; package com.google.refine.sorting;
import java.text.CollationKey;
import java.text.Collator; import java.text.Collator;
import org.json.JSONException; import org.json.JSONException;
@ -71,12 +72,12 @@ public class StringCriterion extends Criterion {
@Override @Override
protected Object makeKey(Object value) { protected Object makeKey(Object value) {
return (ExpressionUtils.isNonBlankData(value) && !(value instanceof String)) ? return (ExpressionUtils.isNonBlankData(value) && !(value instanceof String)) ?
value.toString() : value; collator.getCollationKey(value.toString()) : value;
} }
@Override @Override
public int compareKeys(Object key1, Object key2) { public int compareKeys(Object key1, Object key2) {
return collator.compare(key1, key2); return ((CollationKey)key1).compareTo((CollationKey)key2);
} }
}; };
} }