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]);
 }
Example #2
0
  public Map<String, Path> buildMultipleAndReturnOutputs(String... args) throws IOException {
    // Add in `--show-output` to the build, so we can parse the output paths after the fact.
    ImmutableList<String> buildArgs =
        ImmutableList.<String>builder().add("--show-output").add(args).build();
    ProjectWorkspace.ProcessResult buildResult =
        runBuckBuild(buildArgs.toArray(new String[buildArgs.size()]));
    buildResult.assertSuccess();

    // Grab the stdout lines, which have the build outputs.
    List<String> lines =
        Splitter.on(CharMatcher.anyOf(System.lineSeparator()))
            .trimResults()
            .omitEmptyStrings()
            .splitToList(buildResult.getStdout());

    // Skip the first line, which is just "The outputs are:".
    assertThat(lines.get(0), Matchers.equalTo("The outputs are:"));
    lines = lines.subList(1, lines.size());

    Splitter lineSplitter = Splitter.on(' ').trimResults();
    ImmutableMap.Builder<String, Path> builder = ImmutableMap.builder();
    for (String line : lines) {
      List<String> fields = lineSplitter.splitToList(line);
      assertThat(fields, Matchers.hasSize(2));
      builder.put(fields.get(0), getPath(fields.get(1)));
    }

    return builder.build();
  }
Example #3
0
 /**
  * Returns an immutable list containing the given elements, in order.
  *
  * <p>Despite the method name, this method attempts to avoid actually copying the data when it is
  * safe to do so. The exact circumstances under which a copy will or will not be performed are
  * undocumented and subject to change.
  *
  * <p>Note that if {@code list} is a {@code List<String>}, then {@code ImmutableList.copyOf(list)}
  * returns an {@code ImmutableList<String>} containing each of the strings in {@code list}, while
  * ImmutableList.of(list)} returns an {@code ImmutableList<List<String>>} containing one element
  * (the given list itself).
  *
  * <p>This method is safe to use even when {@code elements} is a synchronized or concurrent
  * collection that is currently being modified by another thread.
  *
  * @throws NullPointerException if any of {@code elements} is null
  */
 public static <E> ImmutableList<E> copyOf(Collection<? extends E> elements) {
   if (elements instanceof ImmutableCollection) {
     @SuppressWarnings("unchecked") // all supported methods are covariant
     ImmutableList<E> list = ((ImmutableCollection<E>) elements).asList();
     return list.isPartialView() ? ImmutableList.<E>asImmutableList(list.toArray()) : list;
   }
   return construct(elements.toArray());
 }
