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:io.seldon.similarity.item.JdoItemSimilarityPeer.java

@Override
public Map<Long, Double> getSimilarItems(long itemId, Set<Integer> dimensions, int max) {
    Collection<Object[]> results;
    Query query;//from   www .  j a va2  s .  c  o m
    if (dimensions.isEmpty()
            || (dimensions.size() == 1 && dimensions.iterator().next() == Constants.DEFAULT_DIMENSION)) {
        String sql = "select isim.item_id2 as item_id,score from item_similarity isim where isim.item_id=? union select isim.item_id,score from item_similarity isim where isim.item_id2=? 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(itemId);
        args.add(itemId);
        results = (Collection<Object[]>) query.executeWithArray(args.toArray());
    } else {
        String dimensionsStr = StringUtils.join(dimensions, ",");
        String sql = "select isim.item_id2 as item_id,score from item_similarity isim join item_map_enum ime on (isim.item_id2=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 isim.item_id=? union select isim.item_id,score from item_similarity isim join item_map_enum ime on (isim.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 isim.item_id2=? 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(itemId);
        args.add(itemId);
        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:com.dubture.composer.ui.converter.License2StringConverter.java

@Override
public String convert(Object fromObject) {
    ArrayList<String> list = new ArrayList<String>();
    License licenses = (License) fromObject;
    for (String license : licenses) {
        list.add(license);/*from  ww w .  j  a  va  2s . co  m*/
    }

    if (list.size() == 0) {
        return "";
    }

    return StringUtils.join(list.toArray(), ", ");
}

From source file:io.jjcastillo.bconferencia.helper.Storage.java

public void saveAll() {
    File f = new File(FILE_NAME);
    FileOutputStream str = null;//from   w  w w .j a v  a 2  s  . c o  m
    try {
        str = new FileOutputStream(f, false);

        ArrayList<Auditorio> data = new ArrayList();
        data.add(auditorio1);
        data.add(auditorio2);

        str.write(toJSON(data.toArray()).getBytes());
        str.close();
    } catch (Exception ex) {
        Logger.getLogger(Storage.class.getName()).log(Level.SEVERE, null, ex);
        if (str != null) {
            try {
                str.close();
            } catch (IOException ex1) {
                Logger.getLogger(Storage.class.getName()).log(Level.SEVERE, null, ex1);
            }
        }
    }

}

From source file:gobblin.ingestion.google.webmaster.UrlTriePrefixGrouperTest.java

@Test
public void testGroupToPagesWithContainsOperator() {
    List<String> pages = Arrays.asList(_property + "13", _property + "14");
    UrlTrie trie = new UrlTrie(_property, pages);
    ArrayList<String> actual = UrlTriePrefixGrouper
            .groupToPages(Triple.of(_property, FilterOperator.CONTAINS, trie.getRoot()));
    Assert.assertEquals(actual.toArray(), pages.toArray());
}

From source file:gobblin.ingestion.google.webmaster.UrlTriePrefixGrouperTest.java

@Test
public void testGroupToPagesWithContainsOperator2() {
    List<String> pages = Arrays.asList(_property + "13", _property + "14", _property + "1", _property + "1");
    UrlTrie trie = new UrlTrie(_property, pages);
    ArrayList<String> actual = UrlTriePrefixGrouper
            .groupToPages(Triple.of(_property, FilterOperator.CONTAINS, trie.getRoot()));
    Assert.assertEquals(actual.toArray(), new String[] { _property + "13", _property + "14", _property + "1" });
}

From source file:edu.duke.cabig.c3pr.web.study.tabs.StudyRandomizationTab.java

public ModelAndView parseFile(HttpServletRequest request, Object commandObj, Errors error) {

    String flowType = " ";
    if (getFlow().getName().equals("Create Study")) {
        flowType = "CREATE_STUDY";
    } else if (getFlow().getName().equals("Edit Study")) {
        flowType = "EDIT_STUDY";
    } else if (getFlow().getName().equals("Amend Study")) {
        flowType = "AMEND_STUDY";
    }//from   w ww.j  a  v a2 s  .c  o m

    Map<String, String> map = new HashMap<String, String>();
    try {
        String index = request.getParameter("index").toString();
        StudyWrapper wrapper = (StudyWrapper) commandObj;

        Object viewData = bookRandomizationAjaxFacade.getTableForWrapper(new HashMap<String, List>(),
                wrapper.getFile(), index, request, flowType, wrapper);
        if (StringUtils.isEmpty(viewData.toString())) {
            map.put(AjaxableUtils.getFreeTextModelName(),
                    "<div><b>Incorrect format. Please try again.</b></div>");
        } else {
            ArrayList<String> bookRandomizationEntries = new ArrayList<String>();
            bookRandomizationEntries.add(Integer.parseInt(index), viewData.toString());
            request.setAttribute("bookRandomizationEntries", bookRandomizationEntries.toArray());
            map.put(AjaxableUtils.getFreeTextModelName(), viewData.toString());
        }
    } catch (Exception e) {
        log.error(e.getMessage());
    }
    return new ModelAndView("", map);
}

From source file:glluch.com.ontotaxoseeker.TermsTest.java

/**
 * Test of terms method, of class Terms.
 * @throws java.io.IOException// w w  w . j ava 2s.  co  m
 * @throws java.io.FileNotFoundException
 * @throws java.lang.ClassNotFoundException
 */
@Test
public void testTerms() throws IOException, FileNotFoundException, ClassNotFoundException {
    TermsTest.resetTs();
    System.out.println("Terms.terms");
    Terms instance = TermsTest.ts;
    File file = new File("resources/test/testTermsResults.bin");
    byte[] v = FileUtils.readFileToByteArray(file);
    ArrayList<String> expResult = SerializationUtils.deserialize(v);
    ArrayList<Term> result = instance.terms();
    Iterator iter = result.iterator();
    ArrayList<String> lemas = new ArrayList<>();
    while (iter.hasNext()) {
        Term next = (Term) iter.next();
        lemas.add(next.getLema());
    }
    Object[] lemas1 = lemas.toArray();
    Object[] exp = expResult.toArray();
    java.util.Arrays.sort(lemas1);
    java.util.Arrays.sort(exp);
    //Out.p(lemas1);
    //Out.p(exp);
    Assert.assertArrayEquals(exp, lemas1);

}

From source file:gobblin.ingestion.google.webmaster.UrlTriePrefixGrouperTest.java

@Test
public void testGroupToPagesWithEqualsOperator() {
    List<String> pages = Arrays.asList(_property + "13", _property + "14");
    UrlTrie trie1 = new UrlTrie(_property, pages);
    ArrayList<String> actual1 = UrlTriePrefixGrouper
            .groupToPages(Triple.of(_property, FilterOperator.EQUALS, trie1.getRoot()));
    Assert.assertEquals(actual1.size(), 0);

    List<String> pagesWithRoot = new ArrayList<>();
    pagesWithRoot.addAll(pages);// w  ww .  j a  v  a2 s.c o m
    pagesWithRoot.add(_property);
    UrlTrie trie2 = new UrlTrie(_property, pagesWithRoot);
    ArrayList<String> actual2 = UrlTriePrefixGrouper
            .groupToPages(Triple.of(_property, FilterOperator.EQUALS, trie2.getRoot()));
    Assert.assertEquals(actual2.toArray(), new String[] { _property });
}

From source file:net.sf.xmm.moviemanager.http.HttpUtil.java

/**
 * Decodes a html string /* w w  w .j  a  v a2  s  .c o  m*/
 **/
public static Object[] decodeHTMLtoArray(String toDecode) {
    ArrayList<String> decoded = new ArrayList<String>();
    String tmp = "";

    try {
        int end = 0;
        for (int i = 0; i < toDecode.length(); i++) {
            if (toDecode.charAt(i) == '&' && toDecode.charAt(i + 1) == '#'
                    && (end = toDecode.indexOf(";", i)) != -1) {
                tmp += (char) Integer.parseInt(toDecode.substring(i + 3, end), 16);
                i = end;
            } else if (toDecode.charAt(i) == '<' && toDecode.indexOf('>', i) != -1) {
                i = toDecode.indexOf('>', i);

                if (!tmp.trim().equals(""))
                    decoded.add(tmp.trim());

                tmp = "";
            } else {
                tmp += toDecode.charAt(i);
            }
        }
    } catch (Exception e) {
        log.error("", e);
    }
    /* Returns the decoded string... */
    return decoded.toArray();
}

From source file:com.onpositive.semantic.wikipedia.abstracts.svc.HtmlRendererBase.java

private void printPart(String format, ArrayList<Object> a, int last, int i) {
    if (i - last > 0) {
        String f = format.substring(last, i);
        if (a.isEmpty()) {
            p.print(f);// ww w  .  j  a  v  a  2 s .c  om
        } else {
            p.print(String.format(f, a.toArray()));
            a.clear();
        }
    }
}