Java Code Examples for java.text.RuleBasedCollator#compare()

The following examples show how to use java.text.RuleBasedCollator#compare() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FacadeUtils.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public int compare(Object o1, Object o2) {
	try{
		RuleBasedCollator r_collator= new RuleBasedCollator(((RuleBasedCollator)Collator.getInstance()).getRules().replaceAll("<'\u005f'", "<' '<'\u005f'"));
		return r_collator.compare(((EnrollmentRecord)o1).getUser().getSortName(),((EnrollmentRecord)o2).getUser().getSortName());
	}catch(ParseException e){
		  return Collator.getInstance().compare(((EnrollmentRecord)o1).getUser().getSortName(),((EnrollmentRecord)o2).getUser().getSortName());
	}
}
 
Example 2
Source File: FacadeUtils.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public int compare(Object o1, Object o2) {
try{
	RuleBasedCollator r_collator= new RuleBasedCollator(((RuleBasedCollator)Collator.getInstance()).getRules().replaceAll("<'\u005f'", "<' '<'\u005f'"));
	return r_collator.compare(((EnrollmentRecord)o1).getUser().getDisplayId(),((EnrollmentRecord)o2).getUser().getDisplayId());
}catch(ParseException e){
	  return Collator.getInstance().compare(((EnrollmentRecord)o1).getUser().getDisplayId(),((EnrollmentRecord)o2).getUser().getDisplayId());
}
     }
 
Example 3
Source File: QuestionPoolBean.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public int compare(Object o1, Object o2) {
 QuestionPoolFacade i1 = (QuestionPoolFacade)o1;
 QuestionPoolFacade i2 = (QuestionPoolFacade)o2;
 if (i1 == null && i2 != null) {
  return 1;
 }
 if (i2 == null && i1 != null) {
  return -1;
 }
 if (i2 == null && i1 == null) {
  return 0;
 }
 if (i1.getTitle() == null && i2.getTitle() != null) {
  return 1;
 }
 if (i2.getTitle() == null && i1.getTitle() != null) {
  return -1;
 }
 if (i2.getTitle() == null && i1.getTitle() == null) {
  return 0;
 }
 RuleBasedCollator collator_ini = (RuleBasedCollator)Collator.getInstance();
 try {
RuleBasedCollator collator= new RuleBasedCollator(collator_ini.getRules().replaceAll("<'\u005f'", "<' '<'\u005f'"));
return collator.compare(i1.getTitle(), i2.getTitle());
 } catch (ParseException e) {}
 return Collator.getInstance().compare(i1.getTitle(), i2.getTitle());
}
 
Example 4
Source File: SectionBean.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public int compare(Object o1, Object o2) {
 SelectItem i1 = (SelectItem)o1;
 SelectItem i2 = (SelectItem)o2;
try{
	RuleBasedCollator r_collator= new RuleBasedCollator(((RuleBasedCollator)Collator.getInstance()).getRules().replaceAll("<'\u005f'", "<' '<'\u005f'"));
	return r_collator.compare(i1.getLabel(), i2.getLabel());
}catch(ParseException e){
	  return Collator.getInstance().compare(i1.getLabel(),i2.getLabel());
}
}
 
Example 5
Source File: ItemAuthorBean.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public int compare(Object o1, Object o2) {
	SelectItem i1 = (SelectItem) o1;
	SelectItem i2 = (SelectItem) o2;
	RuleBasedCollator collator_ini = (RuleBasedCollator)Collator.getInstance();
	try {
		RuleBasedCollator collator= new RuleBasedCollator(collator_ini.getRules().replaceAll("<'\u005f'", "<' '<'\u005f'"));
		return collator.compare(i1.getLabel(), i2.getLabel());
	} catch (ParseException e) {}
	return Collator.getInstance().compare(i1.getLabel(), i2.getLabel());
}
 
