Example usage for java.util ArrayList toArray

List of usage examples for java.util ArrayList toArray

Introduction

In this page you can find the example usage for java.util ArrayList toArray.

Prototype

@SuppressWarnings("unchecked")
public <T> T[] toArray(T[] a) 

Source Link

Document

Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array.

Usage

From source file:com.panduka.weatherforecast.utils.DataResolver.java

/**
 * Extract weather Alert details from JSON array object
 *
 * @param jsonArray weather alert details JSON array object
 * @return returns an array of Alerts/*ww  w. j av a 2s  .co  m*/
 */
private Alerts[] createAlerts(JSONArray jsonArray) throws JSONException {
    ArrayList<Alerts> dataArr = new ArrayList<>();
    for (int i = 0; i < jsonArray.length(); i++) {
        dataArr.add(createAlert(jsonArray.getJSONObject(i)));
    }
    return dataArr.toArray(new Alerts[dataArr.size()]);
}

From source file:com.panduka.weatherforecast.utils.DataResolver.java

/**
 * Extract Daily weather details from JSON array object
 *
 * @param jsonArray daily weather details JSON array object
 * @return returns an array of DailyData
 *///  w w  w. j  ava 2 s.  c om

private DailyData[] createDailyDataArray(JSONArray jsonArray) throws JSONException {
    ArrayList<DailyData> datas = new ArrayList<>();
    for (int i = 0; i < jsonArray.length(); i++) {
        datas.add(createDailyData(jsonArray.getJSONObject(i)));
    }
    return datas.toArray(new DailyData[datas.size()]);
}

From source file:com.wakatime.eclipse.plugin.Dependencies.java

public void installPython() {
    if (System.getProperty("os.name").contains("Windows")) {
        String url = "https://www.python.org/ftp/python/3.4.2/python-3.4.2.msi";
        if (System.getenv("ProgramFiles(x86)") != null) {
            url = "https://www.python.org/ftp/python/3.4.2/python-3.4.2.amd64.msi";
        }// w w w  .  j  a  v  a 2s.  co m

        File cli = new File(WakaTime.getWakaTimeCLI());
        String outFile = cli.getParentFile().getParentFile().getAbsolutePath() + File.separator + "python.msi";
        if (downloadFile(url, outFile)) {

            // execute python msi installer
            ArrayList<String> cmds = new ArrayList<String>();
            cmds.add("msiexec");
            cmds.add("/i");
            cmds.add(outFile);
            cmds.add("/norestart");
            cmds.add("/qb!");
            try {
                Runtime.getRuntime().exec(cmds.toArray(new String[cmds.size()]));
            } catch (Exception e) {
                WakaTime.error("Error", e);
            }
        }
    }
}

From source file:com.panduka.weatherforecast.utils.DataResolver.java

/**
 * Extract Daily weather details from JSON array object
 *
 * @param jsonArray hourly weather details JSON array object
 * @return returns an array of HourlyData
 */// w  w  w .jav  a 2 s. c o m

private HourlyData[] createHourlyDataArray(JSONArray jsonArray) throws JSONException {
    ArrayList<HourlyData> datas = new ArrayList<>();
    for (int i = 0; i < jsonArray.length(); i++) {
        datas.add(createHourlyData(jsonArray.getJSONObject(i)));
    }
    return datas.toArray(new HourlyData[datas.size()]);
}

From source file:eu.stratosphere.test.util.AbstractTestBase.java

public void compareKeyValueParisWithDelta(String expectedLines, String resultPath, String delimiter,
        double maxDelta) throws Exception {
    ArrayList<String> list = new ArrayList<String>();
    readAllResultLines(list, resultPath, false);

    String[] result = (String[]) list.toArray(new String[list.size()]);
    String[] expected = expectedLines.isEmpty() ? new String[0] : expectedLines.split("\n");

    Assert.assertEquals("Wrong number of result lines.", expected.length, result.length);

    Arrays.sort(result);//w w  w .j  av a2s.co  m
    Arrays.sort(expected);

    for (int i = 0; i < expected.length; i++) {
        String[] expectedFields = expected[i].split(delimiter);
        String[] resultFields = result[i].split(delimiter);

        double expectedPayLoad = Double.parseDouble(expectedFields[1]);
        double resultPayLoad = Double.parseDouble(resultFields[1]);

        Assert.assertTrue("Values differ by more than the permissible delta",
                Math.abs(expectedPayLoad - resultPayLoad) < maxDelta);
    }
}

