private ResolvedTargets<Void> getTargetsInPackage(
     String originalPattern, PathFragment packageNameFragment, FilteringPolicy policy)
     throws TargetParsingException, InterruptedException {
   TargetPatternResolverUtil.validatePatternPackage(originalPattern, packageNameFragment, this);
   try {
     PackageIdentifier packageId = PackageIdentifier.createInDefaultRepo(packageNameFragment);
     Package pkg = packageProvider.getPackage(env.getListener(), packageId);
     ResolvedTargets<Target> packageTargets =
         TargetPatternResolverUtil.resolvePackageTargets(pkg, policy);
     ImmutableList.Builder<SkyKey> builder = ImmutableList.builder();
     for (Target target : packageTargets.getTargets()) {
       builder.add(TransitiveTraversalValue.key(target.getLabel()));
     }
     ImmutableList<SkyKey> skyKeys = builder.build();
     env.getValuesOrThrow(skyKeys, NoSuchPackageException.class, NoSuchTargetException.class);
     if (env.valuesMissing()) {
       throw new MissingDepException();
     }
     return ResolvedTargets.empty();
   } catch (NoSuchThingException e) {
     String message =
         TargetPatternResolverUtil.getParsingErrorMessage(
             "package contains errors", originalPattern);
     throw new TargetParsingException(message, e);
   }
 }
Пример #2
0
 /** @return the current stack trace as a list of functions. */
 public ImmutableList<BaseFunction> getStackTrace() {
   ImmutableList.Builder<BaseFunction> builder = new ImmutableList.Builder<>();
   for (Continuation k = continuation; k != null; k = k.continuation) {
     builder.add(k.function);
   }
   return builder.build().reverse();
 }
Пример #3
0
  public static Optional<TypeSignature> getCommonSuperTypeSignature(
      TypeSignature firstType, TypeSignature secondType) {
    // Special handling for UnknownType is necessary because we forbid cast between types with
    // different number of type parameters.
    // Without this, cast from null to map<bigint, bigint> will not be allowed.
    if (UnknownType.NAME.equals(firstType.getBase())) {
      return Optional.of(secondType);
    }
    if (UnknownType.NAME.equals(secondType.getBase())) {
      return Optional.of(firstType);
    }

    List<TypeSignatureParameter> firstTypeTypeParameters = firstType.getParameters();
    List<TypeSignatureParameter> secondTypeTypeParameters = secondType.getParameters();
    if (firstTypeTypeParameters.size() != secondTypeTypeParameters.size()) {
      return Optional.empty();
    }

    Optional<String> commonSuperTypeBase =
        getCommonSuperTypeBase(firstType.getBase(), secondType.getBase());
    if (!commonSuperTypeBase.isPresent()) {
      return Optional.empty();
    }

    ImmutableList.Builder<TypeSignatureParameter> typeParameters = ImmutableList.builder();
    for (int i = 0; i < firstTypeTypeParameters.size(); i++) {
      TypeSignatureParameter firstParameter = firstTypeTypeParameters.get(i);
      TypeSignatureParameter secondParameter = secondTypeTypeParameters.get(i);

      if (firstParameter.getKind() == secondParameter.getKind()
          && firstParameter.getKind() == ParameterKind.LONG_LITERAL) {
        typeParameters.add(
            TypeSignatureParameter.of(
                Math.max(firstParameter.getLongLiteral(), secondParameter.getLongLiteral())));
      } else if (isCovariantParameterPosition(commonSuperTypeBase.get(), i)) {
        Optional<TypeSignature> firstParameterSignature =
            firstParameter.getTypeSignatureOrNamedTypeSignature();
        Optional<TypeSignature> secondParameterSignature =
            secondParameter.getTypeSignatureOrNamedTypeSignature();
        if (!firstParameterSignature.isPresent() || !secondParameterSignature.isPresent()) {
          return Optional.empty();
        }

        Optional<TypeSignature> commonSuperType =
            getCommonSuperTypeSignature(
                firstParameterSignature.get(), secondParameterSignature.get());
        if (!commonSuperType.isPresent()) {
          return Optional.empty();
        }
        typeParameters.add(TypeSignatureParameter.of(commonSuperType.get()));
      } else {
        if (!firstParameter.equals(secondParameter)) {
          return Optional.empty();
        }
        typeParameters.add(firstParameter);
      }
    }

    return Optional.of(new TypeSignature(commonSuperTypeBase.get(), typeParameters.build()));
  }
