Java 类com.google.common.base.CharMatcher 实例源码

项目:GitHub    文件:SourceExtraction.java   
private static CharSequence readSourceSuperclass(StringTokenizer tokenizer) {
  StringBuilder superclass = new StringBuilder();
  while (tokenizer.hasMoreTokens()) {
    String part = tokenizer.nextToken();
    if (CharMatcher.whitespace().matchesAllOf(part)) {
      continue;
    }
    if (superclass.length() == 0
        || part.charAt(0) == '.'
        || superclass.charAt(superclass.length() - 1) == '.') {
      superclass.append(part);
    } else {
      break;
    }
  }
  return superclass;
}
项目:tac-kbp-eal    文件:QuoteFilter.java   
private QuoteFilter(Map<Symbol, ImmutableRangeSet<Integer>> docIdToBannedRegions) {
  this.docIdToBannedRegions = ImmutableMap.copyOf(docIdToBannedRegions);
  for (RangeSet<Integer> rs : docIdToBannedRegions.values()) {
    for (final Range<Integer> r : rs.asRanges()) {
      checkArgument(r.hasLowerBound());
      checkArgument(r.hasUpperBound());
      checkArgument(r.lowerEndpoint() >= 0);
    }
  }
  // these ensure we can serialize safely
  for (Symbol sym : docIdToBannedRegions.keySet()) {
    final String s = sym.toString();
    checkArgument(!s.isEmpty(), "Document IDs may not be empty");
    checkArgument(!CharMatcher.WHITESPACE.matchesAnyOf(s),
        "Document IDs may not contain whitespace: %s", s);
  }
}
项目:Dalaran    文件:LogUtils.java   
public static void print(Object toJson) {
    if (!ENABLED) return;

    synchronized (sGson) {
        String json = sGson.toJson(toJson);
        Iterable<String> lines = Splitter.on(CharMatcher.anyOf("\r\n")).omitEmptyStrings().split(json);

        int count = 0;
        Log.v(TAG, "┏");
        for (String line : lines) {
            Log.v(TAG, "┃   " + line);

            /**
             * delay the log output to avoid exceeding kernel log buffer size
             */
            if (count++ % 64 == 0) {
                try {
                    Thread.sleep(1);
                } catch (InterruptedException ignored) {
                }
            }
        }
        Log.v(TAG, "┗");
    }
}
项目:guava-mock    文件:ClassPath.java   
/**
 * Returns the simple name of the underlying class as given in the source code.
 *
 * <p>Behaves identically to {@link Class#getSimpleName()} but does not require the class to be
 * loaded.
 */
