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

The following examples show how to use com.google.common.base.Ascii#toUpperCase() . 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: 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 2
Source File: BaseEncoding.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
Alphabet upperCase() {
  if (!hasLowerCase()) {
    return this;
  } else {
    checkState(!hasUpperCase(), "Cannot call upperCase() on a mixed-case alphabet");
    char[] upperCased = new char[chars.length];
    for (int i = 0; i < chars.length; i++) {
      upperCased[i] = Ascii.toUpperCase(chars[i]);
    }
    return new Alphabet(name + ".upperCase()", upperCased);
  }
}
 
Example 3
Source File: BaseEncoding.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
Alphabet upperCase() {
  if (!hasLowerCase()) {
    return this;
  } else {
    checkState(!hasUpperCase(), "Cannot call upperCase() on a mixed-case alphabet");
    char[] upperCased = new char[chars.length];
    for (int i = 0; i < chars.length; i++) {
      upperCased[i] = Ascii.toUpperCase(chars[i]);
    }
    return new Alphabet(name + ".upperCase()", upperCased);
  }
}
 
Example 4
Source File: BaseEncoding.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
Alphabet upperCase() {
  if (!hasLowerCase()) {
    return this;
  } else {
    checkState(!hasUpperCase(), "Cannot call upperCase() on a mixed-case alphabet");
    char[] upperCased = new char[chars.length];
    for (int i = 0; i < chars.length; i++) {
      upperCased[i] = Ascii.toUpperCase(chars[i]);
    }
    return new Alphabet(name + ".upperCase()", upperCased);
  }
}
 
Example 5
Source File: BaseEncoding.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
Alphabet upperCase() {
  if (!hasLowerCase()) {
    return this;
  } else {
    checkState(!hasUpperCase(), "Cannot call upperCase() on a mixed-case alphabet");
    char[] upperCased = new char[chars.length];
    for (int i = 0; i < chars.length; i++) {
      upperCased[i] = Ascii.toUpperCase(chars[i]);
    }
    return new Alphabet(name + ".upperCase()", upperCased);
  }
}
 
Example 6
Source File: BaseEncoding.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
Alphabet upperCase() {
  if (!hasLowerCase()) {
    return this;
  } else {
    checkState(!hasUpperCase(), "Cannot call upperCase() on a mixed-case alphabet");
    char[] upperCased = new char[chars.length];
    for (int i = 0; i < chars.length; i++) {
      upperCased[i] = Ascii.toUpperCase(chars[i]);
    }
    return new Alphabet(name + ".upperCase()", upperCased);
  }
}
 
Example 7
Source File: ExpressionConverter.java    From beam with Apache License 2.0 5 votes vote down vote up
private RexNode convertIntervalToRexIntervalLiteral(ResolvedLiteral resolvedLiteral) {
  if (resolvedLiteral.getType().getKind() != TYPE_STRING) {
    throw new SqlConversionException(INTERVAL_FORMAT_MSG);
  }

  String valStr = resolvedLiteral.getValue().getStringValue();
  List<String> stringList =
      Arrays.stream(valStr.split(" ")).filter(s -> !s.isEmpty()).collect(Collectors.toList());

  if (stringList.size() != 3) {
    throw new SqlConversionException(INTERVAL_FORMAT_MSG);
  }

  if (!Ascii.toUpperCase(stringList.get(0)).equals("INTERVAL")) {
    throw new SqlConversionException(INTERVAL_FORMAT_MSG);
  }

  long intervalValue;
  try {
    intervalValue = Long.parseLong(stringList.get(1));
  } catch (NumberFormatException e) {
    throw new SqlConversionException(INTERVAL_FORMAT_MSG, e);
  }

  String intervalDatepart = Ascii.toUpperCase(stringList.get(2));
  return createCalciteIntervalRexLiteral(intervalValue, intervalDatepart);
}
 