Example 6
Source File: BeanSortComparator.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
private int subCompare(String s1, String s2)
{
 //we do not want to use null values for sorting
 if(s1 == null)
 {
  s1 = "";
 }

 if(s2 == null)
 {
  s2 = "";
 }

 // Deal with n/a case
 if (s1.toLowerCase().startsWith("n/a")
	  && !s2.toLowerCase().startsWith("n/a"))
  return 1;

 if (s2.toLowerCase().startsWith("n/a") &&
	  !s1.toLowerCase().startsWith("n/a"))
  return -1;


 String finalS1 = s1.replaceAll("<.*?>", "");
 String finalS2 = s2.replaceAll("<.*?>", "");
 RuleBasedCollator collator_ini = (RuleBasedCollator)Collator.getInstance();
 try {
RuleBasedCollator collator= new RuleBasedCollator(collator_ini.getRules().replaceAll("<'\u005f'", "<' '<'\u005f'"));
return collator.compare(finalS1.toLowerCase(), finalS2.toLowerCase());
 } catch (ParseException e) {}
 return Collator.getInstance().compare(finalS1.toLowerCase(), finalS2.toLowerCase());	  
}
 
Example 7
Source File: FacadeUtils.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public int compare(Object o1, Object o2) {
	try{
		RuleBasedCollator r_collator= new RuleBasedCollator(((RuleBasedCollator)Collator.getInstance()).getRules().replaceAll("<'\u005f'", "<' '<'\u005f'"));
		return r_collator.compare(((EnrollmentRecord)o1).getUser().getSortName(),((EnrollmentRecord)o2).getUser().getSortName());
	}catch(ParseException e){
		  return Collator.getInstance().compare(((EnrollmentRecord)o1).getUser().getSortName(),((EnrollmentRecord)o2).getUser().getSortName());
	}
}
 
Example 8
Source File: FacadeUtils.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public int compare(Object o1, Object o2) {
try{
	RuleBasedCollator r_collator= new RuleBasedCollator(((RuleBasedCollator)Collator.getInstance()).getRules().replaceAll("<'\u005f'", "<' '<'\u005f'"));
	return r_collator.compare(((EnrollmentRecord)o1).getUser().getDisplayId(),((EnrollmentRecord)o2).getUser().getDisplayId());
}catch(ParseException e){
	  return Collator.getInstance().compare(((EnrollmentRecord)o1).getUser().getDisplayId(),((EnrollmentRecord)o2).getUser().getDisplayId());
}
     }
 
Example 9
Source File: QuestionPoolBean.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public int compare(Object o1, Object o2) {
 QuestionPoolFacade i1 = (QuestionPoolFacade)o1;
 QuestionPoolFacade i2 = (QuestionPoolFacade)o2;
 if (i1 == null && i2 != null) {
  return 1;
 }
 if (i2 == null && i1 != null) {
  return -1;
 }
 if (i2 == null && i1 == null) {
  return 0;
 }
 if (i1.getTitle() == null && i2.getTitle() != null) {
  return 1;
 }
 if (i2.getTitle() == null && i1.getTitle() != null) {
  return -1;
 }
 if (i2.getTitle() == null && i1.getTitle() == null) {
  return 0;
 }
 RuleBasedCollator collator_ini = (RuleBasedCollator)Collator.getInstance();
 try {
RuleBasedCollator collator= new RuleBasedCollator(collator_ini.getRules().replaceAll("<'\u005f'", "<' '<'\u005f'"));
return collator.compare(i1.getTitle(), i2.getTitle());
 } catch (ParseException e) {}
 return Collator.getInstance().compare(i1.getTitle(), i2.getTitle());
}
 
Example 10
Source File: SectionBean.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public int compare(Object o1, Object o2) {
 SelectItem i1 = (SelectItem)o1;
 SelectItem i2 = (SelectItem)o2;
try{
	RuleBasedCollator r_collator= new RuleBasedCollator(((RuleBasedCollator)Collator.getInstance()).getRules().replaceAll("<'\u005f'", "<' '<'\u005f'"));
	return r_collator.compare(i1.getLabel(), i2.getLabel());
}catch(ParseException e){
	  return Collator.getInstance().compare(i1.getLabel(),i2.getLabel());
}
}
 