public String getSimpleName() {
  int lastDollarSign = className.lastIndexOf('$');
  if (lastDollarSign != -1) {
    String innerClassName = className.substring(lastDollarSign + 1);
    // local and anonymous classes are prefixed with number (1,2,3...), anonymous classes are
    // entirely numeric whereas local classes have the user supplied name as a suffix
    return CharMatcher.digit().trimLeadingFrom(innerClassName);
  }
  String packageName = getPackageName();
  if (packageName.isEmpty()) {
    return className;
  }

  // Since this is a top level class, its simple name is always the part after package name.
  return className.substring(packageName.length() + 1);
}
项目:guava-mock    文件:BaseEncoding.java   
@GwtIncompatible // Reader
static Reader ignoringReader(final Reader delegate, final CharMatcher toIgnore) {
  checkNotNull(delegate);
  checkNotNull(toIgnore);
  return new Reader() {
    @Override
    public int read() throws IOException {
      int readChar;
      do {
        readChar = delegate.read();
      } while (readChar != -1 && toIgnore.matches((char) readChar));
      return readChar;
    }

    @Override
    public int read(char[] cbuf, int off, int len) throws IOException {
      throw new UnsupportedOperationException();
    }

    @Override
    public void close() throws IOException {
      delegate.close();
    }
  };
}
项目:reflect    文件:PathFilter.java   
private static ImmutableSet<String> normalizePaths(
    ImmutableSet<String> paths, final boolean keepLeadingSlash) {
  return FluentIterable.from(paths)
      .transform(
          new Function<String, String>() {
            @Override
            public String apply(String s) {
              s = CharMatcher.whitespace().trimFrom(s);
              s = CharMatcher.is('/').trimFrom(s);
              int l = s.length();
              if (keepLeadingSlash) {
                s = "/" + s;
              }
              return l > 0 ? s + "/" : s;
            }
          })
      .toSet();
}
项目:Equella    文件:LDAP.java   
public Filter getUserSearchFilter(String query)
{
    SingleFilter personClass = new SingleFilter(OBJECTCLASS, personObject);
    personClass.setLimit(config.getSearchLimit());

    query = checkQuery(query);
    if( isSearchAllQuery(query) )
    {
        return personClass;
    }

    AndFilter and = new AndFilter(personClass);
    for( String token : Splitter.onPattern("\\s").omitEmptyStrings().trimResults(CharMatcher.is('*')).split(query) )
    {
        token = (config.isWildcards() ? "*" : "") + token + '*';

        OrFilter or = new OrFilter();
        or.addFilter(new SingleFilter(usernameField, token, false));
        or.addFilter(new SingleFilter(firstnameField, token, false));
        or.addFilter(new SingleFilter(surnameField, token, false));

        and.addFilter(or);
    }
    return and;
}
项目:Equella    文件:LDAP.java   
public Filter getGroupSearchFilter(String query)
{
    SingleFilter groupClass = new SingleFilter(OBJECTCLASS, groupObject);
    groupClass.setLimit(config.getSearchLimit());

    query = checkQuery(query);
    if( isSearchAllQuery(query) )
    {
        return groupClass;
    }

    AndFilter and = new AndFilter(groupClass);
    for( String token : Splitter.onPattern("\\s").omitEmptyStrings().trimResults(CharMatcher.is('*')).split(query) )
    {
        token = (config.isWildcards() ? "*" : "") + token + '*';

        OrFilter or = new OrFilter();
        or.addFilter(new SingleFilter(groupNameField, token, false));
        or.addFilter(new SingleFilter(groupIdField, token, false));

        and.addFilter(or);
    }
    return and;
}
项目:javaide    文件:JavaCommentsHelper.java   
@Override
public String rewrite(Tok tok, int maxWidth, int column0) {
    if (!tok.isComment()) {
        return tok.getOriginalText();
    }
    String text = tok.getOriginalText();
    if (tok.isJavadocComment()) {
        text = JavadocFormatter.formatJavadoc(text, column0, options);
    }
    List<String> lines = new ArrayList<>();
    Iterator<String> it = Newlines.lineIterator(text);
    while (it.hasNext()) {
        lines.add(CharMatcher.whitespace().trimTrailingFrom(it.next()));
    }
    if (tok.isSlashSlashComment()) {
        return indentLineComments(lines, column0);
    } else if (javadocShaped(lines)) {
        return indentJavadoc(lines, column0);
    } else {
        return preserveIndentation(lines, column0);
    }
}
项目:javaide    文件:JavaCommentsHelper.java   
private List<String> wrapLineComments(
        List<String> lines, int column0, JavaFormatterOptions options) {
    List<String> result = new ArrayList<>();
    for (String line : lines) {
        // Add missing leading spaces to line comments: `//foo` -> `// foo`
        if (!line.startsWith("// ")) {
            line = "// " + line.substring("//".length());
        }
        while (line.length() + column0 > options.maxLineLength()) {
            int idx = options.maxLineLength() - column0;
            // only break on whitespace characters, and ignore the leading `// `
            while (idx >= 2 && !CharMatcher.whitespace().matches(line.charAt(idx))) {
                idx--;
            }
            if (idx <= 2) {
                break;
            }
            result.add(line.substring(0, idx));
            line = "//" + line.substring(idx);
        }
        result.add(line);
    }
    return result;
}
项目:hadoop    文件:WebApp.java   
static String getPrefix(String pathSpec) {
  int start = 0;
  while (CharMatcher.WHITESPACE.matches(pathSpec.charAt(start))) {
    ++start;
  }
  if (pathSpec.charAt(start) != '/') {
    throw new WebAppException("Path spec syntax error: "+ pathSpec);
  }
  int ci = pathSpec.indexOf(':');
  if (ci == -1) {
    ci = pathSpec.length();
  }
  if (ci == 1) {
    return "/";
  }
  char c;
  do {
    c = pathSpec.charAt(--ci);
  } while (c == '/' || CharMatcher.WHITESPACE.matches(c));
  return pathSpec.substring(start, ci + 1);
}
项目:hadoop    文件:ApplicationSubmissionContextPBImpl.java   
private void checkTags(Set<String> tags) {
  if (tags.size() > YarnConfiguration.APPLICATION_MAX_TAGS) {
    throw new IllegalArgumentException("Too many applicationTags, a maximum of only "
        + YarnConfiguration.APPLICATION_MAX_TAGS + " are allowed!");
  }
  for (String tag : tags) {
    if (tag.length() > YarnConfiguration.APPLICATION_MAX_TAG_LENGTH) {
      throw new IllegalArgumentException("Tag " + tag + " is too long, " +
          "maximum allowed length of a tag is " +
          YarnConfiguration.APPLICATION_MAX_TAG_LENGTH);
    }
    if (!CharMatcher.ASCII.matchesAllOf(tag)) {
      throw new IllegalArgumentException("A tag can only have ASCII " +
          "characters! Invalid tag - " + tag);
    }
  }
}
项目:graphiak    文件:GraphiteMetricDecoder.java   
@Nullable
public static GraphiteMetric decode(@Nullable final String metric) {
    if (metric == null || metric.isEmpty()) {
        return null;
    }

    final List<String> parts = Splitter.on(CharMatcher.BREAKING_WHITESPACE)
            .trimResults().omitEmptyStrings().splitToList(metric);
    if (parts.isEmpty() || parts.size() != 3) {
        return null;
    }

    final double value = Double.parseDouble(parts.get(1));
    final long timestamp = Long.parseUnsignedLong(parts.get(2));

    return new GraphiteMetric(parts.get(0), value, timestamp);
}
项目:googles-monorepo-demo    文件:ClassPath.java   
/**
 * Returns the simple name of the underlying class as given in the source code.
 *
 * <p>Behaves identically to {@link Class#getSimpleName()} but does not require the class to be
 * loaded.
 */
