static {
   ImmutableSet.Builder<Integer> intValues = ImmutableSet.builder();
   // Add boundary values manually to avoid over/under flow (this covers 2^N for 0 and 31).
   intValues.add(Integer.MAX_VALUE - 1, Integer.MAX_VALUE);
   // Add values up to 40. This covers cases like "square of a prime" and such.
   for (int i = 1; i <= 40; i++) {
     intValues.add(i);
   }
   // Now add values near 2^N for lots of values of N.
   for (int exponent : asList(2, 3, 4, 9, 15, 16, 17, 24, 25, 30)) {
     int x = 1 << exponent;
     intValues.add(x, x + 1, x - 1);
   }
   intValues.add(9999).add(10000).add(10001).add(1000000); // near powers of 10
   intValues.add(5792).add(5793); // sqrt(2^25) rounded up and down
   POSITIVE_INTEGER_CANDIDATES = intValues.build();
   NEGATIVE_INTEGER_CANDIDATES =
       ImmutableList.copyOf(
           Iterables.concat(
               Iterables.transform(POSITIVE_INTEGER_CANDIDATES, NEGATE_INT),
               ImmutableList.of(Integer.MIN_VALUE)));
   NONZERO_INTEGER_CANDIDATES =
       ImmutableList.copyOf(
           Iterables.concat(POSITIVE_INTEGER_CANDIDATES, NEGATIVE_INTEGER_CANDIDATES));
   ALL_INTEGER_CANDIDATES = Iterables.concat(NONZERO_INTEGER_CANDIDATES, ImmutableList.of(0));
 }