Example 8
Source File: RegistrarFormFields.java    From nomulus with Apache License 2.0 5 votes vote down vote up
private static @Nullable RegistrarAddress toNewAddress(
    @Nullable Map<String, ?> args,
    final FormField<List<String>, List<String>> streetField,
    final FormField<String, String> cityField,
    final FormField<String, String> stateField,
    final FormField<String, String> zipField) {
  if (args == null) {
    return null;
  }
  RegistrarAddress.Builder builder = new RegistrarAddress.Builder();
  String countryCode = COUNTRY_CODE_FIELD.extractUntyped(args).get();
  builder.setCountryCode(countryCode);
  streetField
      .extractUntyped(args)
      .ifPresent(streets -> builder.setStreet(ImmutableList.copyOf(streets)));
  cityField.extractUntyped(args).ifPresent(builder::setCity);
  Optional<String> stateFieldValue = stateField.extractUntyped(args);
  if (stateFieldValue.isPresent()) {
    String state = stateFieldValue.get();
    if ("US".equals(countryCode)) {
      state = Ascii.toUpperCase(state);
      if (!StateCode.US_MAP.containsKey(state)) {
        throw new FormFieldException(stateField, "Unknown US state code.");
      }
    }
    builder.setState(state);
  }
  zipField.extractUntyped(args).ifPresent(builder::setZip);
  return builder.build();
}
 
Example 9
Source File: CreateOrUpdateDomainCommand.java    From nomulus with Apache License 2.0 5 votes vote down vote up
private static DsRecord create(int keyTag, int alg, int digestType, String digest) {
  digest = Ascii.toUpperCase(digest);
  checkArgument(
      BaseEncoding.base16().canDecode(digest),
      "digest should be even-lengthed hex, but is %s (length %s)",
      digest,
      digest.length());
  return new AutoValue_CreateOrUpdateDomainCommand_DsRecord(keyTag, alg, digestType, digest);
}
 
Example 10
Source File: StringModule.java    From bazel with Apache License 2.0 5 votes vote down vote up
@StarlarkMethod(
    name = "upper",
    doc = "Returns the upper case version of this string.",
    parameters = {@Param(name = "self", type = String.class)})
public String upper(String self) {
  return Ascii.toUpperCase(self);
}
 
Example 11
Source File: PythonOptions.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Override
public PythonVersion convert(String input) throws OptionsParsingException {
  try {
    // Although in rule attributes the enum values are case sensitive, the convention from
    // EnumConverter is that the options parser is case insensitive.
    input = Ascii.toUpperCase(input);
    return PythonVersion.parseTargetValue(input);
  } catch (IllegalArgumentException ex) {
    throw new OptionsParsingException(
        "Not a valid Python major version, should be PY2 or PY3", ex);
  }
}
 
Example 12
Source File: DuplicatedTypesUnifier.java    From jsinterop-generator with Apache License 2.0 4 votes vote down vote up
private String getGetterName(Field field) {
  return "get"
      + Ascii.toUpperCase(field.getName().substring(0, 1))
      + field.getName().substring(1);
}
 
Example 13
Source File: NullSafeAscii.java    From sfs with Apache License 2.0 4 votes vote down vote up
public static char toLowerCase(char c) {
    return Ascii.toUpperCase(c);
}
 
Example 14
Source File: NullSafeAscii.java    From sfs with Apache License 2.0 4 votes vote down vote up
public static String toUpperCase(String string) {
    if (string != null) {
        return Ascii.toUpperCase(string);
    }
    return null;
}
 
Example 15
Source File: NullSafeAscii.java    From sfs with Apache License 2.0 4 votes vote down vote up
public static String toUpperCase(CharSequence chars) {
    if (chars != null) {
        return Ascii.toUpperCase(chars);
    }
    return null;
}
 
Example 16
Source File: NullSafeAscii.java    From sfs with Apache License 2.0 4 votes vote down vote up
public static char toUpperCase(char c) {
    return Ascii.toUpperCase(c);
}