當前位置: 首頁>>代碼示例>>Java>>正文


Java Ascii類代碼示例

本文整理匯總了Java中com.google.common.base.Ascii的典型用法代碼示例。如果您正苦於以下問題:Java Ascii類的具體用法?Java Ascii怎麽用?Java Ascii使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Ascii類屬於com.google.common.base包,在下文中一共展示了Ascii類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: detect

import com.google.common.base.Ascii; //導入依賴的package包/類
@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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:21,代碼來源:Naming.java

示例2: shouldDisableFor

import com.google.common.base.Ascii; //導入依賴的package包/類
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(WARNING_START + " uppercase package names");
          return true;
        }
      }
    }
    if (element.getKind().isClass() || element.getKind().isInterface()) {
      if (Ascii.isLowerCase(element.getSimpleName().charAt(0))) {
        reporter.warning(WARNING_START + " lowercase class names");
        return true;
      }
    }
    element = element.getEnclosingElement();
  }
  return false;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:21,代碼來源:ImportRewriteDisabler.java

示例3: toString

import com.google.common.base.Ascii; //導入依賴的package包/類
/**
 * Returns a string representation for this MapMaker instance. The exact form of the returned
 * string is not specified.
 */
@Override
public String toString() {
  MoreObjects.ToStringHelper s = MoreObjects.toStringHelper(this);
  if (initialCapacity != UNSET_INT) {
    s.add("initialCapacity", initialCapacity);
  }
  if (concurrencyLevel != UNSET_INT) {
    s.add("concurrencyLevel", concurrencyLevel);
  }
  if (keyStrength != null) {
    s.add("keyStrength", Ascii.toLowerCase(keyStrength.toString()));
  }
  if (valueStrength != null) {
    s.add("valueStrength", Ascii.toLowerCase(valueStrength.toString()));
  }
  if (keyEquivalence != null) {
    s.addValue("keyEquivalence");
  }
  return s.toString();
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:25,代碼來源:MapMaker.java

示例4: InternetDomainName

import com.google.common.base.Ascii; //導入依賴的package包/類
/**
 * Constructor used to implement {@link #from(String)}, and from subclasses.
 */
InternetDomainName(String name) {
  // Normalize:
  // * ASCII characters to lowercase
  // * All dot-like characters to '.'
  // * Strip trailing '.'

  name = Ascii.toLowerCase(DOTS_MATCHER.replaceFrom(name, '.'));

  if (name.endsWith(".")) {
    name = name.substring(0, name.length() - 1);
  }

  checkArgument(name.length() <= MAX_LENGTH, "Domain name too long: '%s':", name);
  this.name = name;

  this.parts = ImmutableList.copyOf(DOT_SPLITTER.split(name));
  checkArgument(parts.size() <= MAX_PARTS, "Domain has too many parts: '%s'", name);
  checkArgument(validateSyntax(parts), "Not a valid domain name: '%s'", name);

  this.publicSuffixIndex = findPublicSuffix();
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:25,代碼來源:InternetDomainName.java

示例5: testToString

import com.google.common.base.Ascii; //導入依賴的package包/類
public void testToString() {
  for (String inputName : SOMEWHERE_UNDER_PS) {
    InternetDomainName domain = InternetDomainName.from(inputName);

    /*
     * We would ordinarily use constants for the expected results, but
     * doing it by derivation allows us to reuse the test case definitions
     * used in other tests.
     */

    String expectedName = Ascii.toLowerCase(inputName);
    expectedName = expectedName.replaceAll("[\u3002\uFF0E\uFF61]", ".");

    if (expectedName.endsWith(".")) {
      expectedName = expectedName.substring(0, expectedName.length() - 1);
    }

    assertEquals(expectedName, domain.toString());
  }
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:21,代碼來源:InternetDomainNameTest.java

示例6: endsWithWordOrIs

import com.google.common.base.Ascii; //導入依賴的package包/類
/**
 * True when s ends with suffix in a way that suffix is not part of a larger
 * word by camel-casing or underscore naming conventions.
 */
public static boolean endsWithWordOrIs(String s, String suffix) {
  if (suffix.isEmpty()) {
    return true;
  }
  String lc = Ascii.toLowerCase(s);
  if (lc.endsWith(suffix)) {
    int beforeSuffix = lc.length() - suffix.length() - 1;
    if (beforeSuffix < 0) {
      return true;
    }
    if (!Character.isLetterOrDigit(lc.charAt(beforeSuffix))) {
      return true;
    }
    if (Ascii.isLowerCase(s.charAt(beforeSuffix))
        && Ascii.isUpperCase(s.charAt(beforeSuffix + 1))) {
      return true;
    }
  }
  return false;
}
 
開發者ID:mikesamuel,項目名稱:closure-maven-plugin,代碼行數:25,代碼來源:Words.java

示例7: InternetDomainName

import com.google.common.base.Ascii; //導入依賴的package包/類
/**
 * Constructor used to implement {@link #from(String)}, and from subclasses.
 */

InternetDomainName(String name) {
  // Normalize:
  // * ASCII characters to lowercase
  // * All dot-like characters to '.'
  // * Strip trailing '.'
  name = Ascii.toLowerCase(DOTS_MATCHER.replaceFrom(name, '.'));
  if (name.endsWith(".")) {
    name = name.substring(0, name.length() - 1);
  }
  checkArgument(name.length() <= MAX_LENGTH, "Domain name too long: '%s':", name);
  this.name = name;
  this.parts = ImmutableList.copyOf(DOT_SPLITTER.split(name));
  checkArgument(parts.size() <= MAX_PARTS, "Domain has too many parts: '%s'", name);
  checkArgument(validateSyntax(parts), "Not a valid domain name: '%s'", name);
  this.publicSuffixIndex = findPublicSuffix();
}
 
開發者ID:antlr,項目名稱:codebuff,代碼行數:21,代碼來源:InternetDomainName.java

示例8: toString

import com.google.common.base.Ascii; //導入依賴的package包/類
/**
 * Returns a string representation for this MapMaker instance. The exact form of the returned
 * string is not specificed.
 */

@Override
public String toString() {
  MoreObjects.ToStringHelper s = MoreObjects.toStringHelper(this);
  if (initialCapacity != UNSET_INT) {
    s.add("initialCapacity", initialCapacity);
  }
  if (concurrencyLevel != UNSET_INT) {
    s.add("concurrencyLevel", concurrencyLevel);
  }
  if (keyStrength != null) {
    s.add("keyStrength", Ascii.toLowerCase(keyStrength.toString()));
  }
  if (valueStrength != null) {
    s.add("valueStrength", Ascii.toLowerCase(valueStrength.toString()));
  }
  if (keyEquivalence != null) {
    s.addValue("keyEquivalence");
  }
  return s.toString();
}
 
開發者ID:antlr,項目名稱:codebuff,代碼行數:26,代碼來源:MapMaker.java

示例9: toString

import com.google.common.base.Ascii; //導入依賴的package包/類
/**
 * Returns a string representation for this MapMaker instance. The exact form of the returned
 * string is not specificed.
 */
@Override
public String toString() {
  MoreObjects.ToStringHelper s = MoreObjects.toStringHelper(this);
  if (initialCapacity != UNSET_INT) {
    s.add("initialCapacity", initialCapacity);
  }
  if (concurrencyLevel != UNSET_INT) {
    s.add("concurrencyLevel", concurrencyLevel);
  }
  if (keyStrength != null) {
    s.add("keyStrength", Ascii.toLowerCase(keyStrength.toString()));
  }
  if (valueStrength != null) {
    s.add("valueStrength", Ascii.toLowerCase(valueStrength.toString()));
  }
  if (keyEquivalence != null) {
    s.addValue("keyEquivalence");
  }
  return s.toString();
}
 
開發者ID:antlr,項目名稱:codebuff,代碼行數:25,代碼來源:MapMaker.java

示例10: millisPerUnit

import com.google.common.base.Ascii; //導入依賴的package包/類
private static int millisPerUnit(String unit) {
  switch (Ascii.toLowerCase(unit)) {
    case "d":
      return DateTimeConstants.MILLIS_PER_DAY;
    case "h":
      return DateTimeConstants.MILLIS_PER_HOUR;
    case "m":
      return DateTimeConstants.MILLIS_PER_MINUTE;
    case "s":
      return DateTimeConstants.MILLIS_PER_SECOND;
    case "ms":
      return 1;
    default:
      throw new IllegalArgumentException("Unknown duration unit " + unit);
  }
}
 
開發者ID:GoogleCloudPlatform,項目名稱:pubsub,代碼行數:17,代碼來源:Driver.java

示例11: setHeader

import com.google.common.base.Ascii; //導入依賴的package包/類
public final T setHeader(String name, @Nullable String value) {
  checkArgument(CharMatcher.whitespace().matchesNoneOf(name));
  name = Ascii.toLowerCase(name);
  value = emptyToNull(value);
  switch (name) {
    case "content-type":
      setContentType(value == null ? null : MediaType.parse(value));
      break;
    case "content-length":
      setContentLength(value == null ? -1 : Long.parseLong(value));
      break;
    default:
      if (value == null) {
        headers.remove(name);
      } else {
        checkArgument(CRLF.matchesNoneOf(value));
        headers.put(name, checkNotNull(value));
      }
  }
  return castThis();
}
 
開發者ID:bazelbuild,項目名稱:rules_closure,代碼行數:22,代碼來源:HttpMessage.java

示例12: saveReportToGcs

import com.google.common.base.Ascii; //導入依賴的package包/類
/** Stores a report on GCS, returning the name of the file stored. */
private String saveReportToGcs(String tld, String reportCsv, ReportType reportType)
    throws IOException {
  // Upload resulting CSV file to GCS
  byte[] reportBytes = reportCsv.getBytes(UTF_8);
  String reportFilename =
      String.format(
          "%s-%s-%s.csv",
          tld,
          Ascii.toLowerCase(reportType.toString()),
          DateTimeFormat.forPattern("yyyyMM").print(yearMonth));
  String reportBucketname = String.format("%s/%s", reportingBucket, subdir);
  final GcsFilename gcsFilename = new GcsFilename(reportBucketname, reportFilename);
  gcsUtils.createFromBytes(gcsFilename, reportBytes);
  logger.infofmt(
      "Wrote %d bytes to file location %s",
      reportBytes.length,
      gcsFilename.toString());
  return reportFilename;
}
 
開發者ID:google,項目名稱:nomulus,代碼行數:21,代碼來源:IcannReportingStager.java

示例13: validate

import com.google.common.base.Ascii; //導入依賴的package包/類
/**
 * Validate the checksum of the notice against the domain label.
 *
 * @throws IllegalArgumentException
 * @throws InvalidChecksumException
 */
public void validate(String domainLabel) throws InvalidChecksumException {
  // According to http://tools.ietf.org/html/draft-lozano-tmch-func-spec-08#section-6.3, a TCNID
  // is always 8 chars of checksum + 19 chars of a decimal notice id. Check the length before
  // taking substrings to avoid an IndexOutOfBoundsException.
  String tcnId = getNoticeId().getTcnId();
  checkArgument(tcnId.length() == 27);

  int checksum = Ints.fromByteArray(base16().decode(Ascii.toUpperCase(tcnId.substring(0, 8))));
  String noticeId = tcnId.substring(8);
  checkArgument(CharMatcher.inRange('0', '9').matchesAllOf(noticeId));

  // The checksum in the first 8 chars must match the crc32 of label + expiration + notice id.
  String stringToHash =
      domainLabel + MILLISECONDS.toSeconds(getExpirationTime().getMillis()) + noticeId;
  int computedChecksum = crc32().hashString(stringToHash, UTF_8).asInt();
  if (checksum != computedChecksum) {
    throw new InvalidChecksumException();
  }
}
 
開發者ID:google,項目名稱:nomulus,代碼行數:26,代碼來源:LaunchNotice.java

示例14: apply

import com.google.common.base.Ascii; //導入依賴的package包/類
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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:12,代碼來源:Naming.java

示例15: process

import com.google.common.base.Ascii; //導入依賴的package包/類
void process() {
  if (startType.getKind().isPrimitive()) {
    // taking a shortcut for primitives
    String typeName = Ascii.toLowerCase(startType.getKind().name());
    this.rawTypeName = typeName;
    this.returnTypeName = typeName;
    List<? extends AnnotationMirror> annotations = AnnotationMirrors.from(startType);
    if (!annotations.isEmpty()) {
      returnTypeName = typeAnnotationsToBuffer(annotations).append(typeName).toString();
    }
  } else {
    this.buffer = new StringBuilder(100);
    caseType(startType);

    if (workaroundTypeString != null) {
      // to not mix the mess, we just replace buffer with workaround produced type string
      this.buffer = new StringBuilder(workaroundTypeString);
    }

    // It seems that array type annotations are not exposed in javac
    // Nested type argument's type annotations are not exposed as well (in javac)
    // So currently we instert only for top level, declared type (here),
    // and primitives (see above)
    TypeKind k = startType.getKind();
    if (k == TypeKind.DECLARED || k == TypeKind.ERROR) {
      insertTypeAnnotationsIfPresent(startType, 0, rawTypeName.length());
    }

    this.returnTypeName = buffer.toString();
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:32,代碼來源:TypeStringProvider.java


注:本文中的com.google.common.base.Ascii類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。