private final int getCaseDiff(final String text, final String pattern) {
    final int savedStrength = m_collator.getStrength();
    final int savedDecomposition = m_collator.getDecomposition();
    m_collator.setStrength(Collator.TERTIARY); // not to ignore case
    m_collator.setDecomposition(Collator.CANONICAL_DECOMPOSITION); // corresponds NDF

    final int diff[] = getFirstCaseDiff(text, pattern, m_locale);
    m_collator.setStrength(savedStrength); // restore
    m_collator.setDecomposition(savedDecomposition); // restore
    if (diff != null) {
      if ((m_caseOrder).equals("upper-first")) {
        if (diff[0] == UPPER_CASE) {
          return -1;
        } else {
          return 1;
        }
      } else { // lower-first
        if (diff[0] == LOWER_CASE) {
          return -1;
        } else {
          return 1;
        }
      }
    } else { // No case differences
      return 0;
    }
  }
  public int compareTo(Object o) {
    final String pattern = ((StringComparable) o).toString();
    if (m_text.equals(pattern)) { // Code-point equals
      return 0;
    }
    final int savedStrength = m_collator.getStrength();
    int comp = 0;
    // Is there difference more significant than case-order?
    if (((savedStrength == Collator.PRIMARY) || (savedStrength == Collator.SECONDARY))) {
      comp = m_collator.compare(m_text, pattern);
    } else { // more than SECONDARY
      m_collator.setStrength(Collator.SECONDARY);
      comp = m_collator.compare(m_text, pattern);
      m_collator.setStrength(savedStrength);
    }
    if (comp != 0) { // Difference more significant than case-order
      return comp;
    }

    // No difference more significant than case-order.
    // Find case difference
    comp = getCaseDiff(m_text, pattern);
    if (comp != 0) {
      return comp;
    } else { // No case differences. Less significant difference could exist
      return m_collator.compare(m_text, pattern);
    }
  }