com.google.common.collect.Interner#intern ( )源码实例Demo

下面列出了com.google.common.collect.Interner#intern ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: neoscada   文件: ScriptMonitor.java
public ScriptMonitor ( final String id, final String factoryId, final Executor executor, final BundleContext context, final Interner<String> stringInterner, final EventProcessor eventProcessor, final ObjectPoolTracker<DataSource> dataSourcePoolTracker, final ObjectPoolTracker<MasterItem> masterItemPoolTracker, final ServiceTracker<ConfigurationAdministrator, ConfigurationAdministrator> caTracker )
{
    super ( id, factoryId, executor, context, stringInterner, eventProcessor );
    this.executor = executor;

    this.prefix = stringInterner.intern ( factoryId + ". " + id ); //$NON-NLS-1$

    this.classLoader = getClass ().getClassLoader ();

    this.monitorStateInjector = new MonitorStateInjector ( stringInterner );
    this.monitorStateInjector.setPrefix ( this.prefix );

    this.handler = new InjectMasterHandler ( id, masterItemPoolTracker, 0, caTracker, this.prefix, factoryId );
    this.listener = new MultiDataSourceListener ( dataSourcePoolTracker ) {

        @Override
        protected void handleChange ( final Map<String, DataSourceHandler> sources )
        {
            ScriptMonitor.this.handleChange ( sources );
        }
    };
}
 
源代码2 项目: bazel   文件: NinjaScope.java
private String computeExpandedString(
    long offset,
    String key,
    Map<String, String> cache,
    ImmutableSet<String> variablesToNotExpand,
    Interner<String> interner) {
  String cachedValue = cache.get(key);
  if (cachedValue != null) {
    return cachedValue;
  }
  if (variablesToNotExpand.contains(key)) {
    return null;
  }
  String expandedValue = findExpandedVariable(offset, key);
  // It's very important an interner is used here, as there is considerable duplication of
  // string literals in expanded rule-variable-parts over the course of a large build.
  return expandedValue == null ? null : interner.intern(expandedValue);
}
 
protected String getPrefixed ( final String id, final Interner<String> stringInterner )
{
    if ( id == null )
    {
        return this.prefix;
    }
    else
    {
        return stringInterner.intern ( this.dotPrefix + id );
    }
}
 
源代码4 项目: astor   文件: SourceMapConsumerV1.java
/**
 * Split the file into a filename/directory pair.
 *
 * @param interner The interner to use for interning the strings.
 * @param input The input to split.
 * @return The pair of directory, filename.
 */
private FileName splitFileName(
    Interner<String> interner, String input) {
  int hashIndex = input.lastIndexOf('/');
  String dir = interner.intern(input.substring(0, hashIndex + 1));
  String fileName = interner.intern(input.substring(hashIndex + 1));
  return new FileName(dir, fileName);
}
 
源代码5 项目: bazel   文件: RuleClass.java
/**
 * Converts the build-language-typed {@code buildLangValue} to a native value via {@link
 * BuildType#selectableConvert}. Canonicalizes the value's order if it is a {@link List} type and
 * {@code attr.isOrderIndependent()} returns {@code true}.
 *
 * <p>Throws {@link ConversionException} if the conversion fails, or if {@code buildLangValue} is
 * a selector expression but {@code attr.isConfigurable()} is {@code false}.
 */
private static Object convertFromBuildLangType(
    Rule rule,
    Attribute attr,
    Object buildLangValue,
    ImmutableMap<RepositoryName, RepositoryName> repositoryMapping,
    Interner<ImmutableList<?>> listInterner)
    throws ConversionException {
  LabelConversionContext context = new LabelConversionContext(rule.getLabel(), repositoryMapping);
  Object converted =
      BuildType.selectableConvert(
          attr.getType(),
          buildLangValue,
          new AttributeConversionContext(attr.getName(), rule.getRuleClass()),
          context);

  if ((converted instanceof SelectorList<?>) && !attr.isConfigurable()) {
    throw new ConversionException(
        String.format("attribute \"%s\" is not configurable", attr.getName()));
  }

  if (converted instanceof List<?>) {
    if (attr.isOrderIndependent()) {
      @SuppressWarnings("unchecked")
      List<? extends Comparable<?>> list = (List<? extends Comparable<?>>) converted;
      converted = Ordering.natural().sortedCopy(list);
    }
    // It's common for multiple rule instances in the same package to have the same value for some
    // attributes. As a concrete example, consider a package having several 'java_test' instances,
    // each with the same exact 'tags' attribute value.
    converted = listInterner.intern(ImmutableList.copyOf((List<?>) converted));
  }

  return converted;
}
 
源代码6 项目: buck   文件: MerkleTreeNodeCache.java
public MerkleTreeNode build(Interner<MerkleTreeNode> nodeInterner) {
  ImmutableSortedMap.Builder<Path, MerkleTreeNode> children = ImmutableSortedMap.naturalOrder();
  childrenBuilder.forEach(
      (key, value) ->
          children.put(
              key, value.transform(left -> left, builder -> builder.build(nodeInterner))));

  return nodeInterner.intern(
      new MerkleTreeNode(
          path,
          children.build(),
          ImmutableSortedMap.copyOf(filesBuilder),
          ImmutableSortedMap.copyOf(symlinksBuilder),
          ImmutableSortedMap.copyOf(emptyDirectoryBuilder)));
}
 
 同类方法