From source file:octopus.teamcity.agent.OctopusBuildProcess.java

private void startOcto(final OctopusCommandBuilder command) throws RunBuildException {
    String[] userVisibleCommand = command.buildMaskedCommand();
    String[] realCommand = command.buildCommand();

    logger = runningBuild.getBuildLogger();
    logger.activityStarted("Octopus Deploy", DefaultMessagesInfo.BLOCK_TYPE_INDENTATION);
    logger.message(//from   w  ww  . j  a va2s  .co  m
            "Running command:   octo.exe " + StringUtils.arrayToDelimitedString(userVisibleCommand, " "));
    logger.progressMessage(getLogMessage());

    try {
        Runtime runtime = Runtime.getRuntime();

        String octopusVersion = getSelectedOctopusVersion();

        ArrayList<String> arguments = new ArrayList<String>();
        arguments.add(new File(extractedTo, octopusVersion + "\\octo.exe").getAbsolutePath());
        arguments.addAll(Arrays.asList(realCommand));

        process = runtime.exec(arguments.toArray(new String[arguments.size()]), null,
                context.getWorkingDirectory());

        final LoggingProcessListener listener = new LoggingProcessListener(logger);

        standardError = new OutputReaderThread(process.getErrorStream(), new OutputWriter() {
            public void write(String text) {
                listener.onErrorOutput(text);
            }
        });
        standardOutput = new OutputReaderThread(process.getInputStream(), new OutputWriter() {
            public void write(String text) {
                listener.onStandardOutput(text);
            }
        });

        standardError.start();
        standardOutput.start();
    } catch (IOException e) {
        final String message = "Error from Octo.exe: " + e.getMessage();
        Logger.getInstance(getClass().getName()).error(message, e);
        throw new RunBuildException(message);
    }
}

From source file:goraci.Verify.java

private void readFlushed(Configuration conf) throws Exception {
    DataStore<Utf8, Flushed> flushedTable = DataStoreFactory.getDataStore(Utf8.class, Flushed.class, conf);

    Query<Utf8, Flushed> query = flushedTable.newQuery();
    Result<Utf8, Flushed> result = flushedTable.execute(query);

    ArrayList<String> flushedEntries = new ArrayList<String>();
    while (result.next()) {
        flushedEntries.add(result.getKey() + ":" + result.get().getCount());
    }//from w w w .j  a v a  2s  .c o m

    conf.setStrings("goraci.verify.flushed", flushedEntries.toArray(new String[] {}));

    flushedTable.close();
}

From source file:edu.valelab.GaussianFit.CoordinateMapper.java

/**
 * Feeds control points into this class/* w  ww  .jav  a  2 s .  c  o m*/
 * Performs initial calculations for lwm and affine transforms
 * 
 */
public CoordinateMapper(PointMap pointMap, int order, int method) {
    pointMap_ = pointMap;
    order_ = order;
    method_ = method;

    // Set up LWM
    exponentPairs_ = polynomialExponents(order);
    final ArrayList<Point2D.Double> keys = new ArrayList<Point2D.Double>();
    keys.addAll(pointMap.keySet());
    final Point2D.Double[] keyArray = keys.toArray(new Point2D.Double[] {});
    kdTree_ = new EnhancedKDTree(keyArray);
    controlPoints_ = createControlPoints(kdTree_, order_, pointMap_);

    // Set up Affine transform
    af_ = generateAffineTransformFromPointPairs(pointMap);

    // set up Rigid Body
    rbAf_ = generateRigidBodyTransform(pointMap);

}