Пример #4
0
 public static ImmutableList<Mod> split(String cs) {
   ImmutableList.Builder<Mod> builder = ImmutableList.builder();
   for (String ms : Splitters.csplitter(cs)) {
     builder.add(Mod.parseMod(ms));
   }
   return builder.build();
 }
Пример #5
0
 @Override
 public Long2ObjectMap<List<Event>> get() {
   Long2ObjectMap<ImmutableList.Builder<Event>> table =
       new Long2ObjectOpenHashMap<ImmutableList.Builder<Event>>();
   Cursor<Event> events = eventDAO.streamEvents();
   try {
     for (Event evt : events) {
       final long iid = evt.getItemId();
       ImmutableList.Builder<Event> list = table.get(iid);
       if (list == null) {
         list = new ImmutableList.Builder<Event>();
         table.put(iid, list);
       }
       list.add(evt);
     }
   } finally {
     events.close();
   }
   Long2ObjectMap<List<Event>> result = new Long2ObjectOpenHashMap<List<Event>>(table.size());
   for (Long2ObjectMap.Entry<ImmutableList.Builder<Event>> evt : table.long2ObjectEntrySet()) {
     result.put(evt.getLongKey(), evt.getValue().build());
     evt.setValue(null);
   }
   return result;
 }
Пример #6
0
  private int executeCCompilation(
      ExecutionContext context, ImmutableList.Builder<Path> linkerInputs)
      throws IOException, InterruptedException {

    ImmutableList.Builder<String> cCompileFlags = ImmutableList.builder();
    cCompileFlags.addAll(ocamlContext.getCCompileFlags());
    cCompileFlags.addAll(ocamlContext.getCommonCFlags());

    CxxPreprocessorInput cxxPreprocessorInput = ocamlContext.getCxxPreprocessorInput();

    for (SourcePath cSrc : ocamlContext.getCInput()) {
      Path outputPath = ocamlContext.getCOutput(resolver.getAbsolutePath(cSrc));
      linkerInputs.add(outputPath);
      Step compileStep =
          new OCamlCCompileStep(
              resolver,
              filesystem.getRootPath(),
              new OCamlCCompileStep.Args(
                  cCompilerEnvironment,
                  cCompiler,
                  ocamlContext.getOcamlCompiler().get(),
                  outputPath,
                  cSrc,
                  cCompileFlags.build(),
                  ImmutableMap.copyOf(cxxPreprocessorInput.getIncludes().getNameToPathMap())));
      int compileExitCode = compileStep.execute(context);
      if (compileExitCode != 0) {
        return compileExitCode;
      }
    }
    return 0;
  }
Пример #7
0
 /**
  * @author gabizou - February 7th, 2016
  *     <p>This will short circuit all other patches such that we control the entities being loaded
  *     by chunkloading and can throw our bulk entity event. This will bypass Forge's hook for
  *     individual entity events, but the SpongeModEventManager will still successfully throw the
  *     appropriate event and cancel the entities otherwise contained.
  * @param entities The entities being loaded
  * @param callbackInfo The callback info
  */
 @Final
 @Inject(method = "loadEntities", at = @At("HEAD"), cancellable = true)
 private void spongeLoadEntities(
     Collection<net.minecraft.entity.Entity> entities, CallbackInfo callbackInfo) {
   if (entities.isEmpty()) {
     // just return, no entities to load!
     callbackInfo.cancel();
     return;
   }
   List<Entity> entityList = new ArrayList<>();
   ImmutableList.Builder<EntitySnapshot> snapshotBuilder = ImmutableList.builder();
   for (net.minecraft.entity.Entity entity : entities) {
     entityList.add((Entity) entity);
     snapshotBuilder.add(((Entity) entity).createSnapshot());
   }
   SpawnCause cause = SpawnCause.builder().type(InternalSpawnTypes.CHUNK_LOAD).build();
   List<NamedCause> causes = new ArrayList<>();
   causes.add(NamedCause.source(cause));
   causes.add(NamedCause.of("World", this));
   SpawnEntityEvent.ChunkLoad chunkLoad =
       SpongeEventFactory.createSpawnEntityEventChunkLoad(
           Cause.of(causes), entityList, snapshotBuilder.build(), this);
   SpongeImpl.postEvent(chunkLoad);
   if (!chunkLoad.isCancelled()) {
     for (Entity successful : chunkLoad.getEntities()) {
       this.loadedEntityList.add((net.minecraft.entity.Entity) successful);
       this.onEntityAdded((net.minecraft.entity.Entity) successful);
     }
   }
   callbackInfo.cancel();
 }
