@Override
    public int compareTo(Rule other) {
      int retVal = matchingRule.expectedComponentCount - other.matchingRule.expectedComponentCount;
      if (retVal == 0) {
        retVal = other.matchingRule.matchComponentCount() - matchingRule.matchComponentCount();
        if (retVal == 0) {
          if (this.principal.equals(other.principal)) {
            retVal = toString().compareTo(other.toString());
          } else {
            // check for wildcard realms '.*'
            String realm = this.principal.getRealm();
            String otherRealm = other.principal.getRealm();
            retVal = compareValueWithWildcards(realm, otherRealm);
            if (retVal == 0) {
              for (int i = 1; i <= matchingRule.matchComponentCount(); i++) {
                // check for wildcard component
                String component1 = this.principal.getComponent(1);
                String otherComponent1 = other.principal.getComponent(1);
                retVal = compareValueWithWildcards(component1, otherComponent1);

                if (retVal != 0) {
                  break;
                }
              }
            }
          }
        }
      }
      return retVal;
    }
Compares rules.
<p/>
For rules with different expected component counts, the default string comparison is used.
For rules with the same expected component count rules are ordered so that rules with a higher
match component count occur first.
<p/>
For rules with the same expected component count, default realm rules in the form of
.*@myRealm.com are ordered last.

@param other the other rule to compare
@return a negative integer, zero, or a positive integer as this object is less than,
equal to, or greater than the specified object
ambari-server/src/main/java/org/apache/ambari/server/controller/AuthToLocalBuilder.java