public String getSimpleName() {
  int lastDollarSign = className.lastIndexOf('$');
  if (lastDollarSign != -1) {
    String innerClassName = className.substring(lastDollarSign + 1);
    // local and anonymous classes are prefixed with number (1,2,3...), anonymous classes are
    // entirely numeric whereas local classes have the user supplied name as a suffix
    return CharMatcher.digit().trimLeadingFrom(innerClassName);
  }
  String packageName = getPackageName();
  if (packageName.isEmpty()) {
    return className;
  }

  // Since this is a top level class, its simple name is always the part after package name.
  return className.substring(packageName.length() + 1);
}
项目:googles-monorepo-demo    文件:BaseEncoding.java   
@GwtIncompatible // Reader
static Reader ignoringReader(final Reader delegate, final CharMatcher toIgnore) {
  checkNotNull(delegate);
  checkNotNull(toIgnore);
  return new Reader() {
    @Override
    public int read() throws IOException {
      int readChar;
      do {
        readChar = delegate.read();
      } while (readChar != -1 && toIgnore.matches((char) readChar));
      return readChar;
    }

    @Override
    public int read(char[] cbuf, int off, int len) throws IOException {
      throw new UnsupportedOperationException();
    }

    @Override
    public void close() throws IOException {
      delegate.close();
    }
  };
}
项目:dremio-oss    文件:DistributionLoader.java   
private static Map<String, Distribution> loadDistributions(Iterator<String> lines)
{
    ImmutableMap.Builder<String, Distribution> distributions = ImmutableMap.builder();
    while (lines.hasNext()) {
        // advance to "begin"
        String line = lines.next();
        List<String> parts = ImmutableList.copyOf(Splitter.on(CharMatcher.WHITESPACE).omitEmptyStrings().split(line));
        if (parts.size() != 2) {
            continue;
        }


        if (parts.get(0).equalsIgnoreCase("BEGIN")) {
            String name = parts.get(1);
            Distribution distribution = loadDistribution(lines, name);
            distributions.put(name.toLowerCase(), distribution);
        }
    }
    return distributions.build();
}
项目:aliyun-oss-hadoop-fs    文件:ApplicationSubmissionContextPBImpl.java   
private void checkTags(Set<String> tags) {
  if (tags.size() > YarnConfiguration.APPLICATION_MAX_TAGS) {
    throw new IllegalArgumentException("Too many applicationTags, a maximum of only "
        + YarnConfiguration.APPLICATION_MAX_TAGS + " are allowed!");
  }
  for (String tag : tags) {
    if (tag.length() > YarnConfiguration.APPLICATION_MAX_TAG_LENGTH) {
      throw new IllegalArgumentException("Tag " + tag + " is too long, " +
          "maximum allowed length of a tag is " +
          YarnConfiguration.APPLICATION_MAX_TAG_LENGTH);
    }
    if (!CharMatcher.ASCII.matchesAllOf(tag)) {
      throw new IllegalArgumentException("A tag can only have ASCII " +
          "characters! Invalid tag - " + tag);
    }
  }
}
项目:dsl-devkit    文件:AbstractFragmentProvider.java   
/**
 * Unescapes the given escape characters contained in the given text.
 * <p>
 * Reserved characters for e.g. segment and list separation cannot be used by custom fragment providers unless escaped, i.e. prefixed with a '\'. Such URI
 * segments need to be escaped when forming the URI fragment, and consequently unescaped when reading the URI segments.
 * </p>
 *
 * @param text
 *          the text to unescape, must not be {@code null}
 * @param charactersToEscape
 *          the characters to escape, must not be {@code null}
 * @return the unescaped text, never {@code null}
 */