示例#2
0
  private Iterable<Artifact> getFilteredProtoSources() {
    // Transform the well known proto artifacts by removing the external/bazel_tools prefix if
    // present. Otherwise the comparison for filtering out the well known types is not possible.
    ImmutableSet.Builder<PathFragment> wellKnownProtoPathsBuilder = new ImmutableSet.Builder<>();
    for (Artifact wellKnownProto : attributes.getWellKnownTypeProtos()) {
      PathFragment execPath = wellKnownProto.getExecPath();
      if (execPath.startsWith(BAZEL_TOOLS_PREFIX)) {
        wellKnownProtoPathsBuilder.add(execPath.relativeTo(BAZEL_TOOLS_PREFIX));
      } else {
        wellKnownProtoPathsBuilder.add(execPath);
      }
    }

    ImmutableSet<PathFragment> wellKnownProtoPaths = wellKnownProtoPathsBuilder.build();

    // Filter out the well known types from being sent to be generated, as these protos have already
    // been generated and linked in libprotobuf.a.
    ImmutableSet.Builder<Artifact> filteredProtos = new ImmutableSet.Builder<>();
    for (Artifact proto : getAllProtoSources()) {
      if (!wellKnownProtoPaths.contains(proto.getExecPath())) {
        filteredProtos.add(proto);
      }
    }

    return filteredProtos.build();
  }
    @Override
    public PlanNode visitIndexJoin(IndexJoinNode node, RewriteContext<Set<Symbol>> context) {
      ImmutableSet.Builder<Symbol> probeInputsBuilder = ImmutableSet.builder();
      probeInputsBuilder
          .addAll(context.get())
          .addAll(Iterables.transform(node.getCriteria(), IndexJoinNode.EquiJoinClause::getProbe));
      if (node.getProbeHashSymbol().isPresent()) {
        probeInputsBuilder.add(node.getProbeHashSymbol().get());
      }
      Set<Symbol> probeInputs = probeInputsBuilder.build();

      ImmutableSet.Builder<Symbol> indexInputBuilder = ImmutableSet.builder();
      indexInputBuilder
          .addAll(context.get())
          .addAll(Iterables.transform(node.getCriteria(), IndexJoinNode.EquiJoinClause::getIndex));
      if (node.getIndexHashSymbol().isPresent()) {
        indexInputBuilder.add(node.getIndexHashSymbol().get());
      }
      Set<Symbol> indexInputs = indexInputBuilder.build();

      PlanNode probeSource = context.rewrite(node.getProbeSource(), probeInputs);
      PlanNode indexSource = context.rewrite(node.getIndexSource(), indexInputs);

      return new IndexJoinNode(
          node.getId(),
          node.getType(),
          probeSource,
          indexSource,
          node.getCriteria(),
          node.getProbeHashSymbol(),
          node.getIndexHashSymbol());
    }
    @Override
    public PlanNode visitSemiJoin(SemiJoinNode node, RewriteContext<Set<Symbol>> context) {
      ImmutableSet.Builder<Symbol> sourceInputsBuilder = ImmutableSet.builder();
      sourceInputsBuilder.addAll(context.get()).add(node.getSourceJoinSymbol());
      if (node.getSourceHashSymbol().isPresent()) {
        sourceInputsBuilder.add(node.getSourceHashSymbol().get());
      }
      Set<Symbol> sourceInputs = sourceInputsBuilder.build();

      ImmutableSet.Builder<Symbol> filteringSourceInputBuilder = ImmutableSet.builder();
      filteringSourceInputBuilder.add(node.getFilteringSourceJoinSymbol());
      if (node.getFilteringSourceHashSymbol().isPresent()) {
        filteringSourceInputBuilder.add(node.getFilteringSourceHashSymbol().get());
      }
      Set<Symbol> filteringSourceInputs = filteringSourceInputBuilder.build();

      PlanNode source = context.rewrite(node.getSource(), sourceInputs);
      PlanNode filteringSource = context.rewrite(node.getFilteringSource(), filteringSourceInputs);

      return new SemiJoinNode(
          node.getId(),
          source,
          filteringSource,
          node.getSourceJoinSymbol(),
          node.getFilteringSourceJoinSymbol(),
          node.getSemiJoinOutput(),
          node.getSourceHashSymbol(),
          node.getFilteringSourceHashSymbol());
    }
    @Override
    public PlanNode visitJoin(JoinNode node, RewriteContext<Set<Symbol>> context) {
      ImmutableSet.Builder<Symbol> leftInputsBuilder = ImmutableSet.builder();
      leftInputsBuilder
          .addAll(context.get())
          .addAll(Iterables.transform(node.getCriteria(), JoinNode.EquiJoinClause::getLeft));
      if (node.getLeftHashSymbol().isPresent()) {
        leftInputsBuilder.add(node.getLeftHashSymbol().get());
      }
      Set<Symbol> leftInputs = leftInputsBuilder.build();

      ImmutableSet.Builder<Symbol> rightInputsBuilder = ImmutableSet.builder();
      rightInputsBuilder
          .addAll(context.get())
          .addAll(Iterables.transform(node.getCriteria(), JoinNode.EquiJoinClause::getRight));
      if (node.getRightHashSymbol().isPresent()) {
        rightInputsBuilder.add(node.getRightHashSymbol().get());
      }

      Set<Symbol> rightInputs = rightInputsBuilder.build();

      PlanNode left = context.rewrite(node.getLeft(), leftInputs);
      PlanNode right = context.rewrite(node.getRight(), rightInputs);

      return new JoinNode(
          node.getId(),
          node.getType(),
          left,
          right,
          node.getCriteria(),
          node.getLeftHashSymbol(),
          node.getRightHashSymbol());
    }
 private ImmutableSortedSet<BuildRule> getDexMergeDeps(
     UberRDotJava uberRDotJava, ImmutableSet<DexProducedFromJavaLibrary> preDexDeps) {
   ImmutableSet.Builder<BuildTarget> targets = ImmutableSet.builder();
   targets.add(uberRDotJava.getBuildTarget());
   for (DexProducedFromJavaLibrary preDex : preDexDeps) {
     targets.add(preDex.getBuildTarget());
   }
   return getTargetsAsRules(targets.build());
 }
 static {
   ImmutableSet.Builder<Double> integralBuilder = ImmutableSet.builder();
   ImmutableSet.Builder<Double> fractionalBuilder = ImmutableSet.builder();
   integralBuilder.addAll(Doubles.asList(0.0, -0.0, Double.MAX_VALUE, -Double.MAX_VALUE));
   // Add small multiples of MIN_VALUE and MIN_NORMAL
   for (int scale = 1; scale <= 4; scale++) {
     for (double d : Doubles.asList(Double.MIN_VALUE, Double.MIN_NORMAL)) {
       fractionalBuilder.add(d * scale).add(-d * scale);
     }
   }
   for (double d :
       Doubles.asList(
           0,
           1,
           2,
           7,
           51,
           102,
           Math.scalb(1.0, 53),
           Integer.MIN_VALUE,
           Integer.MAX_VALUE,
           Long.MIN_VALUE,
           Long.MAX_VALUE)) {
     for (double delta : Doubles.asList(0.0, 1.0, 2.0)) {
       integralBuilder.addAll(Doubles.asList(d + delta, d - delta, -d - delta, -d + delta));
     }
     for (double delta : Doubles.asList(0.01, 0.1, 0.25, 0.499, 0.5, 0.501, 0.7, 0.8)) {
       double x = d + delta;
       if (x != Math.round(x)) {
         fractionalBuilder.add(x);
       }
     }
   }
   INTEGRAL_DOUBLE_CANDIDATES = integralBuilder.build();
   fractionalBuilder.add(1.414).add(1.415).add(Math.sqrt(2));
   fractionalBuilder.add(5.656).add(5.657).add(4 * Math.sqrt(2));
   for (double d : INTEGRAL_DOUBLE_CANDIDATES) {
     double x = 1 / d;
     if (x != Math.rint(x)) {
       fractionalBuilder.add(x);
     }
   }
   FRACTIONAL_DOUBLE_CANDIDATES = fractionalBuilder.build();
   FINITE_DOUBLE_CANDIDATES =
       Iterables.concat(FRACTIONAL_DOUBLE_CANDIDATES, INTEGRAL_DOUBLE_CANDIDATES);
   POSITIVE_FINITE_DOUBLE_CANDIDATES =
       Iterables.filter(
           FINITE_DOUBLE_CANDIDATES,
           new Predicate<Double>() {
             @Override
             public boolean apply(Double input) {
               return input.doubleValue() > 0.0;
             }
           });
   DOUBLE_CANDIDATES_EXCEPT_NAN = Iterables.concat(FINITE_DOUBLE_CANDIDATES, INFINITIES);
   ALL_DOUBLE_CANDIDATES = Iterables.concat(DOUBLE_CANDIDATES_EXCEPT_NAN, asList(Double.NaN));
 }
 private ImmutableSortedSet<BuildRule> getDexMergeDeps(
     AaptPackageResources aaptPackageResources,
     ImmutableSet<DexProducedFromJavaLibrary> preDexDeps) {
   ImmutableSet.Builder<BuildTarget> targets = ImmutableSet.builder();
   targets.add(aaptPackageResources.getBuildTarget());
   for (DexProducedFromJavaLibrary preDex : preDexDeps) {
     targets.add(preDex.getBuildTarget());
   }
   return getTargetsAsRules(targets.build());
 }
  /**
   * Creates/finds the set of build rules that correspond to pre-dex'd artifacts that should be
   * merged to create the final classes.dex for the APK.
   *
   * <p>This method may modify {@code ruleResolver}, inserting new rules into its index.
   */
  @VisibleForTesting
  BuildRule createPreDexMergeRule(UberRDotJava uberRDotJava) {
    ImmutableSet.Builder<DexProducedFromJavaLibrary> preDexDeps = ImmutableSet.builder();
    ImmutableSet<JavaLibrary> transitiveJavaDeps =
        Classpaths.getClasspathEntries(originalDeps).keySet();
    for (JavaLibrary javaLibrary : transitiveJavaDeps) {
      // If the rule has no output file (which happens when a java_library has no srcs or
      // resources, but export_deps is true), then there will not be anything to dx.
      if (javaLibrary.getPathToOutputFile() == null) {
        continue;
      }

      // If the rule is in the no_dx list, then do not pre-dex it.
      if (buildRulesToExcludeFromDex.contains(javaLibrary.getBuildTarget())) {
        continue;
      }

      // See whether the corresponding IntermediateDexRule has already been added to the
      // ruleResolver.
      BuildTarget originalTarget = javaLibrary.getBuildTarget();
      BuildTarget preDexTarget =
          new BuildTarget(originalTarget.getBaseName(), originalTarget.getShortName(), DEX_FLAVOR);
      BuildRule preDexRule = ruleResolver.get(preDexTarget);
      if (preDexRule != null) {
        preDexDeps.add((DexProducedFromJavaLibrary) preDexRule.getBuildable());
        continue;
      }

      // Create the IntermediateDexRule and add it to both the ruleResolver and preDexDeps.
      DexProducedFromJavaLibrary preDex = new DexProducedFromJavaLibrary(preDexTarget, javaLibrary);
      buildRuleAndAddToIndex(
          preDex,
          BuildRuleType.PRE_DEX,
          preDexTarget,
          ImmutableSortedSet.of(ruleResolver.get(javaLibrary.getBuildTarget())));
      preDexDeps.add(preDex);
    }

    ImmutableSet<DexProducedFromJavaLibrary> allPreDexDeps = preDexDeps.build();

    BuildTarget buildTargetForDexMerge = createBuildTargetWithFlavor(DEX_MERGE_FLAVOR);
    PreDexMerge preDexMerge =
        new PreDexMerge(
            buildTargetForDexMerge, primaryDexPath, dexSplitMode, allPreDexDeps, uberRDotJava);
    BuildRule preDexMergeBuildRule =
        buildRuleAndAddToIndex(
            preDexMerge,
            BuildRuleType.DEX_MERGE,
            buildTargetForDexMerge,
            getDexMergeDeps(uberRDotJava, allPreDexDeps));

    return preDexMergeBuildRule;
  }
