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

public Object[] toArray() 

Source Link

Document

Returns an array containing all of the elements in this list in proper sequence (from first to last element).

Usage

From source file:com.thoughtworks.go.util.comparator.AlphaAsciiCollectionComparator.java

private String string(Collection<? extends Comparable<T>> other) {
    ArrayList<Comparable> others = new ArrayList<>(other);
    Collections.sort(others);//from w ww .  j a  va  2s .  c  o m
    return StringUtils.join(others.toArray());
}

From source file:configuration.Cluster.java

public static String getPgrmOutput(workflow_properties properties, String std) {
    if (isP2RsaHere()) {
        String fClus = getClusterFilePath(properties, std, "");
        ArrayList<String> tab = runSshCommand(properties, "cat " + fClus);
        if (tab.size() == 1 && tab.get(0).contains("cat"))
            return "";
        else/*from w w  w . ja  v  a 2  s . c o m*/
            return Arrays.toString(tab.toArray());
    }
    return "";
}

From source file:com.espertech.esper.support.util.ArrayAssertionUtil.java

/**
 * Comparing the underlying events to the expected events using equals-semantics.
 * @param events is an event array to get the underlying objects
 * @param expectedValues is an array of expected underlying events
 *//*from ww  w .j a  v  a  2s. c  o  m*/
public static void assertEqualsExactOrderUnderlying(EventBean[] events, Object[] expectedValues) {
    if ((expectedValues == null) && (events == null)) {
        return;
    }
    if (((expectedValues == null) && (events != null)) || ((expectedValues != null) && (events == null))) {
        TestCase.assertTrue(false);
    }

    TestCase.assertEquals(expectedValues.length, events.length);

    ArrayList<Object> underlying = new ArrayList<Object>();
    for (EventBean event : events) {
        underlying.add(event.getUnderlying());
    }

    assertEqualsExactOrder(underlying.toArray(), expectedValues);
}

From source file:JListDemo.java

JListDemo(String s) {
    super(s);//from  w w  w  . j a  v a 2  s.c o m
    Container cp = getContentPane();
    cp.setLayout(new FlowLayout());
    ArrayList data = new ArrayList();
    data.add("Hi");
    data.add("Hello");
    data.add("Goodbye");
    data.add("Adieu");
    data.add("Adios");
    list = new JList(data.toArray());
    list.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent evt) {
            if (evt.getValueIsAdjusting())
                return;
            System.out.println("Selected from " + evt.getFirstIndex() + " to " + evt.getLastIndex());
        }
    });
    cp.add(list, BorderLayout.CENTER);
}

From source file:io.seldon.recommendation.baseline.jdo.SqlStaticRecommendationsProvider.java

@Override
public Map<Long, Double> getStaticRecommendations(long userId, Set<Integer> dimensions, int max) {
    Collection<Object[]> results;
    Query query;//ww  w .  jav  a2s  . c om
    if (dimensions.isEmpty()
            || (dimensions.size() == 1 && dimensions.iterator().next() == Constants.DEFAULT_DIMENSION)) {
        String sql = "select item_id,score from recommendations where user_id=? order by score desc";
        if (max > 0)
            sql = sql + " limit " + max;
        query = getPM().newQuery("javax.jdo.query.SQL", sql);
        ArrayList<Object> args = new ArrayList<>();
        args.add(userId);
        results = (Collection<Object[]>) query.executeWithArray(args.toArray());
    } else {
        String dimensionsStr = StringUtils.join(dimensions, ",");
        String sql = "select recs.item_id,score from recommendations recs join item_map_enum ime on (recs.item_id=ime.item_id) join dimension d on (ime.attr_id=d.attr_id and ime.value_id=d.value_id) where dim_id in ("
                + dimensionsStr + ") and recs.user_id=? order by score desc";
        if (max > 0)
            sql = sql + " limit " + max;
        query = getPM().newQuery("javax.jdo.query.SQL", sql);
        ArrayList<Object> args = new ArrayList<>();
        args.add(userId);
        results = (Collection<Object[]>) query.executeWithArray(args.toArray());
    }
    Map<Long, Double> map = new HashMap<>();
    for (Object[] res : results) {
        Long item = (Long) res[0];
        Double score = (Double) res[1];
        map.put(item, score);
    }
    query.closeAll();
    return map;
}

From source file:hmp.HMPRunRemover.java