protected String unescape(final String text, final CharMatcher charactersToEscape) {
  if (CharMatcher.NONE.equals(charactersToEscape)) {
    return text;
  }
  final StringBuilder result = new StringBuilder(text.length());
  int lastIndex = 0;
  boolean escaped = false;
  for (int index = 0; index < text.length(); index++) {
    char character = text.charAt(index);
    if (escaped) {
      escaped = false;
      if (charactersToEscape.matches(character)) {
        result.append(text.substring(lastIndex, index - 1)).append(character);
        lastIndex = index + 1;
      }
    } else if (character == ESCAPE_CHARACTER) {
      escaped = true;
    }
  }
  if (result.length() == 0) {
    return text;
  }
  result.append(text.substring(lastIndex));
  return result.toString();
}
项目:greenbeans    文件:EntityReferences.java   
private static ListMultimap<String, String> readEntityReferences() {
    ImmutableListMultimap.Builder<String, String> builder = ImmutableListMultimap.builder();
    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                EntityReferences.class.getResourceAsStream("entity-references.txt"), Charsets.UTF_8)); //$NON-NLS-1$
        try {
            Splitter splitter = Splitter.on(CharMatcher.WHITESPACE).trimResults().omitEmptyStrings();

            String line;
            while ((line = reader.readLine()) != null) {
                List<String> lineItems = splitter.splitToList(line);
                checkState(lineItems.size() > 1);
                for (int x = 1; x < lineItems.size(); ++x) {
                    builder.put(lineItems.get(0), lineItems.get(x));
                }
            }
        } finally {
            reader.close();
        }
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
    return builder.build();
}
项目:nomulus    文件:ContactFlowUtils.java   
/** Check that an internationalized postal info has only ascii characters. */
static void validateAsciiPostalInfo(@Nullable PostalInfo internationalized) throws EppException {
  if (internationalized != null) {
    Preconditions.checkState(INTERNATIONALIZED.equals(internationalized.getType()));
    ContactAddress address = internationalized.getAddress();
    Set<String> fields = Sets.newHashSet(
        internationalized.getName(),
        internationalized.getOrg(),
        address.getCity(),
        address.getCountryCode(),
        address.getState(),
        address.getZip());
    fields.addAll(address.getStreet());
    for (String field : fields) {
      if (field != null && !CharMatcher.ascii().matchesAllOf(field)) {
        throw new BadInternationalizedPostalInfoException();
      }
    }
  }
}
项目:big-c    文件:WebApp.java   
static String getPrefix(String pathSpec) {
  int start = 0;
  while (CharMatcher.WHITESPACE.matches(pathSpec.charAt(start))) {
    ++start;
  }
  if (pathSpec.charAt(start) != '/') {
    throw new WebAppException("Path spec syntax error: "+ pathSpec);
  }
  int ci = pathSpec.indexOf(':');
  if (ci == -1) {
    ci = pathSpec.length();
  }
  if (ci == 1) {
    return "/";
  }
  char c;
  do {
    c = pathSpec.charAt(--ci);
  } while (c == '/' || CharMatcher.WHITESPACE.matches(c));
  return pathSpec.substring(start, ci + 1);
}
项目:graylog-plugin-pipeline-processor    文件:KeyValue.java   
public KeyValue() {
    valueParam = string("value").description("The string to extract key/value pairs from").build();
    splitParam = string("delimiters", CharMatcher.class).transform(CharMatcher::anyOf).optional().description("The characters used to separate pairs, defaults to whitespace").build();
    valueSplitParam = string("kv_delimiters", CharMatcher.class).transform(CharMatcher::anyOf).optional().description("The characters used to separate keys from values, defaults to '='").build();

    ignoreEmptyValuesParam = bool("ignore_empty_values").optional().description("Whether to ignore keys with empty values, defaults to true").build();
    allowDupeKeysParam = bool("allow_dup_keys").optional().description("Whether to allow duplicate keys, defaults to true").build();
    duplicateHandlingParam = string("handle_dup_keys").optional().description("How to handle duplicate keys: 'take_first': only use first value, 'take_last': only take last value, default is to concatenate the values").build();
    trimCharactersParam = string("trim_key_chars", CharMatcher.class)
            .transform(CharMatcher::anyOf)
            .optional()
            .description("The characters to trim from keys, default is not to trim")
            .build();
    trimValueCharactersParam = string("trim_value_chars", CharMatcher.class)
            .transform(CharMatcher::anyOf)
            .optional()
            .description("The characters to trim from values, default is not to trim")
            .build();
}
项目:tablesaw    文件:CategoryColumn.java   
public CategoryColumn tokenizeAndRemoveDuplicates() {
    CategoryColumn newColumn = new CategoryColumn(name() + "[without duplicates]", this.size());

    for (int r = 0; r < size(); r++) {
        String value = get(r);

        Splitter splitter = Splitter.on(CharMatcher.whitespace());
        splitter = splitter.trimResults();
        splitter = splitter.omitEmptyStrings();
        List<String> tokens = new ArrayList<>(splitter.splitToList(value));

        value = String.join(" ", new HashSet<>(tokens));
        newColumn.add(value);
    }
    return newColumn;
}
项目:solr-analyzers    文件:AnalyzingSentenceTokenizer.java   
/**
 * Analyzes the sentence for stopwords appearances. It will remove whitespaces and symbols from the sentence to
 * guarantee a high stopwords match.
 * 
 * @param sentence
 *           Sentence to analyze.
 */
