Exemplo n.º 1
0
  /**
   * Returns true if two names match without regard to case or the presence of '-' or '_'
   * characters.
   *
   * @param beanName The name of the bean property to compare
   * @param elementName The name of the element to compare
   * @return True if the names match
   */
  public static boolean namesMatch(String beanName, String elementName) {
    int beanNameLen = beanName.length();
    int elementNameLen = elementName.length();

    int elementPos = 0;
    int beanPos = 0;

    // Keep looping until you hit the end of either of the strings
    while ((elementPos < elementNameLen) && (beanPos < beanNameLen)) {
      // If the next character in the bean name is a '-' or a '/', skip it
      char beanCh = Character.toLowerCase(beanName.charAt(beanPos));
      if ((beanCh == '-') || (beanCh == '_')) {
        beanPos++;
        continue;
      }

      // If the next character in the element name is a '-' or a '/', skip it
      char elementCh = Character.toLowerCase(elementName.charAt(elementPos));
      if ((elementCh == '-') || (elementCh == '_')) {
        elementPos++;
        continue;
      }

      // If the characters don't match, the names don't match
      if (elementCh != beanCh) return false;
      elementPos++;
      beanPos++;
    }

    // You hit the end of both names at the same time, the names match
    if ((elementPos == elementNameLen) && (beanPos == beanNameLen)) {
      return true;
    }

    return false;
  }
Exemplo n.º 2
0
 /**
  * Converts a character to lower case.
  *
  * @param ch character to be converted
  * @return resulting character
  */
 public static int lc(final int ch) {
   return ch >= 'A' && ch <= 'Z' ? ch | 0x20 : ch > 0x7F ? Character.toLowerCase(ch) : ch;
 }