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.mozilla.socorro.RawDumpSizeScan.java

/**
 * Generates an array of scans for different salted ranges for the given dates
 * @param startDate/*from  www .ja  v a  2s  .co  m*/
 * @param endDate
 * @return
 */
public static Scan[] generateScans(Calendar startCal, Calendar endCal) {
    SimpleDateFormat rowsdf = new SimpleDateFormat("yyMMdd");

    ArrayList<Scan> scans = new ArrayList<Scan>();
    String[] salts = new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e",
            "f" };

    long endTime = DateUtil.getEndTimeAtResolution(endCal.getTimeInMillis(), Calendar.DATE);

    while (startCal.getTimeInMillis() < endTime) {
        int d = Integer.parseInt(rowsdf.format(startCal.getTime()));

        for (int i = 0; i < salts.length; i++) {
            Scan s = new Scan();
            s.setCaching(4);
            // disable block caching
            s.setCacheBlocks(false);
            s.addColumn(RAW_DATA_BYTES, DUMP_BYTES);

            s.setStartRow(Bytes.toBytes(salts[i] + String.format("%06d", d)));
            s.setStopRow(Bytes.toBytes(salts[i] + String.format("%06d", d + 1)));
            System.out.println("Adding start-stop range: " + salts[i] + String.format("%06d", d) + " - "
                    + salts[i] + String.format("%06d", d + 1));

            scans.add(s);
        }

        startCal.add(Calendar.DATE, 1);
    }

    return scans.toArray(new Scan[scans.size()]);
}

From source file:com.esofthead.mycollab.spring.MyBatisConfiguration.java

private Resource[] buildBatchMapperResources(String... resourcesPath) throws IOException {
    ArrayList<Resource> resources = new ArrayList<>();
    for (String resourcePath : resourcesPath) {
        CollectionUtils.addAll(resources, buildMapperResources(resourcePath));
    }/*from w ww  . j  a v  a 2 s  . com*/
    return resources.toArray(new Resource[0]);
}

From source file:edu.unc.lib.dl.util.ContainerContentsHelper.java

/**
 * @param oldXML/*from  ww w .jav a2 s. co  m*/
 * @param container
 * @param children
 * @return
 */
public static Document addChildContentListInCustomOrder(Document oldXML, PID container, List<PID> children,
        Collection<PID> reorderedPids) {
    log.debug("HERE incoming children:");
    for (int i = 0; i < children.size(); i++) {
        log.debug(i + " => " + children.get(i));
    }

    // first build a list of existing pid order in the container
    Element parentDiv = oldXML.getRootElement().getChild("div", JDOMNamespaceUtil.METS_NS);
    List<Element> childDivs = parentDiv.getChildren();
    int maxExistingOrder = 5;
    if (childDivs.size() > 0) {
        maxExistingOrder = Integer.parseInt(childDivs.get(childDivs.size() - 1).getAttributeValue("ORDER"));
    }
    ArrayList<PID> order = new ArrayList<PID>(maxExistingOrder);
    try {
        for (Element child : childDivs) {
            int ord = Integer.parseInt(child.getAttributeValue("ORDER"));
            PID pid = new PID(child.getAttributeValue("ID"));
            if (ord >= order.size()) {
                while (ord > order.size()) { // insert nulls
                    order.add(null);
                }
                order.add(pid);
            } else {
                order.add(ord, pid);
            }
        }
    } catch (NullPointerException e) {
        throw new IllegalRepositoryStateException("Invalid container contents XML (MD_CONTENTS) on: ", e);
    }

    log.debug("HERE order before merge:");
    for (int i = 0; i < order.size(); i++) {
        log.debug(i + " => " + order.get(i));
    }

    PID[] originalOrder = order.toArray(new PID[0]);

    // clear out the current children
    parentDiv.removeContent();

    int maxIncomingOrder = 0;
    if (children.size() > 0) {
        maxIncomingOrder = children.size() - 1;
    }
    int capacityEstimate = Math.max(maxIncomingOrder, maxExistingOrder) + 10;
    order.ensureCapacity(capacityEstimate);

    for (ListIterator<PID> foo = children.listIterator(); foo.hasNext();) {
        int ord = foo.nextIndex();
        PID child = foo.next();
        if (ord >= order.size()) {
            while (ord > order.size()) { // insert nulls
                order.add(null);
            }
            order.add(child);
        } else {
            order.add(ord, child);
        }
    }

    log.debug("HERE order after merge:");
    for (int i = 0; i < order.size(); i++) {
        log.debug(i + " => " + order.get(i));
    }

    for (int i = 0; i < originalOrder.length; i++) {
        PID orig = originalOrder[i];
        if (orig != null) {
            if (!orig.equals(order.get(i))) {
                reorderedPids.add(orig);
            }
        }
    }

    for (ListIterator<PID> li = order.listIterator(); li.hasNext();) {
        int ord = li.nextIndex();
        PID pid = li.next();
        if (pid != null) {
            Element el = new Element("div", parentDiv.getNamespace()).setAttribute("ID", pid.getPid())
                    .setAttribute("ORDER", String.valueOf(ord));
            parentDiv.addContent(el);
        }
    }

    return oldXML;
}