private SentenceStatistics analyzeSentence(CharSequence sentence) {
   // remove noise: trim, noise(|<>:;...), multiple whitespace and to lower
   String cleanSentence = WHITESPACE_PATTERN.matcher(SENTENCE_NOISE.removeFrom(
         CharMatcher.WHITESPACE.trimFrom(sentence))).replaceAll(" ")
         .toLowerCase(Locale.GERMAN);

   // split sentence into words
   Iterable<String> words = SPACE_SPLITTER.split(cleanSentence);
   int stopWordCount = 0;
   int wordCount = 0;
   for (String w : words) {
      if (stopWords.contains(w)) {
         stopWordCount++;
      }

      wordCount++;
   }

   // calculate ratio
   return new SentenceStatistics(wordCount, stopWordCount);
}
项目:codebuff    文件:ClassPath.java   
/**
 * Returns the simple name of the underlying class as given in the source code.
 *
 * <p>Behaves identically to {@link Class#getSimpleName()} but does not require the class to be
 * loaded.
 */


public String getSimpleName() {
  int lastDollarSign = className.lastIndexOf('$');
  if (lastDollarSign != -1) {
    String innerClassName = className.substring(lastDollarSign + 1);
    // local and anonymous classes are prefixed with number (1,2,3...), anonymous classes are
    // entirely numeric whereas local classes have the user supplied name as a suffix
    return CharMatcher.digit().trimLeadingFrom(innerClassName);
  }
  String packageName = getPackageName();
  if (packageName.isEmpty()) {
    return className;
  }

  // Since this is a top level class, its simple name is always the part after package name.
  return className.substring(packageName.length() + 1);
}
项目:codebuff    文件:BaseEncoding.java   
@GwtIncompatible // Reader
static Reader ignoringReader(
  final Reader delegate, final CharMatcher toIgnore) {
  checkNotNull(delegate);
  checkNotNull(toIgnore);
  return new Reader() {
    @Override
    public int read() throws IOException {
      int readChar;
      do {
        readChar = delegate.read();
      } while (readChar != -1 && toIgnore.matches((char) readChar));
      return readChar;
    }

    @Override
    public int read(char[] cbuf, int off, int len) throws IOException {
      throw new UnsupportedOperationException();
    }

    @Override
    public void close() throws IOException {
      delegate.close();
    }
  };
}
项目:codebuff    文件:BaseEncoding.java   
@GwtIncompatible // Reader
static Reader ignoringReader(final Reader delegate, final CharMatcher toIgnore) {
  checkNotNull(delegate);
  checkNotNull(toIgnore);
  return new Reader() {
    @Override
    public int read() throws IOException {
      int readChar;
      do {
        readChar = delegate.read();
      } while (readChar != -1 && toIgnore.matches((char) readChar));
      return readChar;
    }

    @Override
    public int read(char[] cbuf, int off, int len) throws IOException {
      throw new UnsupportedOperationException();
    }

    @Override
    public void close() throws IOException {
      delegate.close();
    }
  };
}
项目:xtext-core    文件:RuntimeProjectConfig.java   
/**
 * Returns the root-relative path of the folder where the generated .ecore and .genmodel can be found.
 * The path is delimited by '/', but does not begin or end with a separator.
 */
