java类com.google.common.collect.ImmutableList.Builder的实例源码

AbstractCryptoConditionTest.java 文件源码 项目:java-crypto-conditions 阅读 23 收藏 0 点赞 0 评论 0
/**
 * Concurrently runs one or more instances of {@link Runnable} in a multithreaded fashion,
 * relying upon {@code numThreads} for concurrency.
 */
protected void runConcurrent(final int numThreads, final Runnable... runnableTest)
    throws InterruptedException {
  final Builder<Runnable> builder = ImmutableList.builder();

  // For each runnableTest, add it numThreads times to the bulider.
  for (final Runnable runnable : runnableTest) {
    for (int i = 0; i < numThreads; i++) {
      builder.add(runnable);
    }
  }

  logger.info(String.format("About to run %s threads...", numThreads));
  // Actually runs the Runnables above using multiple threads.
  assertConcurrent("Test did not complete before the harness timed-out. Please consider "
      + "increasing the timeout value for this test.", builder.build(), 15);
  logger.info(String.format("Ran %s threads!", numThreads));
}
AbstractSemanticRegionsFinder.java 文件源码 项目:xtext-core 阅读 19 收藏 0 点赞 0 评论 0
@Override
public List<Pair<ISemanticRegion, ISemanticRegion>> keywordPairs(Keyword kw1, Keyword kw2) {
    Preconditions.checkNotNull(kw1);
    Preconditions.checkNotNull(kw2);
    Preconditions.checkArgument(kw1 != kw2);
    Predicate<ISemanticRegion> p1 = createPredicate(kw1);
    Predicate<ISemanticRegion> p2 = createPredicate(kw2);
    List<ISemanticRegion> all = findAll(Predicates.or(p1, p2));
    Builder<Pair<ISemanticRegion, ISemanticRegion>> result = ImmutableList.builder();
    LinkedList<ISemanticRegion> stack = new LinkedList<ISemanticRegion>();
    for (ISemanticRegion region : all) {
        if (p1.apply(region))
            stack.push(region);
        else if (!stack.isEmpty())
            result.add(Pair.of(stack.pop(), region));
    }
    return result.build();
}
SearchMappingsServiceImpl.java 文件源码 项目:nexus-public 阅读 20 收藏 0 点赞 0 评论 0
private static Collection<SearchMapping> collectMappings(final Map<String, SearchMappings> searchMappings) {
  final Builder<SearchMapping> builder = ImmutableList.builder();

  // put the default mappings in first
  final SearchMappings defaultMappings = searchMappings.get(DEFAULT);
  if (defaultMappings != null) {
    builder.addAll(defaultMappings.get());
  }

  // add the rest of the mappings
  searchMappings.keySet().stream()
      .filter(key -> !DEFAULT.equals(key))
      .sorted()
      .forEach(key -> builder.addAll(searchMappings.get(key).get()));

  return builder.build();
}
ComponentManager.java 文件源码 项目:FinanceAnalytics 阅读 31 收藏 0 点赞 0 评论 0
/**
 * Intelligently sets the property.
 * <p>
 * This uses the repository to link properties declared with classifiers to the instance.
 * 
 * @param bean  the bean, not null
 * @param mp  the property, not null
 * @param value  the configured value, not null
 * @throws ComponentConfigException if the property cannot be initialized
 */