From source file:net.paoding.rose.jade.statement.DefaultInterpreterFactory.java

public synchronized void addInterpreter(Interpreter interpreter) {
    if (!ArrayUtils.contains(this.interpreters, interpreter)) {
        ArrayList<Interpreter> interpreters = new ArrayList<Interpreter>(this.interpreters.length + 1);
        interpreters.add(interpreter);/*from  w  w w .j a  v  a  2s.  c  o  m*/
        Collections.sort(interpreters, new InterpreterComparator());
        this.interpreters = interpreters.toArray(new Interpreter[0]);
    }
}

From source file:com.mozilla.socorro.hadoop.CrashCount2.java

/**
 * Generates an array of scans for different salted ranges for the given dates
 * @param startDateAsInt/*from   ww w .j  ava2s  . c  o  m*/
 * @param endDateAsInt
 * @return
 */
public static Scan[] generateScans(int startDateAsInt, int endDateAsInt) {
    ArrayList<Scan> scans = new ArrayList<Scan>();
    String[] salts = new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e",
            "f" };
    for (int d = startDateAsInt; d <= endDateAsInt; d++) {
        for (int i = 0; i < salts.length; i++) {
            Scan s = new Scan();
            // this caching number is selected by 64MB / Mean JSON Size
            s.setCaching(1788);
            // disable block caching
            s.setCacheBlocks(false);
            // only looking for processed data
            s.addFamily(PROCESSED_DATA_BYTES);

            s.setStartRow(Bytes.toBytes(salts[i] + String.format("%06d", d)));
            s.setStopRow(Bytes.toBytes(salts[i] + String.format("%06d", d + 1)));

            scans.add(s);
        }
    }

    return scans.toArray(new Scan[scans.size()]);
}

From source file:com.dtolabs.rundeck.core.execution.script.ExecTaskParameterGeneratorImpl.java

/**
 *
 * @throws ExecutionException if an error occurs
 * @param nodeentry/*from   w w w .j av  a2 s  .co  m*/
 * @param command
 * @param scriptfile
 * @param args
 */
public ExecTaskParameters generate(final INodeEntry nodeentry, final boolean command, final File scriptfile,
        final String[] args) throws ExecutionException {
    final String commandexecutable;
    final String[] commandargs;

    if (!command && null == scriptfile) {
        throw new ExecutionException("Could not determine the command to dispatch");
    }
    if ("windows".equals(nodeentry.getOsFamily())) {
        //TODO: escape args properly for windows
        commandexecutable = "cmd.exe";
        if (command) {
            ArrayList<String> list = new ArrayList<String>();
            list.add(0, "/c");
            list.addAll(Arrays.asList(args));
            commandargs = list.toArray(new String[list.size()]);
        } else if (null != scriptfile) {
            //commandString is the script file location
            ArrayList<String> list = new ArrayList<String>();
            list.add(scriptfile.getAbsolutePath());
            if (args != null && args.length > 0) {
                list.addAll(Arrays.asList(args));
            }
            list.add(0, "/c");
            commandargs = list.toArray(new String[list.size()]);
        } else {
            throw new ExecutionException("Could not determine the command to dispatch");
        }
    } else {
        if (command) {
            commandexecutable = "/bin/sh";
            commandargs = new String[] { "-c", StringUtils.join(args, " ") };
        } else if (null != scriptfile) {
            final String scriptPath = scriptfile.getAbsolutePath();
            commandexecutable = scriptPath;
            commandargs = args;
        } else {
            throw new ExecutionException("Could not determine the command to dispatch");
        }
    }
    return new ExecTaskParameters() {
        public String getCommandexecutable() {
            return commandexecutable;
        }

        public String[] getCommandArgs() {
            return commandargs;
        }
    };
}