Пример #8
0
  private static List<Type> parameterTypes(TypeManager typeManager, Method method) {
    Annotation[][] parameterAnnotations = method.getParameterAnnotations();

    ImmutableList.Builder<Type> types = ImmutableList.builder();
    for (int i = 0; i < method.getParameterTypes().length; i++) {
      Class<?> clazz = method.getParameterTypes()[i];
      // skip session parameters
      if (clazz == ConnectorSession.class) {
        continue;
      }

      // find the explicit type annotation if present
      SqlType explicitType = null;
      for (Annotation annotation : parameterAnnotations[i]) {
        if (annotation instanceof SqlType) {
          explicitType = (SqlType) annotation;
          break;
        }
      }
      checkArgument(
          explicitType != null,
          "Method %s argument %s does not have a @SqlType annotation",
          method,
          i);
      types.add(type(typeManager, explicitType));
    }
    return types.build();
  }
Пример #9
0
 private static List<Parameter> toBlockParameters(List<Integer> inputChannels) {
   ImmutableList.Builder<Parameter> parameters = ImmutableList.builder();
   for (int channel : inputChannels) {
     parameters.add(arg("block_" + channel, Block.class));
   }
   return parameters.build();
 }
Пример #10
0
  @Override
  public ImmutableList<ServiceDescriptor> getServiceInventory(Iterable<SlotStatus> allSlotStatus) {
    ImmutableList.Builder<ServiceDescriptor> newDescriptors = ImmutableList.builder();
    for (SlotStatus slotStatus : allSlotStatus) {
      // if the self reference is null, the slot is totally offline so skip for now
      if (slotStatus.getSelf() == null) {
        continue;
      }

      List<ServiceDescriptor> serviceDescriptors = getServiceInventory(slotStatus);
      if (serviceDescriptors == null) {
        continue;
      }
      for (ServiceDescriptor serviceDescriptor : serviceDescriptors) {
        newDescriptors.add(
            new ServiceDescriptor(
                null,
                slotStatus.getId().toString(),
                serviceDescriptor.getType(),
                serviceDescriptor.getPool(),
                slotStatus.getLocation(),
                slotStatus.getState() == SlotLifecycleState.RUNNING
                    ? ServiceState.RUNNING
                    : ServiceState.STOPPED,
                interpolateProperties(serviceDescriptor.getProperties(), slotStatus)));
      }
    }
    return newDescriptors.build();
  }
Пример #11
0
    public ParallelQueryRunner(
        int maxParallelism, URI server, String catalog, String schema, boolean debug) {
      executor =
          listeningDecorator(
              newCachedThreadPool(
                  new ThreadFactoryBuilder()
                      .setNameFormat("query-runner-%s")
                      .setDaemon(true)
                      .build()));

      ImmutableList.Builder<QueryRunner> runners = ImmutableList.builder();
      for (int i = 0; i < maxParallelism; i++) {
        ClientSession session =
            new ClientSession(
                server,
                "test-" + i,
                "presto-perf",
                catalog,
                schema,
                TimeZone.getDefault().getID(),
                Locale.getDefault(),
                debug);
        runners.add(new QueryRunner(session, executor));
      }
      this.runners = runners.build();
    }
 private List<KnapsackState> get(String name) throws IOException {
   ImmutableList.Builder<KnapsackState> builder = ImmutableList.builder();
   try {
     logger.debug("get knapsack states: {}", name);
     final Client client = injector.getInstance(Client.class);
     createIndexIfNotExist(client);
     GetResponse getResponse =
         client.prepareGet(INDEX_NAME, MAPPING_NAME, name).execute().actionGet();
     if (!getResponse.isExists()) {
       return builder.build();
     }
     XContentParser parser = xContent(JSON).createParser(getResponse.getSourceAsBytes());
     while (parser.nextToken() != START_ARRAY) {
       // forward
     }
     while (parser.nextToken() != END_ARRAY) {
       KnapsackState state = new KnapsackState();
       builder.add(state.fromXContent(parser));
     }
     return builder.build();
   } catch (Throwable t) {
     logger.error("get settings failed", t);
     return null;
   }
 }