private void run(String[] args) throws ParseException, ClassNotFoundException, SQLException {
    cli = getOptions(args);//  w w w.java 2s.  co m
    conn = new MySQLConnector("localhost", cli.getOptionValue("db"), cli.getOptionValue("dbUser"),
            cli.getOptionValue("dbPassword")).getConnection();
    int runId = getRunIdFromDate();
    System.out.println("Deleting data for " + cli.getOptionValue("date") + ", id = " + runId);
    ArrayList<Integer> samples = getSamplesForRun(runId);
    System.out.println("Samples " + Arrays.toString(samples.toArray()));
    Collections.sort(samples);
    deleteRpdResultData(samples);
    deleteRdpSummaryData(samples);
    deleteSampleData(samples);
    deleteRunData(runId);
    deleteSampleCounts(samples);
    deleteSample(runId);
    deleteRunCounts(runId);
    deleteRun(runId);
}

From source file:com.onpositive.semantic.words3.MultiHashMap.java

public Collection values() {
    ArrayList returnList = new ArrayList(super.size());

    Set pairs = super.entrySet();
    Iterator pairsIterator = pairs.iterator();
    while (pairsIterator.hasNext()) {
        Map.Entry keyValuePair = (Map.Entry) (pairsIterator.next());
        ArrayList list = (ArrayList) (keyValuePair.getValue());

        Object[] values = list.toArray();
        for (int ii = 0; ii < values.length; ii++) {
            returnList.add(values[ii]);//from   w w  w .  j a va2s. c  o m
        }
    }
    return returnList;
}

From source file:com.microsoft.windowsazure.core.tracing.util.JavaTracingInterceptor.java

/**
 * Enter a method./*from   w ww  . ja  v  a2s.c o  m*/
 * 
 * @param invocationId
 *            Method invocation identifier.
 * @param instance
 *            The instance with the method.
 * @param method
 *            Name of the method.
 * @param parameters
 *            Method parameters.
 */
public void enter(String invocationId, Object instance, String method, HashMap<String, Object> parameters) {
    ArrayList<Object> valuesList = new ArrayList<Object>(parameters.values());
    logger.entering(instance.getClass().getName(), method, valuesList.toArray());
}

From source file:io.seldon.recommendation.baseline.jdo.SqlBaselineRecommenderUtils.java

@Override
public Map<Long, Double> getPopularItems(int dimension, int numRecommendations) {

    String sql = "select ip.item_id,opsum from items_popular ip join item_map_enum ime on (ip.item_id=ime.item_id) join dimension d on (ime.attr_id=d.attr_id and ime.value_id=d.value_id) where dim_id=? order by opsum desc limit "
            + numRecommendations;//from   w  ww .  jav  a2s.com
    Query query = getPM().newQuery("javax.jdo.query.SQL", sql);
    ArrayList<Object> args = new ArrayList<>();
    args.add(dimension);
    Collection<Object[]> results = (Collection<Object[]>) query.executeWithArray(args.toArray());
    Map<Long, Double> map = new HashMap<>();
    Double topScore = null;
    for (Object[] res : results) {
        if (topScore == null)
            topScore = (Double) res[1];
        Long item = (Long) res[0];
        Double score = (Double) res[1];
        map.put(item, score / topScore);
    }
    query.closeAll();
    return map;
}

From source file:org.datagator.api.client.SpooledRowBuffer.java

@Override
public Iterator<Object[]> iterator() {
    if (rowsCount <= cacheLimit) {
        return this.cache.iterator();
    } else {//w  w  w .  java 2 s . co  m
        try {
            flush();
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
        return new Iterator<Object[]>() {

            private final JsonParser jp;
            private int rowIndex = 0;
            private final TypeReference<ArrayList<Object>> tr = new TypeReference<ArrayList<Object>>() {
            };

            {
                try {
                    // TODO lock cache file
                    cacheFile.seek(0);
                    FileReader reader = new FileReader(cacheFile.getFD());
                    jp = Entity.json.createParser(reader);
                    JsonToken token = jp.nextToken(); // START_ARRAY
                    if (!token.equals(JsonToken.START_ARRAY)) {
                        throw new RuntimeException("Corrupted cache file");
                    }
                } catch (IOException ex) {
                    throw new RuntimeException(ex);
                }
            }

            @Override
            public boolean hasNext() {
                return rowIndex < rowsCount;
            }

            @Override
            public Object[] next() {
                if (!hasNext()) {
                    throw new NoSuchElementException("No such elememnt.");
                }
                try {
                    rowIndex += 1;
                    ArrayList<Object> buffer = jp.readValueAs(tr);
                    return buffer.toArray();
                } catch (IOException ex) {
                    throw new RuntimeException(ex);
                }
            }

            @Override
            public void remove() {
                throw new UnsupportedOperationException("Not supported yet.");
            }

        };
    }
}