Пример #1
0
  private boolean contains(char c) {
    char case_switched_c =
        Character.isUpperCase(c) ? Character.toLowerCase(c) : Character.toUpperCase(c);

    if (charClassStrings.indexOf(String.valueOf(c)) != -1) return true;

    // check for case_insensitive match if needed
    if (case_insensitive && (charClassStrings.indexOf(String.valueOf(case_switched_c)) != -1))
      return true;

    for (char[] range : rangeList) {
      if ((Character.compare(range[0], c) <= 0) && (Character.compare(range[1], c) >= 0))
        return true; // true if c is within the range
      if (case_insensitive)
        if ((Character.compare(range[0], case_switched_c) <= 0)
            && (Character.compare(range[1], case_switched_c) >= 0))
          return true; // true if case_insensitive matching and c is within the range with its case
                       // switched
    }
    return false;
  }
 /**
  * Static Helper Method which asks user specified question and as long as they give a input will
  * return a boolean type variable.
  *
  * @return Boolean value based on user input
  */
 public static char getChar(String question, char... characters) {
   while (true) {
     // Declare Local Variables
     boolean present = false;
     // Get the character using alternative method to get a char
     char letter = RequestInput.getChar(question);
     // Iterate through the supplied chars and see if it is present
     for (int i = 0; i < characters.length; i++) {
       if (Character.compare(characters[i], letter) == 0) {
         present = true;
       }
     }
     // If present variable is set to true and it is a valid option
     if (present == true) {
       // return the character
       return letter;
     } else {
       // Give an error message
       System.out.println("You have not entered a valid character (" + letter + ").");
       // Continue with next iteration
       continue;
     }
   }
 }
 boolean charIsBetween(char c, char l, char r) {
   return Character.compare(l, c) <= 0 && Character.compare(r, c) >= 0;
 }
 private void smallestValueIsEqualTo(char target) {
   assertTrue(
       "Expected " + smallestValueFound() + " to be equal to " + target,
       Character.compare(smallestValueFound(), target) == 0);
 }
Пример #5
0
 public void test_compare() throws Exception {
   assertEquals(0, Character.compare('a', 'a'));
   assertTrue(Character.compare('a', 'b') < 0);
   assertTrue(Character.compare('b', 'a') > 0);
 }