Пример #13
0
 public Page(
     UUID id,
     Device device,
     PageMapKey key,
     ImmutableHierarchy<UUID, CIP> components,
     List<Frame> layout) {
   super(id);
   this.device = checkNotNull(device);
   this.key = key;
   this.components = checkNotNull(components);
   if (layout == null) {
     this.layout = ImmutableList.of();
   } else {
     this.layout = ImmutableList.copyOf(layout);
   }
   final ImmutableList.Builder<CIP> orderBuilder = ImmutableList.builder();
   final HierarchyVisitor<UUID, CIP> visitor =
       new HierarchyVisitor<UUID, CIP>() {
         public void visit(UUID key, CIP value, UUID parentKey, int position) {
           orderBuilder.add(value);
         }
       };
   Hierarchies.visitDepthFirst(this.components, visitor);
   this.order = orderBuilder.build();
 }
Пример #14
0
  @Override
  public void createTable(ConnectorSession session, ConnectorTableMetadata tableMetadata) {
    checkArgument(!isNullOrEmpty(tableMetadata.getOwner()), "Table owner is null or empty");

    SchemaTableName schemaTableName = tableMetadata.getTable();
    String schemaName = schemaTableName.getSchemaName();
    String tableName = schemaTableName.getTableName();

    ImmutableList.Builder<String> columnNames = ImmutableList.builder();
    ImmutableList.Builder<Type> columnTypes = ImmutableList.builder();

    buildColumnInfo(tableMetadata, columnNames, columnTypes);

    ImmutableList.Builder<FieldSchema> partitionKeys = ImmutableList.builder();
    ImmutableList.Builder<FieldSchema> columns = ImmutableList.builder();

    List<String> names = columnNames.build();
    List<String> typeNames =
        columnTypes
            .build()
            .stream()
            .map(HiveType::toHiveType)
            .map(HiveType::getHiveTypeName)
            .collect(toList());

    for (int i = 0; i < names.size(); i++) {
      if (tableMetadata.getColumns().get(i).isPartitionKey()) {
        partitionKeys.add(new FieldSchema(names.get(i), typeNames.get(i), null));
      } else {
        columns.add(new FieldSchema(names.get(i), typeNames.get(i), null));
      }
    }

    Path targetPath = getTargetPath(schemaName, tableName, schemaTableName);

    HiveStorageFormat hiveStorageFormat = getHiveStorageFormat(session, this.hiveStorageFormat);
    SerDeInfo serdeInfo = new SerDeInfo();
    serdeInfo.setName(tableName);
    serdeInfo.setSerializationLib(hiveStorageFormat.getSerDe());

    StorageDescriptor sd = new StorageDescriptor();
    sd.setLocation(targetPath.toString());

    sd.setCols(columns.build());
    sd.setSerdeInfo(serdeInfo);
    sd.setInputFormat(hiveStorageFormat.getInputFormat());
    sd.setOutputFormat(hiveStorageFormat.getOutputFormat());

    Table table = new Table();
    table.setDbName(schemaName);
    table.setTableName(tableName);
    table.setOwner(tableMetadata.getOwner());
    table.setTableType(TableType.MANAGED_TABLE.toString());
    String tableComment = "Created by Presto";
    table.setParameters(ImmutableMap.of("comment", tableComment));
    table.setPartitionKeys(partitionKeys.build());
    table.setSd(sd);

    metastore.createTable(table);
  }
