Ejemplo n.º 1
0
 /**
  * Determines whether a string could be the name of a Java class.
  *
  * <p>If this method returns true, it does not necessarily mean that the Java class with <code>
  * className</code> exists; it only means that one could write a Java class with that
  * fully-qualified name.
  *
  * @param className A string to test.
  * @return Whether the class name was valid.
  */
 public static boolean isValidClassName(String className) {
   // A valid class name is a bunch of valid Java identifiers separated by dots.
   for (String part : StringUtils.splitByWholeSeparatorPreserveAllTokens(className, ".")) {
     if (!isValidIdentifier(part)) {
       return false;
     }
   }
   return true;
 }
 public Line(String separator, String textPart, boolean endsWithNextLine) {
   this.endsWithNextLine = endsWithNextLine;
   this.separator = separator;
   if (separator.equals(" ")) {
     split = StringUtils.splitByWholeSeparator(textPart, separator);
   } else {
     split = StringUtils.splitByWholeSeparatorPreserveAllTokens(textPart, separator);
   }
   hasSeparatorBeforeFirstToken = split.length > 0 && split[0].length() == 0;
 }
Ejemplo n.º 3
0
 /**
  * Parses an {@code ObjectId} from a formatted scheme and value.
  *
  * <p>This parses the identifier from the form produced by {@code toString()} which is {@code
  * <SCHEME>~<VALUE>}.
  *
  * @param str the object identifier to parse, not null
  * @return the object identifier, not null
  * @throws IllegalArgumentException if the identifier cannot be parsed
  */
 @FromString
 public static ObjectId parse(String str) {
   ArgumentChecker.notEmpty(str, "str");
   if (str.contains("~") == false) {
     str = StringUtils.replace(str, "::", "~"); // leniently parse old data
   }
   String[] split = StringUtils.splitByWholeSeparatorPreserveAllTokens(str, "~");
   switch (split.length) {
     case 2:
       return ObjectId.of(split[0], split[1]);
   }
   throw new IllegalArgumentException("Invalid identifier format: " + str);
 }