示例#10
0
 private Set<PlanNodeId> getNoMoreSplits() {
   ImmutableSet.Builder<PlanNodeId> noMoreSplits = ImmutableSet.builder();
   if (partitionedDriverFactory != null && partitionedDriverFactory.isNoMoreSplits()) {
     noMoreSplits.add(partitionedSourceId);
   }
   for (TaskSource taskSource : unpartitionedSources.values()) {
     if (taskSource.isNoMoreSplits()) {
       noMoreSplits.add(taskSource.getPlanNodeId());
     }
   }
   return noMoreSplits.build();
 }
  @Override
  public Iterable<BuildTarget> findDepsForTargetFromConstructorArgs(
      BuildTarget buildTarget, Arg constructorArg) {
    ImmutableSet.Builder<BuildTarget> deps = ImmutableSet.builder();

    deps.add(cxxBuckConfig.getPythonDep());

    if (constructorArg.lexSrcs.isPresent() && !constructorArg.lexSrcs.get().isEmpty()) {
      deps.add(cxxBuckConfig.getLexDep());
    }

    return deps.build();
  }
示例#12
0
 private Set<Type> getStandardPrimitiveTypes() {
   ImmutableSet.Builder<Type> builder = ImmutableSet.builder();
   // add unparametrized types
   builder.addAll(typeRegistry.getTypes());
   // add corner cases for parametrized types
   builder.add(createDecimalType(1, 0));
   builder.add(createDecimalType(17, 0));
   builder.add(createDecimalType(38, 0));
   builder.add(createDecimalType(17, 17));
   builder.add(createDecimalType(38, 38));
   builder.add(createVarcharType(0));
   builder.add(createUnboundedVarcharType());
   return builder.build();
 }
    @Override
    public PlanNode visitWindow(WindowNode node, RewriteContext<Set<Symbol>> context) {
      ImmutableSet.Builder<Symbol> expectedInputs =
          ImmutableSet.<Symbol>builder()
              .addAll(context.get())
              .addAll(node.getPartitionBy())
              .addAll(node.getOrderBy());

      if (node.getFrame().getStartValue().isPresent()) {
        expectedInputs.add(node.getFrame().getStartValue().get());
      }
      if (node.getFrame().getEndValue().isPresent()) {
        expectedInputs.add(node.getFrame().getEndValue().get());
      }

      if (node.getHashSymbol().isPresent()) {
        expectedInputs.add(node.getHashSymbol().get());
      }

      ImmutableMap.Builder<Symbol, Signature> functions = ImmutableMap.builder();
      ImmutableMap.Builder<Symbol, FunctionCall> functionCalls = ImmutableMap.builder();
      for (Map.Entry<Symbol, FunctionCall> entry : node.getWindowFunctions().entrySet()) {
        Symbol symbol = entry.getKey();

        if (context.get().contains(symbol)) {
          FunctionCall call = entry.getValue();
          expectedInputs.addAll(DependencyExtractor.extractUnique(call));

          functionCalls.put(symbol, call);
          functions.put(symbol, node.getSignatures().get(symbol));
        }
      }

      PlanNode source = context.rewrite(node.getSource(), expectedInputs.build());

      return new WindowNode(
          node.getId(),
          source,
          node.getPartitionBy(),
          node.getOrderBy(),
          node.getOrderings(),
          node.getFrame(),
          functionCalls.build(),
          functions.build(),
          node.getHashSymbol(),
          node.getPrePartitionedInputs(),
          node.getPreSortedOrderPrefix());
    }
 static {
   ImmutableSet.Builder<String> builder = ImmutableSet.builder();
   for (TrackerFilterEnum eventFilter : TrackerFilterEnum.values()) {
     builder.add(eventFilter.getValue());
   }
   valuesSet = builder.build();
 }