Пример #15
0
 private static List<NamedParameterDefinition> toBlockParameters(List<Integer> inputChannels) {
   ImmutableList.Builder<NamedParameterDefinition> parameters = ImmutableList.builder();
   for (int channel : inputChannels) {
     parameters.add(arg("block_" + channel, com.facebook.presto.spi.block.Block.class));
   }
   return parameters.build();
 }
  @Override
  public ConnectorPageSource createPageSource(
      ConnectorTransactionHandle transactionHandle,
      ConnectorSession session,
      ConnectorSplit split,
      List<ColumnHandle> columns) {
    InternalTable table = getInternalTable(transactionHandle, session, split, columns);

    List<Integer> channels = new ArrayList<>();
    for (ColumnHandle column : columns) {
      String columnName =
          checkType(column, InformationSchemaColumnHandle.class, "column").getColumnName();
      int columnIndex = table.getColumnIndex(columnName);
      channels.add(columnIndex);
    }

    ImmutableList.Builder<Page> pages = ImmutableList.builder();
    for (Page page : table.getPages()) {
      Block[] blocks = new Block[channels.size()];
      for (int index = 0; index < blocks.length; index++) {
        blocks[index] = page.getBlock(channels.get(index));
      }
      pages.add(new Page(page.getPositionCount(), blocks));
    }
    return new FixedPageSource(pages.build());
  }
  @Override
  public Records getNext(int maxNumberOfRecords) {
    ensureBuffered();

    if (!it.hasNext() && buffer.isEndOfShard()) {
      return new Records(ImmutableList.<Record>of(), true);
    }

    ImmutableList.Builder<Record> recs = new ImmutableList.Builder<>();
    int recsSize = 0;

    while (recsSize < maxNumberOfRecords) {
      if (it.hasNext()) {
        recs.add(it.next());
        recsSize++;
      } else if (!it.hasNext() && !buffer.isEndOfShard()) {
        rebuffer();
        // No more data in shard.
        if (!it.hasNext()) {
          break;
        }
      } else {
        // No more records, end of shard.
        break;
      }
    }

    return new Records(recs.build(), false);
  }
 protected static ImmutableList<Integer> rangeList(int start, int end) {
   ImmutableList.Builder<Integer> builder = ImmutableList.builder();
   for (int i = start; i < end; i++) {
     builder.add(i);
   }
   return builder.build();
 }
  private void testCorrectnessOfErrorFunction(List<Number> inputList) throws Exception {
    int inRange = 0;
    int numberOfRuns = 1000;
    double sampleRatio = 1 / (double) WEIGHT;
    double actual = getExpectedValue(inputList);
    Random rand = new Random(1);

    for (int i = 0; i < numberOfRuns; i++) {
      // Compute Sampled Value using sampledList (numberOfRuns times)
      ImmutableList.Builder<Number> sampledList = ImmutableList.builder();
      for (Number x : inputList) {
        if (rand.nextDouble() < sampleRatio) {
          sampledList.add(x);
        }
      }

      BlockBuilder builder = getType().createBlockBuilder(new BlockBuilderStatus());
      for (Number sample : sampledList.build()) {
        if (getType() == BIGINT) {
          BIGINT.writeLong(builder, sample.longValue());
        } else if (getType() == DOUBLE) {
          DOUBLE.writeDouble(builder, sample.doubleValue());
        } else {
          throw new AssertionError("Can only handle longs and doubles");
        }
      }
      Page page = new Page(builder.build());
      page = OperatorAssertion.appendSampleWeight(ImmutableList.of(page), WEIGHT).get(0);
      Accumulator accumulator =
          getFunction()
              .bind(
                  ImmutableList.of(0),
                  Optional.<Integer>absent(),
                  Optional.of(page.getChannelCount() - 1),
                  getConfidence())
              .createAccumulator();

      accumulator.addInput(page);
      Block result = accumulator.evaluateFinal();

      String approxValue =
          BlockAssertions.toValues(accumulator.getFinalType(), result).get(0).toString();
      double approx = Double.parseDouble(approxValue.split(" ")[0]);
      double error = Double.parseDouble(approxValue.split(" ")[2]);

      // Check if actual answer lies within [approxAnswer - error, approxAnswer + error]
      if (Math.abs(approx - actual) <= error) {
        inRange++;
      }
    }

    BinomialDistribution binomial = new BinomialDistribution(numberOfRuns, getConfidence());
    int lowerBound = binomial.inverseCumulativeProbability(0.01);
    int upperBound = binomial.inverseCumulativeProbability(0.99);
    assertTrue(
        lowerBound < inRange && inRange < upperBound,
        String.format(
            "%d out of %d passed. Expected [%d, %d]",
            inRange, numberOfRuns, lowerBound, upperBound));
  }
 public FetchNotificationsResult a(
     FetchNotificationsParams paramFetchNotificationsParams, ApiResponse paramApiResponse) {
   paramApiResponse.g();
   FqlResultHelper localFqlResultHelper = new FqlResultHelper(paramApiResponse.c());
   JsonNode localJsonNode1 = localFqlResultHelper.a("notifications");
   JsonNode localJsonNode2 = localFqlResultHelper.a("profiles");
   ImmutableList.Builder localBuilder = ImmutableList.e();
   Iterator localIterator1 = localJsonNode1.iterator();
   while (localIterator1.hasNext()) {
     JsonNode localJsonNode4 = (JsonNode) localIterator1.next();
     localBuilder.b(
         FacebookNotification.a(FBJsonFactory.a.createJsonParser(localJsonNode4.toString())));
   }
   ImmutableMap.Builder localBuilder1 = ImmutableMap.k();
   Iterator localIterator2 = localJsonNode2.iterator();
   while (localIterator2.hasNext()) {
     JsonNode localJsonNode3 = (JsonNode) localIterator2.next();
     FacebookProfile localFacebookProfile =
         FacebookProfile.a(FBJsonFactory.a.createJsonParser(localJsonNode3.toString()));
     localBuilder1.b(Long.valueOf(localFacebookProfile.mId), localFacebookProfile);
   }
   return new FetchNotificationsResult(
       DataFreshnessResult.FROM_SERVER,
       localBuilder.b(),
       localBuilder1.b(),
       System.currentTimeMillis());
 }