From source file:RHHBaseRecorder.java

public static Scan[] getAllColumnQualifier(HTable table) {
    ArrayList<Scan> scans = new ArrayList<Scan>();
    Scan scans2 = new Scan();
    try {//www .  jav  a 2  s. com
        int count = 0;

        ResultScanner ss = table.getScanner(scans2);
        for (Result r : ss) {
            for (KeyValue kv : r.raw()) {
                //System.out.print("\n Rowkey " +org.apache.commons.codec.binary.Base64.encodeBase64String(kv.getRow())  ); 
                // System.out.print(new String(kv.getFamily()) + ":");
                //System.out.print(org.apache.commons.codec.binary.Base64.encodeBase64String(kv.getQualifier() )+ " ");   
                //s.addFamily(kv.getFamily());
                scans2.addColumn(kv.getFamily(), kv.getQualifier());
            }
        }
        //return s;
    } catch (IOException e) {
        e.printStackTrace();
    }
    scans.add(scans2);
    return scans.toArray(new Scan[scans.size()]);
}

From source file:gdt.jgui.entity.folder.JFolderPanel.java

public static JFileOpenItem[] sort(JFileOpenItem[] foia) {
    ArrayList<String> sl = new ArrayList<String>();
    String title$;//from   w ww .jav a2s  .c  o  m
    Hashtable<String, JFileOpenItem> map = new Hashtable<String, JFileOpenItem>();
    if (foia == null)
        return null;
    for (JFileOpenItem foi : foia) {
        title$ = foi.getTitle();
        if (title$ == null)
            continue;
        sl.add(title$);
        map.put(title$, foi);
    }
    Collections.sort(sl);
    String[] sa = sl.toArray(new String[0]);
    ArrayList<Object> foil = new ArrayList<Object>();
    for (String aSa : sa) {
        foil.add(map.get(aSa));
    }
    return foil.toArray(new JFileOpenItem[0]);
}

From source file:com.manydesigns.portofino.persistence.QueryUtils.java

/**
 * Merges a HQL query string with a {@link TableCriteria} object representing a search. The query string is
 * processed with an {@link OgnlSqlFormat}, so it can access values from the OGNL context, as well as from an
 * (optional) root object./*ww w. j  a va 2 s  . co m*/
 * 
 * @param queryString the base query
 * @param criteria the criteria to merge with the query
 * @param rootObject the OGNL root object (can be null)
 * @return the merged query
 */