@Override
public String getEcoreModelFolder() {
  boolean _startsWith = this.ecoreModel.getPath().startsWith(this.getRoot().getPath());
  if (_startsWith) {
    final String relativePath = this.ecoreModel.getPath().substring(this.getRoot().getPath().length()).replace("\\", "/");
    return CharMatcher.is('/').trimFrom(relativePath);
  }
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("Could not derive the Ecore model folder from the project configuration. ");
  _builder.newLine();
  _builder.append("Please make sure that \'root\' is a prefix of \'ecoreModel\'.");
  _builder.newLine();
  _builder.append("was (root=\'");
  String _path = this.getRoot().getPath();
  _builder.append(_path);
  _builder.append("\', ecoreModel=\'");
  String _path_1 = this.ecoreModel.getPath();
  _builder.append(_path_1);
  _builder.append("\')");
  _builder.newLineIfNotEmpty();
  _builder.newLine();
  throw new RuntimeException(_builder.toString());
}
项目:codebuff    文件:ClassPath.java   
/**
 * Returns the simple name of the underlying class as given in the source code.
 *
 * <p>Behaves identically to {@link Class#getSimpleName()} but does not require the class to be
 * loaded.
 */


public String getSimpleName() {
  int lastDollarSign = className.lastIndexOf('$');
  if (lastDollarSign != -1) {
    String innerClassName = className.substring(lastDollarSign + 1);
    // local and anonymous classes are prefixed with number (1,2,3...), anonymous classes are
    // entirely numeric whereas local classes have the user supplied name as a suffix
    return CharMatcher.digit().trimLeadingFrom(innerClassName);
  }
  String packageName = getPackageName();
  if (packageName.isEmpty()) {
    return className;
  }

  // Since this is a top level class, its simple name is always the part after package name.
  return className.substring(packageName.length() + 1);
}
项目:rules_closure    文件:PersistentWorker.java   
private void loadArguments(boolean isWorker) {
  try {
    String lastArg = Iterables.getLast(arguments, "");
    if (lastArg.startsWith("@")) {
      Path flagFile = fs.getPath(CharMatcher.is('@').trimLeadingFrom(lastArg));
      if ((isWorker && lastArg.startsWith("@@")) || Files.exists(flagFile)) {
        arguments.clear();
        arguments.addAll(Files.readAllLines(flagFile, UTF_8));
      }
    } else {
      List<String> newArguments = new ArrayList<>();
      for (String argument : arguments) {
        if (argument.startsWith(FLAGFILE_ARG)) {
          newArguments.addAll(
              Files.readAllLines(fs.getPath(argument.substring(FLAGFILE_ARG.length())), UTF_8));
        }
      }
      if (!newArguments.isEmpty()) {
        arguments.clear();
        arguments.addAll(newArguments);
      }
    }
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}
项目:easyrec_major    文件:JSONProfileWebService.java   
private String checkItemType(String itemType, Integer coreTenantId, @Nullable String defaultValue, List<Message> messages) {
    if (itemType != null)
        itemType = CharMatcher.WHITESPACE.trimFrom(itemType);

    if (Strings.isNullOrEmpty(itemType))
        return defaultValue;
    else
        try {
            typeMappingService.getIdOfItemType(coreTenantId, itemType, true);

            return itemType;
        } catch (IllegalArgumentException ex) {
            messages.add(MSG.OPERATION_FAILED.append(String.format(" itemType %s not found for tenant", itemType)));
            return null;
        }
}
项目:codebuff    文件:ClassPath.java   
/**
 * Returns the simple name of the underlying class as given in the source code.
 *
 * <p>Behaves identically to {@link Class#getSimpleName()} but does not require the class to be
 * loaded.
 */


public String getSimpleName() {
  int lastDollarSign = className.lastIndexOf('$');
  if (lastDollarSign != -1) {
    String innerClassName = className.substring(lastDollarSign + 1);
    // local and anonymous classes are prefixed with number (1,2,3...), anonymous classes are
    // entirely numeric whereas local classes have the user supplied name as a suffix
    return CharMatcher.digit().trimLeadingFrom(innerClassName);
  }
  String packageName = getPackageName();
  if (packageName.isEmpty()) {
    return className;
  }

  // Since this is a top level class, its simple name is always the part after package name.
  return className.substring(packageName.length() + 1);
}
项目:codebuff    文件:BaseEncoding.java   
@GwtIncompatible // Reader
static Reader ignoringReader(
  final Reader delegate, final CharMatcher toIgnore) {
  checkNotNull(delegate);
  checkNotNull(toIgnore);
  return new Reader() {
    @Override
    public int read() throws IOException {
      int readChar;
      do {
        readChar = delegate.read();
      } while (readChar != -1 && toIgnore.matches((char) readChar));
      return readChar;
    }

    @Override
    public int read(char[] cbuf, int off, int len) throws IOException {
      throw new UnsupportedOperationException();
    }

    @Override
    public void close() throws IOException {
      delegate.close();
    }
  };
}
项目:nomulus    文件:LaunchNotice.java   
/**
 * 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();
  }
}
项目:codebuff    文件:ClassPath.java   
/**
 * Returns the simple name of the underlying class as given in the source code.
 *
 * <p>Behaves identically to {@link Class#getSimpleName()} but does not require the class to be
 * loaded.
 */


public String getSimpleName() {
  int lastDollarSign = className.lastIndexOf('$');
  if (lastDollarSign != -1) {
    String innerClassName = className.substring(lastDollarSign + 1);
    // local and anonymous classes are prefixed with number (1,2,3...), anonymous classes are
    // entirely numeric whereas local classes have the user supplied name as a suffix
    return CharMatcher.digit().trimLeadingFrom(innerClassName);
  }
  String packageName = getPackageName();
  if (packageName.isEmpty()) {
    return className;
  }

  // Since this is a top level class, its simple name is always the part after package name.
  return className.substring(packageName.length() + 1);
}
项目:codebuff    文件:ClassPath.java   
/**
 * Returns the simple name of the underlying class as given in the source code.
 *
 * <p>Behaves identically to {@link Class#getSimpleName()} but does not require the class to be
 * loaded.
 */
public String getSimpleName() {
  int lastDollarSign = className.lastIndexOf('$');
  if (lastDollarSign != -1) {
    String innerClassName = className.substring(lastDollarSign + 1);
    // local and anonymous classes are prefixed with number (1,2,3...), anonymous classes are
    // entirely numeric whereas local classes have the user supplied name as a suffix
    return CharMatcher.digit().trimLeadingFrom(innerClassName);
  }
  String packageName = getPackageName();
  if (packageName.isEmpty()) {
    return className;
  }

  // Since this is a top level class, its simple name is always the part after package name.
  return className.substring(packageName.length() + 1);
}
项目:GitHub    文件:MarshallingTest.java   
@Test
public void nullableMarshaling() {
  check(CharMatcher.WHITESPACE.removeFrom(Marshaling.toJson(ImmutableHasNullable.of())))
      .is("{}");
  check(Marshaling.fromJson("{}", ImmutableHasNullable.class)).is(ImmutableHasNullable.of());
  check(Marshaling.fromJson("{\"in\":1}", ImmutableHasNullable.class)).is(ImmutableHasNullable.of(1));
  check(Marshaling.fromJson("{\"def\":\"1\"}", ImmutableHasNullable.class)).is(ImmutableHasNullable.of().withDef("1"));
}
项目:GitHub    文件:Code.java   
private int whileMatches(int p, CharMatcher matcher) {
  for (;; p++) {
    if (!matcher.matches(get(p))) {
      return p;
    }
  }
}
项目:Machine-Learning-End-to-Endguide-for-Java-developers    文件:App (2).java   
public static String findReplaceGuava(String text){
    out.println(text);
    text = text.replace("me", " ");
    out.println("With double spaces: " + text);

      // trim whitespace at ends, and replace/collapse whitespace into single spaces
    String spaced = CharMatcher.WHITESPACE.trimAndCollapseFrom(text, ' ');
    out.println("With double spaces removed: " + spaced);
    String noDigits = CharMatcher.JAVA_DIGIT.replaceFrom(text, "*"); // star out all digits
    String lowerAndDigit = CharMatcher.JAVA_DIGIT.or(CharMatcher.JAVA_LOWER_CASE).retainFrom(text);
      // eliminate all characters that aren't digits or lowercase

    return text;
}
项目:tac-kbp-eal    文件:_CorpusQueryAssessments.java   
@Value.Check
protected void check() {
  checkArgument(queryReponses().containsAll(metadata().keySet()),
      "Metadata contained an unknown query; error in constructing the store!");
  checkArgument(queryReponses().containsAll(assessments().keySet()),
      "Assessments contained an unknown query; error in constructing the store!");
  checkArgument(queryReponses().equals(queryResponsesToSystemIDs().keySet()));
  final Iterable<String> systemIDStrings = transform(queryResponsesToSystemIDs().values(),
      desymbolizeFunction());
  checkArgument(all(systemIDStrings, not(isEmpty())), "System IDs may not be empty");
  checkArgument(all(systemIDStrings, not(anyCharMatches(CharMatcher.WHITESPACE))),
      "System IDs may not contain whitespace");
}