Пример #21
0
 private List<JavaType> convertAsmTypes(org.objectweb.asm.Type[] asmTypes) {
   ImmutableList.Builder<JavaType> result = ImmutableList.builder();
   for (org.objectweb.asm.Type asmType : asmTypes) {
     result.add(convertAsmType(asmType));
   }
   return result.build();
 }
Пример #22
0
 public void testComplexBuilder() {
   List<Integer> colorElem = asList(0x00, 0x33, 0x66, 0x99, 0xCC, 0xFF);
   ImmutableList.Builder<Integer> webSafeColorsBuilder = ImmutableList.builder();
   for (Integer red : colorElem) {
     for (Integer green : colorElem) {
       for (Integer blue : colorElem) {
         webSafeColorsBuilder.add((red << 16) + (green << 8) + blue);
       }
     }
   }
   ImmutableList<Integer> webSafeColors = webSafeColorsBuilder.build();
   assertEquals(216, webSafeColors.size());
   Integer[] webSafeColorArray = webSafeColors.toArray(new Integer[webSafeColors.size()]);
   assertEquals(0x000000, (int) webSafeColorArray[0]);
   assertEquals(0x000033, (int) webSafeColorArray[1]);
   assertEquals(0x000066, (int) webSafeColorArray[2]);
   assertEquals(0x003300, (int) webSafeColorArray[6]);
   assertEquals(0x330000, (int) webSafeColorArray[36]);
   assertEquals(0x000066, (int) webSafeColors.get(2));
   assertEquals(0x003300, (int) webSafeColors.get(6));
   ImmutableList<Integer> addedColor = webSafeColorsBuilder.add(0x00BFFF).build();
   assertEquals(
       "Modifying the builder should not have changed any already" + " built sets",
       216,
       webSafeColors.size());
   assertEquals("the new array should be one bigger than webSafeColors", 217, addedColor.size());
   Integer[] appendColorArray = addedColor.toArray(new Integer[addedColor.size()]);
   assertEquals(0x00BFFF, (int) appendColorArray[216]);
 }
 /**
  * Gets the list of Arguments needed to create the request constructor. This includes all non-void
  * required parameters, and arguments described within the request header.
  */
 @Override
 public ImmutableList<Arguments> toConstructorArgumentsList(final Ds3Request ds3Request) {
   final ImmutableList.Builder<Arguments> builder = ImmutableList.builder();
   builder.addAll(getRequiredArgsFromRequestHeader(ds3Request));
   builder.addAll(removeVoidArguments(toArgumentsList(ds3Request.getRequiredQueryParams())));
   return builder.build();
 }
