code: public static String validate(String name, String value, String[] validValues)
              throws IllegalArgumentException {
          String normVal = validate(name, value, Integer.MAX_VALUE);
          StringBuilder s = new StringBuilder();
          for (int i = 0; i < validValues.length; i++) {
              if (i > 0) {
                  s.append(", ");
              }
              s.append("'");
              s.append(validValues[i]);
              s.append("'");
              if (normVal.equals(validValues[i])) return normVal;
          }
          throw new IllegalArgumentException("One of the following values must"
                  + " be specified for '" + name + "': [ " + s.toString()
                  + " ]");
      }
docs: Checks that the given value's normalized form is one of the allowed
  values.
  
  @param name the name of the property being checked, for error reporting.
  @param value the value.
  @param validValues the allowed values.
  @return the normalized value.
  @throws IllegalArgumentException if the normalized value is null,
  zero-length, or not one of the allowed values.