Example 11
Source File: ItemAuthorBean.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public int compare(Object o1, Object o2) {
	SelectItem i1 = (SelectItem) o1;
	SelectItem i2 = (SelectItem) o2;
	RuleBasedCollator collator_ini = (RuleBasedCollator)Collator.getInstance();
	try {
		RuleBasedCollator collator= new RuleBasedCollator(collator_ini.getRules().replaceAll("<'\u005f'", "<' '<'\u005f'"));
		return collator.compare(i1.getLabel(), i2.getLabel());
	} catch (ParseException e) {}
	return Collator.getInstance().compare(i1.getLabel(), i2.getLabel());
}
 
Example 12
Source File: BeanSortComparator.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
private int subCompare(String s1, String s2)
{
 //we do not want to use null values for sorting
 if(s1 == null)
 {
  s1 = "";
 }

 if(s2 == null)
 {
  s2 = "";
 }

 // Deal with n/a case
 if (s1.toLowerCase().startsWith("n/a")
	  && !s2.toLowerCase().startsWith("n/a"))
  return 1;

 if (s2.toLowerCase().startsWith("n/a") &&
	  !s1.toLowerCase().startsWith("n/a"))
  return -1;


 String finalS1 = s1.replaceAll("<.*?>", "");
 String finalS2 = s2.replaceAll("<.*?>", "");
 RuleBasedCollator collator_ini = (RuleBasedCollator)Collator.getInstance();
 try {
RuleBasedCollator collator= new RuleBasedCollator(collator_ini.getRules().replaceAll("<'\u005f'", "<' '<'\u005f'"));
return collator.compare(finalS1.toLowerCase(), finalS2.toLowerCase());
 } catch (ParseException e) {}
 return Collator.getInstance().compare(finalS1.toLowerCase(), finalS2.toLowerCase());	  
}
 
Example 13
Source File: Like.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * If the character in val matches the character in pat, then it does not
 * matter if the database is UCS_BASIC or territory based, we simply return 
 * TRUE from the method. 
 * If the characters do not match and we are running with UCS_BASIC 
 * collation, then we will return FALSE. 
 * But if the database is territory based, then we want to use the Collator 
 * for the territory to determine if the Collator treats the 2 characters 
 * as equal (ie if their collation elements match, then the 2 characters 
 * are equal even if they  are not the same character).
 * 
 * @param val value to compare.
 * @param vLoc character position in val.
 * @param pat pattern to look for in val.
 * @param pLoc character position in pat.
 * @param collator null if we are dealing with UCS_BASIC character string
 *   types. If not null, then we use it to determine the equality of the
 *   2 characters in pat and val if they are not same.
 * @return TRUE if the character in val and vLoc match based on straight
 *   equality or collation element based equality. Otherwise we will 
 *   return FALSE.
 */
private static boolean checkEquality(char[] val, int vLoc,
		char[] pat, int pLoc, RuleBasedCollator collator) {

	if (val[vLoc] == pat[pLoc]) { 
        // same character, so two strings consisting of this 
        // single character must be equal regardless of territory 
        return true; 
    } else if (collator == null) { 
        // not same character, must be unequal in UCS_BASIC 
        return false; 
    } 

	//Check if the Collator for this database's territory considers these
	//2 characters as equal based on their collation elements
    String s1 = new String(val, vLoc, 1); 
    String s2 = new String(pat, pLoc, 1); 

    return collator.compare(s1, s2) == 0; 
}
 
Example 14
Source File: Like.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * If the character in val matches the character in pat, then it does not
 * matter if the database is UCS_BASIC or territory based, we simply return 
 * TRUE from the method. 
 * If the characters do not match and we are running with UCS_BASIC 
 * collation, then we will return FALSE. 
 * But if the database is territory based, then we want to use the Collator 
 * for the territory to determine if the Collator treats the 2 characters 
 * as equal (ie if their collation elements match, then the 2 characters 
 * are equal even if they  are not the same character).
 * 
 * @param val value to compare.
 * @param vLoc character position in val.
 * @param pat pattern to look for in val.
 * @param pLoc character position in pat.
 * @param collator null if we are dealing with UCS_BASIC character string
 *   types. If not null, then we use it to determine the equality of the
 *   2 characters in pat and val if they are not same.
 * @return TRUE if the character in val and vLoc match based on straight
 *   equality or collation element based equality. Otherwise we will 
 *   return FALSE.
 */