Пример #24
0
 /** Applies {@link #fileReference(Path)} to each item in the sequence. */
 private final Iterable<PBXFileReference> fileReferences(Iterable<Path> paths) {
   ImmutableList.Builder<PBXFileReference> result = new ImmutableList.Builder<>();
   for (Path path : paths) {
     result.add(fileReference(path));
   }
   return result.build();
 }
Пример #25
0
  /**
   * Parse a string delimited by comma into a list of object instances depending on
   *
   * <pre>itemParser</pre>
   *
   * .
   *
   * @param str String delimited by comma
   * @param itemParser A function to transform a string to an object.
   * @param <T> Type to be transformed from a string
   * @return List of object instances
   */
  static <T> List<T> parseList(String str, Function<String, T> itemParser) {
    if (!str.contains(",")) { // if just one item
      return ImmutableList.of(itemParser.apply(str));
    }

    final ImmutableList.Builder<T> fields = ImmutableList.builder();
    final Stack<Character> stack = new Stack<>();
    int paramStartIdx = 0;
    for (int i = 0; i < str.length(); i++) {
      char c = str.charAt(i);

      if (c == '<' || c == '[' || c == '(') {
        stack.push(c);
      } else if (c == '>') {
        Assert.assertCondition(stack.pop() == '<', "Bad signature: '%s'", str);
      } else if (c == ']') {
        Assert.assertCondition(stack.pop() == '[', "Bad signature: '%s'", str);
      } else if (c == ')') {
        Assert.assertCondition(stack.pop() == '(', "Bad signature: '%s'", str);
      } else if (c == ',') {
        if (stack.isEmpty()) { // ensure outermost type parameters
          fields.add(itemParser.apply(str.substring(paramStartIdx, i)));
          paramStartIdx = i + 1;
        }
      }
    }

    Assert.assertCondition(stack.empty(), "Bad signature: '%s'", str);
    if (paramStartIdx < str.length()) {
      fields.add(itemParser.apply(str.substring(paramStartIdx, str.length())));
    }

    return fields.build();
  }
    public PagePartitioner(
        PartitionFunction partitionFunction,
        List<Integer> partitionChannels,
        List<Optional<NullableValue>> partitionConstants,
        OptionalInt nullChannel,
        OutputBuffer outputBuffer,
        List<Type> sourceTypes,
        DataSize maxMemory) {
      this.partitionFunction = requireNonNull(partitionFunction, "partitionFunction is null");
      this.partitionChannels = requireNonNull(partitionChannels, "partitionChannels is null");
      this.partitionConstants =
          requireNonNull(partitionConstants, "partitionConstants is null")
              .stream()
              .map(constant -> constant.map(NullableValue::asBlock))
              .collect(toImmutableList());
      this.nullChannel = requireNonNull(nullChannel, "nullChannel is null");
      this.outputBuffer = requireNonNull(outputBuffer, "outputBuffer is null");
      this.sourceTypes = requireNonNull(sourceTypes, "sourceTypes is null");

      int pageSize =
          Math.min(
              PageBuilderStatus.DEFAULT_MAX_PAGE_SIZE_IN_BYTES,
              ((int) maxMemory.toBytes()) / partitionFunction.getPartitionCount());
      pageSize = Math.max(1, pageSize);

      ImmutableList.Builder<PageBuilder> pageBuilders = ImmutableList.builder();
      for (int i = 0; i < partitionFunction.getPartitionCount(); i++) {
        pageBuilders.add(PageBuilder.withMaxPageSize(pageSize, sourceTypes));
      }
      this.pageBuilders = pageBuilders.build();
    }
