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


Java CharMatcher類代碼示例

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


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

示例1: readSourceSuperclass

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

示例2: QuoteFilter

import com.google.common.base.CharMatcher; //導入依賴的package包/類
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);
  }
}
 
開發者ID:isi-nlp,項目名稱:tac-kbp-eal,代碼行數:18,代碼來源:QuoteFilter.java

示例3: print

import com.google.common.base.CharMatcher; //導入依賴的package包/類
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, "┗");
    }
}
 
開發者ID:killnono,項目名稱:Dalaran,代碼行數:26,代碼來源:LogUtils.java

示例4: getSimpleName

import com.google.common.base.CharMatcher; //導入依賴的package包/類
/**
 * 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);
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:23,代碼來源:ClassPath.java

示例5: ignoringReader

import com.google.common.base.CharMatcher; //導入依賴的package包/類
@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();
    }
  };
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:26,代碼來源:BaseEncoding.java

示例6: normalizePaths

import com.google.common.base.CharMatcher; //導入依賴的package包/類
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();
}
 
開發者ID:wangyuntao,項目名稱:reflect,代碼行數:19,代碼來源:PathFilter.java

示例7: getUserSearchFilter

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

示例8: getGroupSearchFilter

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

示例9: rewrite

import com.google.common.base.CharMatcher; //導入依賴的package包/類
@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);
    }
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:23,代碼來源:JavaCommentsHelper.java

示例10: wrapLineComments

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

示例11: getPrefix

import com.google.common.base.CharMatcher; //導入依賴的package包/類
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);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:22,代碼來源:WebApp.java

示例12: checkTags

import com.google.common.base.CharMatcher; //導入依賴的package包/類
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);
    }
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:18,代碼來源:ApplicationSubmissionContextPBImpl.java

示例13: decode

import com.google.common.base.CharMatcher; //導入依賴的package包/類
@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);
}
 
開發者ID:smoketurner,項目名稱:graphiak,代碼行數:18,代碼來源:GraphiteMetricDecoder.java

示例14: loadDistributions

import com.google.common.base.CharMatcher; //導入依賴的package包/類
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();
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:21,代碼來源:DistributionLoader.java

示例15: unescape

import com.google.common.base.CharMatcher; //導入依賴的package包/類
/**
 * 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();
}
 
開發者ID:dsldevkit,項目名稱:dsl-devkit,代碼行數:39,代碼來源:AbstractFragmentProvider.java


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