示例#15
0
 private void logHealthChecks() {
   final ImmutableSet.Builder<String> builder = ImmutableSet.builder();
   for (HealthCheck healthCheck : healthChecks.build()) {
     builder.add(healthCheck.getClass().getCanonicalName());
   }
   LOG.debug("health checks = {}", builder.build());
 }
示例#16
0
 private void logManagedObjects() {
   final ImmutableSet.Builder<String> builder = ImmutableSet.builder();
   for (Object bean : lifeCycle.getBeans()) {
     builder.add(bean.getClass().getCanonicalName());
   }
   LOG.debug("managed objects = {}", builder.build());
 }
示例#17
0
  private ImmutableSet<SimpleModule> getModules() {
    ImmutableSet.Builder<SimpleModule> builder = ImmutableSet.builder();

    // add custom support for Java 8 Date Times (the Jackson extension (v2.4.0) is de-serializing
    // the date as GMT)
    SimpleModule java8DateTimeModule = new SimpleModule(VERSION);
    java8DateTimeModule.addSerializer(ZonedDateTime.class, new ZonedDateTimeSerializer());
    java8DateTimeModule.addDeserializer(ZonedDateTime.class, new ZonedDateTimeDeserializer());
    builder.add(java8DateTimeModule);

    builder.add(
        new SimpleModule("JCR PropertyDefinition Module", VERSION)
            .addSerializer(new PropertyDefinitionSerializer()));

    return builder.build();
  }
  public static ImmutableSet<Path> createPackageLookupPathSet(IjModuleGraph moduleGraph) {
    ImmutableSet.Builder<Path> builder = ImmutableSet.builder();

    for (IjModule module : moduleGraph.getModuleNodes()) {
      for (IjFolder folder : module.getFolders()) {
        if (!folder.getWantsPackagePrefix()) {
          continue;
        }
        Optional<Path> firstJavaFile =
            FluentIterable.from(folder.getInputs())
                .filter(
                    new Predicate<Path>() {
                      @Override
                      public boolean apply(Path input) {
                        return input.getFileName().toString().endsWith(".java");
                      }
                    })
                .first();
        if (firstJavaFile.isPresent()) {
          builder.add(firstJavaFile.get());
        }
      }
    }

    return builder.build();
  }
  public ImmutableSet<CxxInferCapture> createInferCaptureBuildRules(
      ImmutableMap<String, CxxSource> sources,
      CxxInferTools inferTools,
      CxxInferSourceFilter sourceFilter) {

    ImmutableSet.Builder<CxxInferCapture> objects = ImmutableSet.builder();

    for (Map.Entry<String, CxxSource> entry : sources.entrySet()) {
      String name = entry.getKey();
      CxxSource source = entry.getValue();

      Preconditions.checkState(
          CxxSourceTypes.isPreprocessableType(source.getType()),
          "Only preprocessable source types are currently supported");

      if (sourceFilter.isBlacklisted(source)) {
        continue;
      }

      CxxInferCapture rule = requireInferCaptureBuildRule(name, source, inferTools);
      objects.add(rule);
    }

    return objects.build();
  }
 /**
  * Returns the configurable attribute conditions necessary to evaluate the given configured
  * target, or null if not all dependencies have yet been SkyFrame-evaluated.
  */
 @Nullable
 private Set<ConfigMatchingProvider> getConfigurableAttributeConditions(
     TargetAndConfiguration ctg, Environment env) {
   if (!(ctg.getTarget() instanceof Rule)) {
     return ImmutableSet.of();
   }
   Rule rule = (Rule) ctg.getTarget();
   RawAttributeMapper mapper = RawAttributeMapper.of(rule);
   Set<SkyKey> depKeys = new LinkedHashSet<>();
   for (Attribute attribute : rule.getAttributes()) {
     for (Label label : mapper.getConfigurabilityKeys(attribute.getName(), attribute.getType())) {
       if (!BuildType.Selector.isReservedLabel(label)) {
         depKeys.add(ConfiguredTargetValue.key(label, ctg.getConfiguration()));
       }
     }
   }
   Map<SkyKey, SkyValue> cts = env.getValues(depKeys);
   if (env.valuesMissing()) {
     return null;
   }
   ImmutableSet.Builder<ConfigMatchingProvider> conditions = ImmutableSet.builder();
   for (SkyValue ctValue : cts.values()) {
     ConfiguredTarget ct = ((ConfiguredTargetValue) ctValue).getConfiguredTarget();
     conditions.add(Preconditions.checkNotNull(ct.getProvider(ConfigMatchingProvider.class)));
   }
   return conditions.build();
 }
