RESOLVED - task 202: Sort text with accents
http://code.google.com/p/google-refine/issues/detail?id=202 git-svn-id: http://google-refine.googlecode.com/svn/trunk@1951 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
dda74792bc
commit
209f157656
@ -33,6 +33,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
package com.google.refine.sorting;
|
||||
|
||||
import java.text.Collator;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
@ -41,6 +43,17 @@ import com.google.refine.model.Project;
|
||||
|
||||
public class StringCriterion extends Criterion {
|
||||
public boolean caseSensitive;
|
||||
Collator collator;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public StringCriterion() {
|
||||
super();
|
||||
collator = Collator.getInstance();
|
||||
collator.setDecomposition(Collator.FULL_DECOMPOSITION);
|
||||
collator.setStrength(Collator.SECONDARY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeFromJSON(Project project, JSONObject obj) throws JSONException {
|
||||
@ -48,6 +61,7 @@ public class StringCriterion extends Criterion {
|
||||
|
||||
if (obj.has("caseSensitive") && !obj.isNull("caseSensitive")) {
|
||||
caseSensitive = obj.getBoolean("caseSensitive");
|
||||
collator.setStrength(Collator.IDENTICAL);
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,11 +76,7 @@ public class StringCriterion extends Criterion {
|
||||
|
||||
@Override
|
||||
public int compareKeys(Object key1, Object key2) {
|
||||
if (StringCriterion.this.caseSensitive) {
|
||||
return ((String) key1).compareTo((String) key2);
|
||||
} else {
|
||||
return ((String) key1).compareToIgnoreCase((String) key2);
|
||||
}
|
||||
return collator.compare(key1, key2);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user