@Test public void testCollation() { Comparator<Object> c = Constant.getComparator("es", true); List<String> vals = Arrays.asList("ñ", "n", "o"); Collections.sort(vals, c); assertEquals("ñ", vals.get(1)); assertEquals(0, c.compare("a ", "a")); }
static Comparator<Object> getComparator(String localeString, final boolean padSpace) { if (localeString == null) { return getComparator(padSpace); } String[] parts = localeString.split("_"); Locale locale = null; if (parts.length == 1) { locale = new Locale(parts[0]); } else if (parts.length == 2) { locale = new Locale(parts[0], parts[1]); } else if (parts.length == 3) { locale = new Locale(parts[0], parts[1], parts[2]); } else { LogManager.logError(LogConstants.CTX_DQP, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30564, localeString)); return getComparator(padSpace); } final Collator c = Collator.getInstance(locale); LogManager.logError(LogConstants.CTX_DQP, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30565, locale)); return new Comparator<Object>() { @Override public int compare(Object o1, Object o2) { Class<?> clazz = o1.getClass(); if (clazz == String.class) { String s1 = (String)o1; String s2 = (String)o2; if (padSpace) { s1 = FunctionMethods.rightTrim(s1, ' ', false); s2 = FunctionMethods.rightTrim(s2, ' ', false); } return c.compare(s1, s2); } return ((Comparable<Object>)o1).compareTo(o2); } }; }
Constant implements Expression, Comparable<Constant> { static Comparator<Object> getComparator(String localeString, final boolean padSpace) { if (localeString == null) { return getComparator(padSpace); } String[] parts = localeString.split("_"); Locale locale = null; if (parts.length == 1) { locale = new Locale(parts[0]); } else if (parts.length == 2) { locale = new Locale(parts[0], parts[1]); } else if (parts.length == 3) { locale = new Locale(parts[0], parts[1], parts[2]); } else { LogManager.logError(LogConstants.CTX_DQP, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30564, localeString)); return getComparator(padSpace); } final Collator c = Collator.getInstance(locale); LogManager.logError(LogConstants.CTX_DQP, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30565, locale)); return new Comparator<Object>() { @Override public int compare(Object o1, Object o2) { Class<?> clazz = o1.getClass(); if (clazz == String.class) { String s1 = (String)o1; String s2 = (String)o2; if (padSpace) { s1 = FunctionMethods.rightTrim(s1, ' ', false); s2 = FunctionMethods.rightTrim(s2, ' ', false); } return c.compare(s1, s2); } return ((Comparable<Object>)o1).compareTo(o2); } }; } }
Constant implements Expression, Comparable<Constant> { static Comparator<Object> getComparator(String localeString, final boolean padSpace) { if (localeString == null) { return getComparator(padSpace); } String[] parts = localeString.split("_"); Locale locale = null; if (parts.length == 1) { locale = new Locale(parts[0]); } else if (parts.length == 2) { locale = new Locale(parts[0], parts[1]); } else if (parts.length == 3) { locale = new Locale(parts[0], parts[1], parts[2]); } else { LogManager.logError(LogConstants.CTX_DQP, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30564, localeString)); return getComparator(padSpace); } final Collator c = Collator.getInstance(locale); LogManager.logError(LogConstants.CTX_DQP, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30565, locale)); return new Comparator<Object>() { @Override public int compare(Object o1, Object o2) { Class<?> clazz = o1.getClass(); if (clazz == String.class) { String s1 = (String)o1; String s2 = (String)o2; if (padSpace) { s1 = FunctionMethods.rightTrim(s1, ' ', false); s2 = FunctionMethods.rightTrim(s2, ' ', false); } return c.compare(s1, s2); } return ((Comparable<Object>)o1).compareTo(o2); } }; } Constant(Object value, Class<?> type);  Constant(Object value); }
Constant implements Expression, Comparable<Constant> { static Comparator<Object> getComparator(String localeString, final boolean padSpace) { if (localeString == null) { return getComparator(padSpace); } String[] parts = localeString.split("_"); Locale locale = null; if (parts.length == 1) { locale = new Locale(parts[0]); } else if (parts.length == 2) { locale = new Locale(parts[0], parts[1]); } else if (parts.length == 3) { locale = new Locale(parts[0], parts[1], parts[2]); } else { LogManager.logError(LogConstants.CTX_DQP, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30564, localeString)); return getComparator(padSpace); } final Collator c = Collator.getInstance(locale); LogManager.logError(LogConstants.CTX_DQP, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30565, locale)); return new Comparator<Object>() { @Override public int compare(Object o1, Object o2) { Class<?> clazz = o1.getClass(); if (clazz == String.class) { String s1 = (String)o1; String s2 = (String)o2; if (padSpace) { s1 = FunctionMethods.rightTrim(s1, ' ', false); s2 = FunctionMethods.rightTrim(s2, ' ', false); } return c.compare(s1, s2); } return ((Comparable<Object>)o1).compareTo(o2); } }; } Constant(Object value, Class<?> type);  Constant(Object value); Class<?> getType(); void setType(Class<?> type); Object getValue(); boolean isNull(); void setMultiValued(List<?> value); boolean isMultiValued(); void acceptVisitor(LanguageVisitor visitor); boolean equals(Object obj); int hashCode(); Object clone(); String toString(); @Override int compareTo(Constant o); boolean isBindEligible(); void setBindEligible(boolean bindEligible); }
Constant implements Expression, Comparable<Constant> { static Comparator<Object> getComparator(String localeString, final boolean padSpace) { if (localeString == null) { return getComparator(padSpace); } String[] parts = localeString.split("_"); Locale locale = null; if (parts.length == 1) { locale = new Locale(parts[0]); } else if (parts.length == 2) { locale = new Locale(parts[0], parts[1]); } else if (parts.length == 3) { locale = new Locale(parts[0], parts[1], parts[2]); } else { LogManager.logError(LogConstants.CTX_DQP, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30564, localeString)); return getComparator(padSpace); } final Collator c = Collator.getInstance(locale); LogManager.logError(LogConstants.CTX_DQP, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30565, locale)); return new Comparator<Object>() { @Override public int compare(Object o1, Object o2) { Class<?> clazz = o1.getClass(); if (clazz == String.class) { String s1 = (String)o1; String s2 = (String)o2; if (padSpace) { s1 = FunctionMethods.rightTrim(s1, ' ', false); s2 = FunctionMethods.rightTrim(s2, ' ', false); } return c.compare(s1, s2); } return ((Comparable<Object>)o1).compareTo(o2); } }; } Constant(Object value, Class<?> type);  Constant(Object value); Class<?> getType(); void setType(Class<?> type); Object getValue(); boolean isNull(); void setMultiValued(List<?> value); boolean isMultiValued(); void acceptVisitor(LanguageVisitor visitor); boolean equals(Object obj); int hashCode(); Object clone(); String toString(); @Override int compareTo(Constant o); boolean isBindEligible(); void setBindEligible(boolean bindEligible); static final Constant NULL_CONSTANT; static final Comparator<Object> COMPARATOR; }