示例#21
0
 /** Get the safe path strings for a list of paths to use in the build variables. */
 private Collection<String> getSafePathStrings(Collection<PathFragment> paths) {
   ImmutableSet.Builder<String> result = ImmutableSet.builder();
   for (PathFragment path : paths) {
     result.add(path.getSafePathString());
   }
   return result.build();
 }
示例#22
0
  public ResponseLinking copyWithFilteredResponses(final Predicate<Response> toKeepCondition) {
    final Set<Response> newIncompletes = Sets.filter(incompleteResponses(), toKeepCondition);
    final ImmutableSet.Builder<ResponseSet> newResponseSetsB = ImmutableSet.builder();
    final ImmutableBiMap.Builder<String, ResponseSet> responseSetsIdB = ImmutableBiMap.builder();
    // to account for ResponseSets merging due to lost annotation
    final Set<ResponseSet> alreadyAdded = Sets.newHashSet();
    for (final ResponseSet responseSet : responseSets()) {
      final ImmutableSet<Response> okResponses =
          FluentIterable.from(responseSet.asSet()).filter(toKeepCondition).toSet();
      if (!okResponses.isEmpty()) {
        final ResponseSet newResponseSet = ResponseSet.from(okResponses);
        if (alreadyAdded.contains(newResponseSet)) {
          continue;
        }
        alreadyAdded.add(newResponseSet);
        newResponseSetsB.add(newResponseSet);
        if (responseSetIds().isPresent()) {
          responseSetsIdB.put(responseSetIds().get().inverse().get(responseSet), newResponseSet);
        }
      }
    }

    final ImmutableSet<ResponseSet> newResponseSets = newResponseSetsB.build();
    final ResponseLinking.Builder ret =
        ResponseLinking.builder()
            .docID(docID())
            .responseSets(newResponseSets)
            .incompleteResponses(newIncompletes);
    if (responseSetIds().isPresent()) {
      ret.responseSetIds(responseSetsIdB.build());
    }
    return ret.build();
  }
 static ImmutableSet<ObjectType> withPropertyRequired(Set<ObjectType> objs, String pname) {
   ImmutableSet.Builder<ObjectType> newObjs = ImmutableSet.builder();
   for (ObjectType obj : objs) {
     newObjs.add(obj.withPropertyRequired(pname));
   }
   return newObjs.build();
 }
  @Override
  public AnswerKey apply(AnswerKey input) {
    final Set<Response> existingResponses = Sets.newHashSet(input.allResponses());
    final ImmutableSet.Builder<AssessedResponse> newAssessedResponses = ImmutableSet.builder();
    newAssessedResponses.addAll(input.annotatedResponses());

    for (final AssessedResponse assessedResponse : input.annotatedResponses()) {
      if (assessedResponse.assessment().realis().isPresent()) {
        final Response responseWithAssessedRealis =
            assessedResponse
                .response()
                .copyWithSwappedRealis(assessedResponse.assessment().realis().get());
        if (!existingResponses.contains(responseWithAssessedRealis)) {
          newAssessedResponses.add(
              AssessedResponse.from(responseWithAssessedRealis, assessedResponse.assessment()));
          existingResponses.add(responseWithAssessedRealis);
        }
      }
    }

    return AnswerKey.from(
        input.docId(),
        newAssessedResponses.build(),
        input.unannotatedResponses(),
        input.corefAnnotation());
  }
