Java Code Examples for com.google.common.base.Ascii#isUpperCase()

The following examples show how to use com.google.common.base.Ascii#isUpperCase() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JexlASTHelper.java    From datawave with Apache License 2.0 6 votes vote down vote up
/**
 * Rebuild the identifier with the {@link #IDENTIFIER_PREFIX} if the identifier starts with an invalid character per the Jexl IDENTIFIER definition
 * 
 * @param fieldName
 * @param includeGroupingContext
 * @return
 */
public static String rebuildIdentifier(String fieldName, Boolean includeGroupingContext) {
    // fieldName may be null if it is from a Function node
    if (fieldName != null && fieldName.length() > 1) {
        if (!includeGroupingContext) {
            fieldName = removeGroupingContext(fieldName);
        }
        
        Character firstChar = fieldName.charAt(0);
        
        // Accepted first character in an identifier given the Commons-Jexl-2.1.1 IDENTIFIER definition
        if (!Ascii.isLowerCase(firstChar) && !Ascii.isUpperCase(firstChar) && firstChar != '_' && firstChar != '$' && firstChar != '@') {
            return IDENTIFIER_PREFIX + fieldName;
        }
    }
    
    return fieldName;
}
 
Example 2
Source File: AnnotatedElementNameUtil.java    From armeria with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
static String toHeaderName(String name) {
    requireNonNull(name, "name");
    checkArgument(!name.isEmpty(), "name is empty.");

    final String upperCased = Ascii.toUpperCase(name);
    if (name.equals(upperCased)) {
        return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, name);
    }
    final String lowerCased = Ascii.toLowerCase(name);
    if (name.equals(lowerCased)) {
        return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, name);
    }
    // Ensure that the name does not contain '_'.
    // If it contains '_', we give up to make it lower hyphen case. Just converting it to lower case.
    if (name.indexOf('_') >= 0) {
        return lowerCased;
    }
    if (Ascii.isUpperCase(name.charAt(0))) {
        return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, name);
    } else {
        return CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, name);
    }
}
 
Example 3
Source File: Naming.java    From immutables with Apache License 2.0 6 votes vote down vote up
@Override
public String detect(String identifier) {
  if (identifier.length() <= lengthsOfPrefixAndSuffix) {
    return NOT_DETECTED;
  }

  boolean prefixMatches = prefix.isEmpty() ||
      (identifier.startsWith(prefix) && Ascii.isUpperCase(identifier.charAt(prefix.length())));

  boolean suffixMatches = suffix.isEmpty() || identifier.endsWith(suffix);

  if (prefixMatches && suffixMatches) {
    String detected = identifier.substring(prefix.length(), identifier.length() - suffix.length());
    return prefix.isEmpty()
        ? detected
        : CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, detected);
  }

  return NOT_DETECTED;
}
 
Example 4
Source File: ImportRewriteDisabler.java    From immutables with Apache License 2.0 6 votes vote down vote up
private static boolean shouldDisableFor(Reporter reporter, Element element) {
  while (element != null) {
    if (element.getKind() == ElementKind.PACKAGE) {
      for (String segment : DOT_SPLITTER.split(((PackageElement) element).getQualifiedName())) {
        if (!segment.isEmpty() && Ascii.isUpperCase(segment.charAt(0))) {
          reporter.warning(About.INCOMPAT, WARNING_START + " uppercase package names");
          return true;
        }
      }
    }
    if (element.getKind().isClass() || element.getKind().isInterface()) {
      if (Ascii.isLowerCase(element.getSimpleName().charAt(0))) {
        reporter.warning(About.INCOMPAT, WARNING_START + " lowercase class names");
        return true;
      }
    }
    element = element.getEnclosingElement();
  }
  return false;
}
 
Example 5
Source File: BaseEncoding.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private boolean hasUpperCase() {
  for (char c : chars) {
    if (Ascii.isUpperCase(c)) {
      return true;
    }
  }
  return false;
}
 
Example 6
Source File: BaseEncoding.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private boolean hasUpperCase() {
  for (char c : chars) {
    if (Ascii.isUpperCase(c)) {
      return true;
    }
  }
  return false;
}
 
Example 7
Source File: BaseEncoding.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private boolean hasUpperCase() {
  for (char c : chars) {
    if (Ascii.isUpperCase(c)) {
      return true;
    }
  }
  return false;
}
 
Example 8
Source File: BaseEncoding.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private boolean hasUpperCase() {
  for (char c : chars) {
    if (Ascii.isUpperCase(c)) {
      return true;
    }
  }
  return false;
}
 
Example 9
Source File: BaseEncoding.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private boolean hasUpperCase() {
  for (char c : chars) {
    if (Ascii.isUpperCase(c)) {
      return true;
    }
  }
  return false;
}
 