public static QueryStringWithParameters mergeQuery(String queryString, @Nullable TableCriteria criteria,
        Object rootObject) {
    OgnlSqlFormat sqlFormat = OgnlSqlFormat.create(queryString);
    String formatString = sqlFormat.getFormatString();
    Object[] parameters = sqlFormat.evaluateOgnlExpressions(rootObject);

    CCJSqlParserManager parserManager = new CCJSqlParserManager();
    PlainSelect parsedQueryString;
    PlainSelect parsedCriteriaQuery;
    try {
        parsedQueryString = parseQuery(parserManager, formatString);
    } catch (JSQLParserException e) {
        throw new RuntimeException("Couldn't merge query", e);
    }

    String mainEntityAlias = null;
    if (criteria != null) {
        mainEntityAlias = getEntityAlias(criteria.getTable().getActualEntityName(), parsedQueryString);
    }

    QueryStringWithParameters criteriaQuery = getQueryStringWithParametersForCriteria(criteria,
            mainEntityAlias);
    String criteriaQueryString = criteriaQuery.getQueryString();
    Object[] criteriaParameters = criteriaQuery.getParameters();

    try {
        if (StringUtils.isEmpty(criteriaQueryString)) {
            parsedCriteriaQuery = new PlainSelect();
        } else {
            parsedCriteriaQuery = parseQuery(parserManager, criteriaQueryString);
        }
    } catch (JSQLParserException e) {
        throw new RuntimeException("Couldn't merge query", e);
    }

    Expression whereExpression;
    if (parsedQueryString.getWhere() != null) {
        if (parsedCriteriaQuery.getWhere() != null) {
            whereExpression = parsedQueryString.getWhere();
            if (!(whereExpression instanceof Parenthesis)) {
                whereExpression = new Parenthesis(whereExpression);
            }
            whereExpression = new AndExpression(whereExpression, parsedCriteriaQuery.getWhere());
        } else {
            whereExpression = parsedQueryString.getWhere();
        }
    } else {
        whereExpression = parsedCriteriaQuery.getWhere();
    }
    parsedQueryString.setWhere(whereExpression);
    if (criteria != null && criteria.getOrderBy() != null) {
        List orderByElements = new ArrayList();
        OrderByElement orderByElement = new OrderByElement();
        orderByElement.setAsc(criteria.getOrderBy().isAsc());
        String propertyName = criteria.getOrderBy().getPropertyAccessor().getName();
        if (mainEntityAlias != null) {
            propertyName = mainEntityAlias + "." + propertyName;
        }
        orderByElement.setExpression(
                new net.sf.jsqlparser.schema.Column(new net.sf.jsqlparser.schema.Table(), propertyName));
        orderByElements.add(orderByElement);
        if (parsedQueryString.getOrderByElements() != null) {
            for (Object el : parsedQueryString.getOrderByElements()) {
                OrderByElement toAdd = (OrderByElement) el;
                if (toAdd.getExpression() instanceof net.sf.jsqlparser.schema.Column) {
                    net.sf.jsqlparser.schema.Column column = (net.sf.jsqlparser.schema.Column) toAdd
                            .getExpression();
                    if (StringUtils.isEmpty(column.getTable().getName())
                            && propertyName.equals(column.getColumnName())) {
                        continue; // do not add
                    }
                }
                orderByElements.add(toAdd);
            }
        }
        parsedQueryString.setOrderByElements(orderByElements);
    }
    String fullQueryString = parsedQueryString.toString();
    if (fullQueryString.toLowerCase().startsWith(FAKE_SELECT_PREFIX)) {
        fullQueryString = fullQueryString.substring(FAKE_SELECT_PREFIX.length());
    }

    // merge the parameters
    ArrayList<Object> mergedParametersList = new ArrayList<Object>();
    mergedParametersList.addAll(Arrays.asList(parameters));
    mergedParametersList.addAll(Arrays.asList(criteriaParameters));
    Object[] mergedParameters = new Object[mergedParametersList.size()];
    mergedParametersList.toArray(mergedParameters);

    return new QueryStringWithParameters(fullQueryString, mergedParameters);
}

From source file:importer.filters.MarkupSet.java

/**
 * Print an array of queued end-tags (as ranges) in reverse order
 * @param tags the queued tags//from   www  . j a  v  a2 s . c  o  m
 */
void printEndTags(ArrayList<Range> tags) {
    // first insert sort ranges
    Range[] ranges = new Range[tags.size()];
    tags.toArray(ranges);
    for (int i = 1; i < ranges.length; i++) {
        Range key = ranges[i];
        int j = i - 1;
        while (j >= 0 && ranges[j].offset < key.offset) {
            ranges[j + 1] = ranges[j];
            j = j - 1;
        }
        ranges[j + 1] = key;
    }
    for (int i = 0; i < ranges.length; i++) {
        Range r = tags.get(i);
        System.out.print("</" + ranges[i].name + ">");
    }
    tags.clear();
}