示例#25
0
 static Set<UUID> extractIndexes(List<ShardIndexInfo> inputShards, int... indexes) {
   ImmutableSet.Builder<UUID> builder = ImmutableSet.builder();
   for (int index : indexes) {
     builder.add(inputShards.get(index).getShardUuid());
   }
   return builder.build();
 }
示例#26
0
  private ImmutableSet<AspectWithParameters> requiredAspects(
      AspectDefinition aspectDefinition,
      AspectParameters aspectParameters,
      Attribute attribute,
      Target target,
      Rule originalRule) {
    if (!(target instanceof Rule)) {
      return ImmutableSet.of();
    }

    Set<AspectWithParameters> aspectCandidates =
        extractAspectCandidates(aspectDefinition, aspectParameters, attribute, originalRule);
    RuleClass ruleClass = ((Rule) target).getRuleClassObject();
    ImmutableSet.Builder<AspectWithParameters> result = ImmutableSet.builder();
    for (AspectWithParameters candidateClass : aspectCandidates) {
      ConfiguredAspectFactory candidate =
          (ConfiguredAspectFactory) AspectFactory.Util.create(candidateClass.getAspectFactory());
      if (Sets.difference(
              candidate.getDefinition().getRequiredProviders(), ruleClass.getAdvertisedProviders())
          .isEmpty()) {
        result.add(candidateClass);
      }
    }
    return result.build();
  }
 static ImmutableSet<ObjectType> withoutProperty(Set<ObjectType> objs, QualifiedName qname) {
   ImmutableSet.Builder<ObjectType> newObjs = ImmutableSet.builder();
   for (ObjectType obj : objs) {
     newObjs.add(obj.withProperty(qname, null));
   }
   return newObjs.build();
 }
  /**
   * List the remote's {@link Ref refs}.
   *
   * @param getHeads whether to return refs in the {@code refs/heads} namespace
   * @param getTags whether to return refs in the {@code refs/tags} namespace
   * @return an immutable set of refs from the remote
   */
  @Override
  public ImmutableSet<Ref> listRefs(final boolean getHeads, final boolean getTags) {
    HttpURLConnection connection = null;
    ImmutableSet.Builder<Ref> builder = new ImmutableSet.Builder<Ref>();
    try {
      String expanded = repositoryURL.toString() + "/repo/manifest";
      connection = HttpUtils.connect(expanded);

      // Get Response
      InputStream is = HttpUtils.getResponseStream(connection);
      BufferedReader rd = new BufferedReader(new InputStreamReader(is));
      String line;
      try {
        while ((line = rd.readLine()) != null) {
          if ((getHeads && line.startsWith("refs/heads"))
              || (getTags && line.startsWith("refs/tags"))) {
            builder.add(HttpUtils.parseRef(line));
          }
        }
      } finally {
        rd.close();
      }

    } catch (Exception e) {
      throw Throwables.propagate(e);
    } finally {
      HttpUtils.consumeErrStreamAndCloseConnection(connection);
    }
    return builder.build();
  }
示例#29
0
 public static Set<Sort> of(Collection<org.kframework.kil.Sort> sorts) {
   ImmutableSet.Builder<Sort> builder = ImmutableSet.builder();
   for (org.kframework.kil.Sort name : sorts) {
     builder.add(Sort.of(name.getName()));
   }
   return builder.build();
 }
 private void ensureTagCache() {
   if (tagCache == null) {
     synchronized (this) {
       if (tagCache == null) {
         tagCache = new Long2ObjectOpenHashMap<List<String>>();
         ImmutableSet.Builder<String> vocabBuilder = ImmutableSet.builder();
         Cursor<String[]> lines = null;
         try {
           lines = new DelimitedTextCursor(tagFile, ",");
         } catch (FileNotFoundException e) {
           throw new DataAccessException("cannot open file", e);
         }
         try {
           for (String[] line : lines) {
             long mid = Long.parseLong(line[0]);
             List<String> tags = tagCache.get(mid);
             if (tags == null) {
               tags = new ArrayList<String>();
               tagCache.put(mid, tags);
             }
             tags.add(line[1]);
             vocabBuilder.add(line[1]);
           }
         } finally {
           lines.close();
         }
         vocabCache = vocabBuilder.build();
       }
     }
   }
 }