Example 10
Source File: ClassName.java    From dagger2-sample with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a new {@link ClassName} instance for the given fully-qualified class name string. This
 * method assumes that the input is ASCII and follows typical Java style (lower-case package
 * names, upper-camel-case class names) and may produce incorrect results or throw
 * {@link IllegalArgumentException} otherwise. For that reason, {@link #fromClass(Class)} and
 * {@link #fromClass(Class)} should be preferred as they can correctly create {@link ClassName}
 * instances without such restrictions.
 */
public static ClassName bestGuessFromString(String classNameString) {
  checkNotNull(classNameString);
  List<String> parts = Splitter.on('.').splitToList(classNameString);
  int firstClassPartIndex = -1;
  for (int i = 0; i < parts.size(); i++) {
    String part = parts.get(i);
    checkArgument(SourceVersion.isIdentifier(part));
    char firstChar = part.charAt(0);
    if (Ascii.isLowerCase(firstChar)) {
      // looks like a package part
      if (firstClassPartIndex >= 0) {
        throw new IllegalArgumentException("couldn't make a guess for " + classNameString);
      }
    } else if (Ascii.isUpperCase(firstChar)) {
      // looks like a class part
      if (firstClassPartIndex < 0) {
        firstClassPartIndex = i;
      }
    } else {
      throw new IllegalArgumentException("couldn't make a guess for " + classNameString);
    }
  }
  int lastIndex = parts.size() - 1;
  return new ClassName(
      Joiner.on('.').join(parts.subList(0, firstClassPartIndex)),
      firstClassPartIndex == lastIndex
          ? ImmutableList.<String>of()
          : ImmutableList.copyOf(parts.subList(firstClassPartIndex, lastIndex)),
      parts.get(lastIndex));
}
 
Example 11
Source File: RefasterRule.java    From Refaster with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
  List<String> path = Splitter.on('.').splitToList(qualifiedTemplateClass());
  for (int topLevel = 0; topLevel < path.size() - 1; topLevel++) {
    if (Ascii.isUpperCase(path.get(topLevel).charAt(0))) {
      return Joiner.on('_').join(path.subList(topLevel + 1, path.size()));
    }
  }
  return qualifiedTemplateClass();
}
 
Example 12
Source File: Naming.java    From immutables with Apache License 2.0 5 votes vote down vote up
public String apply(String input) {
  if (!input.isEmpty()) {
    if (this == CAPITALIZED && !Ascii.isUpperCase(input.charAt(0))) {
      return CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, input);
    }
    if (this == LOWERIZED && !Ascii.isLowerCase(input.charAt(0))) {
      return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, input);
    }
  }
  return input;
}
 
Example 13
Source File: ImportRewriteDisabler.java    From immutables with Apache License 2.0 5 votes vote down vote up
static boolean shouldDisableFor(ValueType type) {
  Reporter reporter = type.constitution.protoclass().report();

  for (String segment : DOT_SPLITTER.split(type.constitution.implementationPackage())) {
    if (!segment.isEmpty() && Ascii.isUpperCase(segment.charAt(0))) {
      reporter.warning(About.INCOMPAT, WARNING_START + " uppercase package names");
      return true;
    }
  }

  Element element = type.constitution.protoclass().sourceElement();
  if (shouldDisableFor(reporter, element)) {
    return true;
  }

  for (ValueAttribute attribute : type.attributes) {
    if (Ascii.isUpperCase(attribute.names.get.charAt(0))) {
      reporter.warning(About.INCOMPAT, WARNING_START + " uppercase attribute names");
      return true;
    }
    if (attribute.containedTypeElement != null) {
      if (shouldDisableFor(reporter, attribute.containedTypeElement)) {
        return true;
      }
    }
  }

  for (ValueType nested : type.nested) {
    if (shouldDisableFor(nested)) {
      return true;
    }
  }
  return false;
}
 
Example 14
Source File: ImportsTypeStringResolver.java    From immutables with Apache License 2.0 5 votes vote down vote up
@Override
public String apply(String input) {
  unresolved = false;
  boolean assumedUnqualified = Ascii.isUpperCase(input.charAt(0));
  if (assumedUnqualified) {
    input = qualifyImportedIfPossible(input, false);
  }
  return input;
}
 
Example 15
Source File: ImportsTypeStringResolver.java    From immutables with Apache License 2.0 5 votes vote down vote up
String resolveTopForAttribute(String input) {
  unresolved = false;
  boolean assumedUnqualified = Ascii.isUpperCase(input.charAt(0));
  if (assumedUnqualified) {
    input = qualifyImportedIfPossible(input, !unresolvedYetArguments.contains(input));
  }
  return input;
}
 
Example 16
Source File: NullSafeAscii.java    From sfs with Apache License 2.0 4 votes vote down vote up
public static boolean isUpperCase(char c) {
    return Ascii.isUpperCase(c);
}