Пример #27
0
  private void logEndpoints() {
    final StringBuilder stringBuilder = new StringBuilder(1024).append("\n\n");

    final ImmutableList.Builder<Class<?>> builder = ImmutableList.builder();
    for (Object o : config.getSingletons()) {
      if (o.getClass().isAnnotationPresent(Path.class)) {
        builder.add(o.getClass());
      }
    }
    for (Class<?> klass : config.getClasses()) {
      if (klass.isAnnotationPresent(Path.class)) {
        builder.add(klass);
      }
    }

    for (Class<?> klass : builder.build()) {
      final String path = klass.getAnnotation(Path.class).value();
      final ImmutableList.Builder<String> endpoints = ImmutableList.builder();
      for (AnnotatedMethod method : annotatedMethods(klass)) {
        for (HttpMethod verb : method.getMetaMethodAnnotations(HttpMethod.class)) {
          endpoints.add(
              String.format("    %-7s %s (%s)", verb.value(), path, klass.getCanonicalName()));
        }
      }

      for (String line : Ordering.natural().sortedCopy(endpoints.build())) {
        stringBuilder.append(line).append('\n');
      }
    }

    LOG.info(stringBuilder.toString());
  }
 /** Unlike EC2, you cannot default GCE instances to a region. Hence, we constrain to zones. */
 @Override
 public Iterable<Location> listLocations() {
   Location provider = justProvider.get().iterator().next();
   ImmutableList.Builder<Location> zones = ImmutableList.builder();
   for (Region region : concat(api.regions().list())) {
     Location regionLocation =
         new LocationBuilder()
             .scope(LocationScope.REGION)
             .id(region.name())
             .description(region.selfLink().toString())
             .parent(provider)
             .build();
     for (URI zoneSelfLink : region.zones()) {
       String zoneName = toName(zoneSelfLink);
       zones.add(
           new LocationBuilder()
               .scope(LocationScope.ZONE)
               .id(zoneName)
               .description(zoneSelfLink.toString())
               .parent(regionLocation)
               .build());
     }
   }
   return zones.build();
 }
Пример #29
0
  private ImmutableList<Artifact> generatedOutputArtifacts(FileType newFileType) {
    ImmutableList.Builder<Artifact> builder = new ImmutableList.Builder<>();
    for (Artifact protoFile : getFilteredProtoSources()) {
      String protoFileName = FileSystemUtils.removeExtension(protoFile.getFilename());
      String generatedOutputName;
      if (attributes.outputsCpp()) {
        generatedOutputName = protoFileName;
      } else if (usesProtobufLibrary()) {
        // The protobuf library generates filenames with some slight modifications.
        generatedOutputName = generateProtobufFilename(protoFileName);
      } else {
        String lowerUnderscoreBaseName = protoFileName.replace('-', '_').toLowerCase();
        generatedOutputName = LOWER_UNDERSCORE.to(UPPER_CAMEL, lowerUnderscoreBaseName);
      }

      PathFragment generatedFilePath =
          new PathFragment(
              protoFile.getRootRelativePath().getParentDirectory(),
              new PathFragment(generatedOutputName));

      PathFragment outputFile =
          FileSystemUtils.appendExtension(generatedFilePath, newFileType.getExtensions().get(0));

      if (outputFile != null) {
        builder.add(
            ruleContext.getUniqueDirectoryArtifact(
                UNIQUE_DIRECTORY_NAME, outputFile, ruleContext.getBinOrGenfilesDirectory()));
      }
    }
    return builder.build();
  }
Пример #30
0
 public static ImmutableList<RexNode> getInputRef(List<Integer> inputRefs, RelNode inputRel) {
   ImmutableList.Builder<RexNode> bldr = ImmutableList.<RexNode>builder();
   for (int i : inputRefs) {
     bldr.add(new RexInputRef(i, inputRel.getRowType().getFieldList().get(i).getType()));
   }
   return bldr.build();
 }