protected void setPropertyInferType(Bean bean, MetaProperty<?> mp, String value) {
  Class<?> propertyType = mp.propertyType();
  if (isConvertibleFromString(mp.propertyType())) {
    // set property by value type conversion from String
    mp.set(bean, convert(propertyType, value));

  } else if (Collection.class.isAssignableFrom(propertyType)) {
    // set property by value type conversion from comma separated String
    Class<?> collType = JodaBeanUtils.collectionType(mp, bean.getClass());
    if (isConvertibleFromString(collType)) {
      Iterable<String> split = Splitter.on(',').trimResults().split(value);
      Builder<Object> builder = ImmutableList.builder();
      for (String singleValue : split) {
        builder.add(convert(collType, singleValue));
      }
      mp.set(bean, builder.build());
    } else {
      throw new ComponentConfigException(String.format("No mechanism found to set collection property %s from value: %s", mp, value));
    }

  } else {
    throw new ComponentConfigException(String.format("No mechanism found to set property %s from value: %s", mp, value));
  }
}
XtaAction.java 文件源码 项目:theta 阅读 19 收藏 0 点赞 0 评论 0
private BasicXtaAction(final XtaSystem system, final List<Loc> sourceLocs, final Edge edge) {
    super(system, sourceLocs);
    this.edge = checkNotNull(edge);

    final ImmutableList.Builder<Loc> builder = ImmutableList.builder();
    final Loc source = edge.getSource();
    final Loc target = edge.getTarget();
    boolean matched = false;
    for (final Loc loc : sourceLocs) {
        if (loc.equals(source)) {
            checkArgument(!matched);
            builder.add(target);
            matched = true;
        } else {
            builder.add(loc);
        }
    }
    checkArgument(matched);
    targetLocs = builder.build();
}
XtaAction.java 文件源码 项目:theta 阅读 19 收藏 0 点赞 0 评论 0
@Override
public List<Stmt> getStmts() {
    List<Stmt> result = stmts;
    if (stmts == null) {
        final ImmutableList.Builder<Stmt> builder = ImmutableList.builder();
        addInvariants(builder, getSourceLocs());
        addGuards(builder, edge);
        addUpdates(builder, edge);
        addInvariants(builder, targetLocs);
        if (shouldApplyDelay(getTargetLocs())) {
            addDelay(builder, getClockVars());
        }
        result = builder.build();
        stmts = result;
    }
    return result;
}
XtaAction.java 文件源码 项目:theta 阅读 25 收藏 0 点赞 0 评论 0
@Override
public List<Stmt> getStmts() {
    List<Stmt> result = stmts;
    if (stmts == null) {
        final ImmutableList.Builder<Stmt> builder = ImmutableList.builder();
        addInvariants(builder, getSourceLocs());
        addSync(builder, emitEdge, recvEdge);
        addGuards(builder, emitEdge);
        addGuards(builder, recvEdge);
        addUpdates(builder, emitEdge);
        addUpdates(builder, recvEdge);
        addInvariants(builder, targetLocs);
        if (shouldApplyDelay(getTargetLocs())) {
            addDelay(builder, getClockVars());
        }
        result = builder.build();
        stmts = result;
    }
    return result;
}
DirHelper.java 文件源码 项目:broker-store 阅读 18 收藏 0 点赞 0 评论 0
public static List<String> dirList(String path){
    Builder<String> builder = ImmutableList.builder();
    File folder = new File(path);
    File[] files = folder.listFiles();
    if(files == null) {
        throw new NullPointerException();
    }
    for (File entry : files) {
        if (entry.isFile()) {
            builder.add("File : " + entry.getName());
        } else if (entry.isDirectory()) {
            builder.add("Directory : " + entry.getName());
        }
    }
    return builder.build();
}
Z3Model.java 文件源码 项目:java-smt 阅读 29 收藏 0 点赞 0 评论 0
@Override
protected ImmutableList<ValueAssignment> modelToList() {
  Builder<ValueAssignment> out = ImmutableList.builder();

  // Iterate through constants.
  for (int constIdx = 0; constIdx < Native.modelGetNumConsts(z3context, model); constIdx++) {
    long keyDecl = Native.modelGetConstDecl(z3context, model, constIdx);
    Native.incRef(z3context, keyDecl);
    out.addAll(getConstAssignments(keyDecl));
    Native.decRef(z3context, keyDecl);
  }

  // Iterate through function applications.
  for (int funcIdx = 0; funcIdx < Native.modelGetNumFuncs(z3context, model); funcIdx++) {
    long funcDecl = Native.modelGetFuncDecl(z3context, model, funcIdx);
    Native.incRef(z3context, funcDecl);
    if (!isInternalSymbol(funcDecl)) {
      String functionName = z3creator.symbolToString(Native.getDeclName(z3context, funcDecl));
      out.addAll(getFunctionAssignments(funcDecl, funcDecl, functionName));
    }
    Native.decRef(z3context, funcDecl);
  }

  return out.build();
}
Mathsat5Model.java 文件源码 项目:java-smt 阅读 19 收藏 0 点赞 0 评论 0
@Override
protected ImmutableList<ValueAssignment> modelToList() {
  Builder<ValueAssignment> assignments = ImmutableList.builder();

  long modelIterator = msat_model_create_iterator(model);
  while (msat_model_iterator_has_next(modelIterator)) {
    long[] key = new long[1];
    long[] value = new long[1];
    if (msat_model_iterator_next(modelIterator, key, value)) {
      throw new NoSuchElementException();
    }

    if (msat_is_array_type(creator.getEnv(), msat_term_get_type(value[0]))) {
      assignments.addAll(getArrayAssignments(key[0], key[0], value[0], Collections.emptyList()));
    } else {
      assignments.add(getAssignment(key[0], value[0]));
    }
  }
  msat_destroy_model_iterator(modelIterator);
  return assignments.build();
}


问题


面经


文章

微信
公众号

扫码关注公众号