Example #4
0
  /**
   * Vraci seznam vsech kombinaci pro zadanou strategy
   *
   * @param strategyName jmeno strategie
   * @return {key=cci, value=1;key=ema, value=13} {key=cci, value=2;key=ema, value=13} {key=cci,
   *     value=1;key=ema, value=14} atd...
   */
  public static List<Map<String, Integer>> getParametersCombination(String strategyName) {
    Map<String, Integer> map;
    List<Map<String, Integer>> list = new ArrayList<Map<String, Integer>>();
    // nactu z konfigu seznam vsech klicu
    List<String> keys = PropertyHelper.getAllOptimizationParamsForStrategy(strategyName);
    // naplnim si mapu konfiguracnich dat ex. {key=cci,value=3,4,5},{key=macd_1, value=10,2,20}
    Set[] sets = new Set[keys.size()];
    // sets[0] = ImmutableSet.of(keys);
    int loop = 0;
    for (String string : keys) {
      Integer[] values = PropertyHelper.getIntPropertyForOptimizer(string);
      Integer[] ilist = getAllIntegers(values);
      sets[loop++] = ImmutableSet.of(ilist);
    }
    List<String> reducedKeys = new ArrayList<String>();
    for (int i = 0; i < keys.size(); i++) {
      String s = keys.get(i);
      s = s.split("\\.")[1];
      reducedKeys.add(s);
    }

    Set s = Sets.cartesianProduct(sets);
    System.out.println(s.size());
    Iterator it = s.iterator();
    loop = 0;
    while (it.hasNext()) {
      ImmutableList il = (ImmutableList) it.next();
      Object[] o = il.toArray();
      map = new HashMap<String, Integer>();
      for (int i = 0; i < reducedKeys.size(); i++) {
        map.put(reducedKeys.get(i), (Integer) o[i]);
      }
      list.add(map);
    }
    return list;
    /*map = new  HashMap<String, Integer>();
    map.put("pt", 40);
    map.put("sl", 30);
    map.put("emaslow", 15);
    map.put("emafast", 5);
    map.put("cci", 13);
    map.put("macd_1", 5);
    map.put("macd_2", 40);
    map.put("macd_3", 5);
    list.add(map);

    map = new  HashMap<String, Integer>();
    map.put("pt", 50);
    map.put("sl", 20);
    map.put("emaslow", 13);
    map.put("emafast", 3);
    map.put("cci", 16);
    map.put("macd_1", 5);
    map.put("macd_2", 35);
    map.put("macd_3", 5);
    list.add(map);*/
  }
 @Override
 public StepExecutionResult execute(ExecutionContext context)
     throws IOException, InterruptedException {
   ImmutableList<String> lldbCommandPrefix = lldb.getCommandPrefix(resolver);
   ProcessExecutorParams params =
       ProcessExecutorParams.builder()
           .addCommand(lldbCommandPrefix.toArray(new String[lldbCommandPrefix.size()]))
           .build();
   return StepExecutionResult.of(
       context
           .getProcessExecutor()
           .launchAndExecute(
               params,
               ImmutableSet.<ProcessExecutor.Option>of(),
               Optional.of(
                   String.format(
                       "target create %s\ntarget symbols add %s",
                       binaryBuildRule.getPathToOutput(), location)),
               Optional.<Long>absent(),
               Optional.<Function<Process, Void>>absent())
           .getExitCode());
 }
  /**
   * Starts the defined appium server
   *
   * @throws AppiumServerHasNotBeenStartedLocallyException If an error occurs while spawning the
   *     child process.
   * @see #stop()
   */
  public void start() throws AppiumServerHasNotBeenStartedLocallyException {
    lock.lock();
    try {
      if (isRunning()) {
        return;
      }

      try {
        process =
            new CommandLine(
                this.nodeJSExec.getCanonicalPath(), nodeJSArgs.toArray(new String[] {}));
        process.setEnvironmentVariables(nodeJSEnvironment);
        process.copyOutputTo(stream);
        process.executeAsync();
        ping(startupTimeout, timeUnit);
      } catch (Throwable e) {
        destroyProcess();
        String msgTxt =
            "The local appium server has not been started. "
                + "The given Node.js executable: "
                + this.nodeJSExec.getAbsolutePath()
                + " Arguments: "
                + nodeJSArgs.toString()
                + " "
                + "\n";
        if (process != null) {
          String processStream = process.getStdOut();
          if (!StringUtils.isBlank(processStream))
            msgTxt = msgTxt + "Process output: " + processStream + "\n";
        }

        throw new AppiumServerHasNotBeenStartedLocallyException(msgTxt, e);
      }
    } finally {
      lock.unlock();
    }
  }
Example #7
0
  @VisibleForTesting
  static void run(String[] args, FileSystem fileSystem) {
    Flags flags = Flags.parse(args, fileSystem);
    Config config = null;
    try (InputStream stream = newInputStream(flags.config)) {
      config = Config.load(stream, fileSystem);
    } catch (IOException e) {
      e.printStackTrace(System.err);
      System.exit(-1);
    }

    if (flags.printConfig) {
      Gson gson = new GsonBuilder().setPrettyPrinting().create();
      String header = " Configuration  ";
      int len = header.length();
      String pad = Strings.repeat("=", len / 2);

      System.err.println(pad + header + pad);
      System.err.println(gson.toJson(config.toJson()));
      System.err.println(Strings.repeat("=", 79));
      System.exit(1);
    }

    Iterable<String> standardFlags = STANDARD_FLAGS;
    if (config.isStrict()) {
      standardFlags =
          transform(
              standardFlags,
              new Function<String, String>() {
                @Override
                public String apply(String input) {
                  return input.replace("--jscomp_warning", "--jscomp_error");
                }
              });
    }

    ImmutableList<String> compilerFlags =
        ImmutableList.<String>builder()
            .addAll(transform(config.getSources(), toFlag("--js=")))
            .addAll(transform(config.getModules(), toFlag("--js=")))
            .addAll(transform(config.getExterns(), toFlag("--externs=")))
            .add("--language_in=" + config.getLanguage().getName())
            .addAll(standardFlags)
            .build();

    PrintStream nullStream = new PrintStream(ByteStreams.nullOutputStream());
    args = compilerFlags.toArray(new String[compilerFlags.size()]);

    Logger log = Logger.getLogger(Main.class.getPackage().getName());
    log.setLevel(Level.WARNING);
    log.addHandler(
        new Handler() {
          @Override
          public void publish(LogRecord record) {
            System.err.printf(
                "[%s][%s] %s\n", record.getLevel(), record.getLoggerName(), record.getMessage());
          }

          @Override
          public void flush() {}

          @Override
          public void close() {}
        });

    Main main = new Main(args, nullStream, System.err, config);
    main.runCompiler();
  }