private static boolean checkEquality(char[] val, int vLoc,
		char[] pat, int pLoc, RuleBasedCollator collator) {

	if (val[vLoc] == pat[pLoc]) { 
        // same character, so two strings consisting of this 
        // single character must be equal regardless of territory 
        return true; 
    } else if (collator == null) { 
        // not same character, must be unequal in UCS_BASIC 
        return false; 
    } 

	//Check if the Collator for this database's territory considers these
	//2 characters as equal based on their collation elements
    String s1 = new String(val, vLoc, 1); 
    String s2 = new String(pat, pLoc, 1); 

    return collator.compare(s1, s2) == 0; 
}
 
Example 15
Source File: Compare.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 4 votes vote down vote up
final static public int compare(CharSequence a,CharSequence b,RuleBasedCollator col) {

    	return col.compare(a.toString(), b.toString());

/*
 * pnajvar -
 * The following implementation is deprecated. 
 * There is no clear historical reason for such implementation.
 * 
 * Tests show using Collator.compare() is more efficient even on StringBuilders and works correctly
 * on characters like 't' and 't wedge', 'l' and 'l acute' etc.	
 */

/*    	
        CollationElementIterator iterA = col.getCollationElementIterator(
                        new CharSequenceCharacterIterator(a)); 
        CollationElementIterator iterB = col.getCollationElementIterator(
                new CharSequenceCharacterIterator(b)); 

        int elementA,elementB;
        int orderA,orderB;
        
        while ((elementA = iterA.next()) != CollationElementIterator.NULLORDER) {
            elementB=iterB.next();
            if (elementB != CollationElementIterator.NULLORDER){
                // check primary order
                orderA=CollationElementIterator.primaryOrder(elementA);
                orderB=CollationElementIterator.primaryOrder(elementB);
                if (orderA!=orderB){
                    return orderA-orderB;
                }
                orderA=CollationElementIterator.secondaryOrder(elementA);
                orderB=CollationElementIterator.secondaryOrder(elementB);
                if (orderA!=orderB){
                    return orderA-orderB;
                }
                orderA=CollationElementIterator.tertiaryOrder(elementA);
                orderB=CollationElementIterator.tertiaryOrder(elementB);
                if (orderA!=orderB){
                    return orderA-orderB;
                }
                
            }else{
                return 1; // first sequence seems to be longer than second
            }
        }
        elementB = iterB.next();
        if (elementB != CollationElementIterator.NULLORDER){
            return -1; // second sequence seems to be longer than first
        }else{
            return 0; // equal
        }
--
end of deprecated code */    
        
    }
 
Example 16
Source File: Like.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * If the character in val matches the character in pat, then it does not
 * matter if the database is UCS_BASIC or territory based, we simply return 
 * TRUE from the method. 
 * If the characters do not match and we are running with UCS_BASIC 
 * collation, then we will return FALSE. 
 * But if the database is territory based, then we want to use the Collator 
 * for the territory to determine if the Collator treats the 2 characters 
 * as equal (ie if their collation elements match, then the 2 characters 
 * are equal even if they  are not the same character).
 * 
 * @param val value to compare.
 * @param vLoc character position in val.
 * @param pat pattern to look for in val.
 * @param pLoc character position in pat.
 * @param collator null if we are dealing with UCS_BASIC character string
 *   types. If not null, then we use it to determine the equality of the
 *   2 characters in pat and val if they are not same.
 * @return TRUE if the character in val and vLoc match based on straight
 *   equality or collation element based equality. Otherwise we will 
 *   return FALSE.
 */
private static boolean checkEquality(char[] val, int vLoc,
		char[] pat, int pLoc, RuleBasedCollator collator) {

	if (val[vLoc] == pat[pLoc]) { 
        // same character, so two strings consisting of this 
        // single character must be equal regardless of territory 
        return true; 
    } else if (collator == null) { 
        // not same character, must be unequal in UCS_BASIC 
        return false; 
    } 

	//Check if the Collator for this database's territory considers these
	//2 characters as equal based on their collation elements
    String s1 = new String(val, vLoc, 1); 
    String s2 = new String(pat, pLoc, 1); 

    return collator.compare(s1, s2) == 0; 
}