Example usage for java.util Vector copyInto

List of usage examples for java.util Vector copyInto

Introduction

In this page you can find the example usage for java.util Vector copyInto.

Prototype

public synchronized void copyInto(Object[] anArray) 

Source Link

Document

Copies the components of this vector into the specified array.

Usage

From source file:org.openbravo.erpCommon.ad_process.AlertProcess.java

private static AlertProcessData[] selectAlert(ConnectionProvider connectionProvider, String alertRule,
        String alertRuleId) throws ServletException {
    String alertRuleSQL = (alertRule == null || alertRule.equals("")) ? "" : alertRule;
    String strSql = "SELECT * FROM (" + alertRuleSQL + ") AAA where not exists ("
            + "select 1 from ad_alert a where a.ad_alertrule_id = ? "
            + "and a.referencekey_id = aaa.referencekey_id and coalesce(a.status, 'NEW') != 'SOLVED')";

    String dateTimeFormat = OBPropertiesProvider.getInstance().getOpenbravoProperties()
            .getProperty("dateTimeFormat.java");

    ResultSet result;/*from w  w  w . j  a va2  s. c o m*/
    Vector<java.lang.Object> vector = new Vector<java.lang.Object>(0);
    PreparedStatement st = null;

    try {
        connectionProvider.getConnection().setReadOnly(true);
        st = connectionProvider.getPreparedStatement(strSql);
        st.setString(1, alertRuleId);
        result = st.executeQuery();
        while (result.next()) {
            AlertProcessData objectAlertProcessData = new AlertProcessData();
            objectAlertProcessData.adClientId = UtilSql.getValue(result, "ad_client_id");
            objectAlertProcessData.adOrgId = UtilSql.getValue(result, "ad_org_id");
            objectAlertProcessData.created = UtilSql.getDateTimeValue(result, "created", dateTimeFormat);
            objectAlertProcessData.createdby = UtilSql.getValue(result, "createdby");
            objectAlertProcessData.updated = UtilSql.getValue(result, "updated");
            objectAlertProcessData.updatedby = UtilSql.getValue(result, "updatedby");
            objectAlertProcessData.recordId = UtilSql.getValue(result, "record_id");
            objectAlertProcessData.referencekeyId = UtilSql.getValue(result, "referencekey_id");
            objectAlertProcessData.description = UtilSql.getValue(result, "description");
            objectAlertProcessData.isactive = UtilSql.getValue(result, "isactive");
            objectAlertProcessData.adUserId = UtilSql.getValue(result, "ad_user_id");
            objectAlertProcessData.adRoleId = UtilSql.getValue(result, "ad_role_id");
            vector.addElement(objectAlertProcessData);
        }
        result.close();
    } catch (SQLException e) {
        log4j.error("SQL error in query: " + strSql + "Exception:" + e);
        throw new ServletException("@CODE=" + Integer.toString(e.getErrorCode()) + "@" + e.getMessage());
    } catch (Exception ex) {
        log4j.error("Exception in query: " + strSql + "Exception:" + ex);
        throw new ServletException("@CODE=@" + ex.getMessage());
    } finally {
        try {
            connectionProvider.getConnection().setReadOnly(false);
            connectionProvider.releasePreparedStatement(st);
        } catch (Exception ignore) {
            ignore.printStackTrace();
        }
    }
    AlertProcessData objectAlertProcessData[] = new AlertProcessData[vector.size()];
    vector.copyInto(objectAlertProcessData);
    return (objectAlertProcessData);
}

From source file:com.jada.admin.AdminLookupDispatchAction.java

protected void initSiteProfiles(AdminMaintActionForm form, Site site) throws Exception {
    EntityManager em = JpaConnection.getInstance().getCurrentEntityManager();

    Vector<LabelValueBean> vector = new Vector<LabelValueBean>();
    Long siteProfileClassDefaultId = null;
    SiteProfileClass siteProfileClassDefault = site.getSiteProfileClassDefault();
    if (siteProfileClassDefault != null) {
        siteProfileClassDefaultId = siteProfileClassDefault.getSiteProfileClassId();
        form.setSiteProfileClassDefaultId(siteProfileClassDefaultId);
        vector.add(new LabelValueBean(siteProfileClassDefault.getSiteProfileClassName(),
                siteProfileClassDefault.getSiteProfileClassId().toString()));
    }// w  w  w  .ja  va 2  s .  c o  m

    String sql = "from   SiteProfileClass siteProfileClass " + "where  siteProfileClass.site.siteId = :siteId "
            + "order  by siteProfileClassName ";
    Query query = em.createQuery(sql);
    query.setParameter("siteId", site.getSiteId());
    Iterator<?> iterator = query.getResultList().iterator();
    while (iterator.hasNext()) {
        SiteProfileClass siteProfileClass = (SiteProfileClass) iterator.next();
        if (siteProfileClassDefault != null) {
            if (siteProfileClass.getSiteProfileClassId().equals(siteProfileClassDefaultId)) {
                continue;
            }
        }
        vector.add(new LabelValueBean(siteProfileClass.getSiteProfileClassName(),
                siteProfileClass.getSiteProfileClassId().toString()));
    }
    LabelValueBean siteProfileClassBeans[] = new LabelValueBean[vector.size()];
    vector.copyInto(siteProfileClassBeans);
    form.setSiteProfileClassBeans(siteProfileClassBeans);

    if (form.getSiteProfileClassId() != null) {
        boolean found = false;
        for (LabelValueBean bean : siteProfileClassBeans) {
            if (bean.getValue().equals(form.getSiteProfileClassId().toString())) {
                found = true;
                break;
            }
        }
        if (!found) {
            form.setSiteProfileClassId(null);
        }
    }

    if (form.getSiteProfileClassId() == null) {
        if (siteProfileClassDefault != null) {
            form.setSiteProfileClassId(siteProfileClassDefaultId);
        }
        form.setSiteProfileClassDefault(true);
    } else {
        if (siteProfileClassDefault == null || form.getSiteProfileClassId().equals(siteProfileClassDefaultId)) {
            form.setSiteProfileClassDefault(true);
        } else {
            form.setSiteProfileClassDefault(false);
        }
        form.setTranslationEnable(false);
        String fromLocale = "";
        String toLocale = "";
        fromLocale = siteProfileClassDefault.getLanguage().getGoogleTranslateLocale();
        SiteProfileClass siteProfileClass = (SiteProfileClass) em.find(SiteProfileClass.class,
                form.getSiteProfileClassId());
        toLocale = siteProfileClass.getLanguage().getGoogleTranslateLocale();
        if (!Format.isNullOrEmpty(fromLocale) && !Format.isNullOrEmpty(toLocale)
                && !fromLocale.equals(toLocale)) {
            form.setTranslationEnable(true);
            form.setFromLocale(fromLocale);
            form.setToLocale(toLocale);
        }
    }

    vector = new Vector<LabelValueBean>();
    Long siteCurrencyClassDefaultId = null;
    SiteCurrencyClass siteCurrencyClassDefault = site.getSiteCurrencyClassDefault();
    if (siteCurrencyClassDefault != null) {
        siteCurrencyClassDefaultId = siteCurrencyClassDefault.getSiteCurrencyClassId();
        form.setSiteCurrencyClassDefaultId(siteCurrencyClassDefaultId);
        vector.add(new LabelValueBean(siteCurrencyClassDefault.getSiteCurrencyClassName(),
                siteCurrencyClassDefault.getSiteCurrencyClassId().toString()));
    }

    sql = "from   SiteCurrencyClass siteCurrencyClass " + "where  siteCurrencyClass.site.siteId = :siteId "
            + "order  by siteCurrencyClassName ";
    query = em.createQuery(sql);
    query.setParameter("siteId", site.getSiteId());
    iterator = query.getResultList().iterator();
    while (iterator.hasNext()) {
        SiteCurrencyClass siteCurrencyClass = (SiteCurrencyClass) iterator.next();
        if (siteProfileClassDefault != null) {
            if (siteCurrencyClass.getSiteCurrencyClassId().equals(siteCurrencyClassDefaultId)) {
                continue;
            }
        }
        vector.add(new LabelValueBean(siteCurrencyClass.getSiteCurrencyClassName(),
                siteCurrencyClass.getSiteCurrencyClassId().toString()));
    }
    LabelValueBean siteCurrencyClassBeans[] = new LabelValueBean[vector.size()];
    vector.copyInto(siteCurrencyClassBeans);
    form.setSiteCurrencyClassBeans(siteCurrencyClassBeans);

    if (form.getSiteCurrencyClassId() == null) {
        if (siteCurrencyClassDefault != null) {
            form.setSiteCurrencyClassId(siteCurrencyClassDefaultId);
        }
        form.setSiteCurrencyClassDefault(true);
    } else {
        if (siteCurrencyClassDefault == null
                || form.getSiteCurrencyClassId().equals(siteCurrencyClassDefaultId)) {
            form.setSiteCurrencyClassDefault(true);
        } else {
            form.setSiteCurrencyClassDefault(false);
        }
    }
}

From source file:hudson.org.apache.tools.ant.taskdefs.cvslib.ChangeLogTask.java

/**
 * Filter the specified entries according to an appropriate rule.
 *
 * @param entrySet the entry set to filter
 * @return the filtered entry set/*from ww  w . java 2  s .c o m*/
 */
private CVSEntry[] filterEntrySet(final CVSEntry[] entrySet) {
    log("Filtering entries", Project.MSG_VERBOSE);

    final Vector results = new Vector();

    for (int i = 0; i < entrySet.length; i++) {
        final CVSEntry cvsEntry = entrySet[i];
        final Date date = cvsEntry.getDate();

        if (date == null) {
            // skip dates that didn't parse.
            log("Filtering out " + cvsEntry + " because it has no date", Project.MSG_VERBOSE);
            continue;
        }

        if (null != m_start && m_start.after(date)) {
            //Skip dates that are too early
            log("Filtering out " + cvsEntry + " because it's too early compare to " + m_start,
                    Project.MSG_VERBOSE);
            continue;
        }
        if (null != m_stop && m_stop.before(date)) {
            //Skip dates that are too late
            log("Filtering out " + cvsEntry + " because it's too late compare to " + m_stop,
                    Project.MSG_VERBOSE);
            continue;
        }
        //if tag was specified, it takes care of branches or HEAD, because it does not go out of one. Otherwise HEAD or specified Brach should be filtered
        if (null == getTag() && !cvsEntry.containsBranch(branch)) {
            // didn't match the branch
            log("Filtering out " + cvsEntry + " because it didn't match the branch '" + branch + "'",
                    Project.MSG_VERBOSE);
            continue;
        }
        results.addElement(cvsEntry);
    }

    final CVSEntry[] resultArray = new CVSEntry[results.size()];

    results.copyInto(resultArray);
    return resultArray;
}

From source file:Matrix.java

/**
 * Read a matrix from a stream. The format is the same the print method, so
 * printed matrices can be read back in (provided they were printed using US
 * Locale). Elements are separated by whitespace, all the elements for each
 * row appear on a single line, the last row is followed by a blank line.
 * //from   w w w.  j a v  a 2 s . c om
 * @param input
 *            the input stream.
 */

public static Matrix read(BufferedReader input) throws java.io.IOException {
    StreamTokenizer tokenizer = new StreamTokenizer(input);

    // Although StreamTokenizer will parse numbers, it doesn't recognize
    // scientific notation (E or D); however, Double.valueOf does.
    // The strategy here is to disable StreamTokenizer's number parsing.
    // We'll only get whitespace delimited words, EOL's and EOF's.
    // These words should all be numbers, for Double.valueOf to parse.

    tokenizer.resetSyntax();
    tokenizer.wordChars(0, 255);
    tokenizer.whitespaceChars(0, ' ');
    tokenizer.eolIsSignificant(true);
    java.util.Vector v = new java.util.Vector();

    // Ignore initial empty lines
    while (tokenizer.nextToken() == StreamTokenizer.TT_EOL)
        ;
    if (tokenizer.ttype == StreamTokenizer.TT_EOF)
        throw new java.io.IOException("Unexpected EOF on matrix read.");
    do {
        v.addElement(Double.valueOf(tokenizer.sval)); // Read & store 1st
        // row.
    } while (tokenizer.nextToken() == StreamTokenizer.TT_WORD);

    int n = v.size(); // Now we've got the number of columns!
    double row[] = new double[n];
    for (int j = 0; j < n; j++)
        // extract the elements of the 1st row.
        row[j] = ((Double) v.elementAt(j)).doubleValue();
    v.removeAllElements();
    v.addElement(row); // Start storing rows instead of columns.
    while (tokenizer.nextToken() == StreamTokenizer.TT_WORD) {
        // While non-empty lines
        v.addElement(row = new double[n]);
        int j = 0;
        do {
            if (j >= n)
                throw new java.io.IOException("Row " + v.size() + " is too long.");
            row[j++] = Double.valueOf(tokenizer.sval).doubleValue();
        } while (tokenizer.nextToken() == StreamTokenizer.TT_WORD);
        if (j < n)
            throw new java.io.IOException("Row " + v.size() + " is too short.");
    }
    int m = v.size(); // Now we've got the number of rows.
    double[][] A = new double[m][];
    v.copyInto(A); // copy the rows out of the vector
    return new Matrix(A);
}

From source file:net.longfalcon.newsj.nntp.client.CustomNNTPClient.java

/***
 * List all new articles added to the NNTP server since a particular
 * date subject to the conditions of the specified query.  If no new
 * new news is found, a zero length array will be returned.  If the
 * command fails, null will be returned.  You must add at least one
 * newsgroup to the query, else the command will fail.  Each String
 * in the returned array is a unique message identifier including the
 * enclosing &lt and &gt./*  ww  w  .j a  v a2  s .  c o  m*/
 * This uses the "NEWNEWS" command.
 * <p>
 * @param query  The query restricting how to search for new news.  You
 *    must add at least one newsgroup to the query.
 * @return An array of String instances containing the unique message
 *    identifiers for each new article added to the NNTP server.  If no
 *    new news is found, a zero length array will be returned.  If the
 *    command fails, null will be returned.
 * @exception NNTPConnectionClosedException
 *      If the NNTP server prematurely closes the connection as a result
 *      of the client being idle or some other reason causing the server
 *      to send NNTP reply code 400.  This exception may be caught either
 *      as an IOException or independently as itself.
 * @exception IOException  If an I/O error occurs while either sending a
 *      command to the server or receiving a reply from the server.
 *
 * @see #iterateNewNews(NewGroupsOrNewsQuery)
 ***/
@Override
public String[] listNewNews(NewGroupsOrNewsQuery query) throws IOException {
    if (!NNTPReply.isPositiveCompletion(newnews(query.getNewsgroups(), query.getDate(), query.getTime(),
            query.isGMT(), query.getDistributions()))) {
        return null;
    }

    Vector<String> list = new Vector<String>();
    BufferedReader reader = new DotTerminatedMessageReader(_reader_);

    String line;
    try {
        while ((line = reader.readLine()) != null) {
            list.addElement(line);
        }
    } finally {
        reader.close();
    }

    int size = list.size();
    if (size < 1) {
        return new String[0];
    }

    String[] result = new String[size];
    list.copyInto(result);

    return result;
}

From source file:org.openbravo.base.VariablesBase.java

/**
 * Retrieve a set of values belonging to a parameter passed to the servlet as part of a multi part
 * content./*from w  ww.  j  av  a 2 s  .  c o m*/
 * 
 * @param parameter
 *          The name of the parameter to be retrieved.
 * @param requestFilter
 *          filter used to validate the input against list of allowed inputs
 * @return String array containing the values of the parameter. Empty string if the content is not
 *         multipart.
 */
public String[] getMultiParameters(String parameter, RequestFilter requestFilter) {
    if (!isMultipart || items == null)
        return null;
    Iterator<FileItem> iter = items.iterator();
    Vector<String> result = new Vector<String>();
    while (iter.hasNext()) {
        FileItem item = iter.next();
        if (item.isFormField() && item.getFieldName().equals(parameter)) {
            try {
                String value = item.getString("UTF-8");
                filterRequest(requestFilter, value);
                result.addElement(value);
            } catch (Exception ex) {
            }
        }
    }
    String[] strResult = new String[result.size()];
    result.copyInto(strResult);
    return strResult;
}

From source file:org.efs.openreports.engine.ChartReportEngine.java

/**
 * Executes the Chart query and builds an array of ChartValues from the results.
 *///w ww  .  ja v  a 2  s  .  com
public ChartValue[] getChartValues(ReportChart reportChart, Map parameters) throws ProviderException {
    Connection conn = null;
    PreparedStatement pStmt = null;
    ResultSet rs = null;

    try {
        ReportDataSource dataSource = reportChart.getDataSource();
        conn = dataSourceProvider.getConnection(dataSource.getId());

        // Use JasperReports Query logic to parse parameters in chart
        // queries

        JRDesignQuery query = new JRDesignQuery();
        query.setText(reportChart.getQuery());

        // convert parameters to JRDesignParameters so they can be parsed
        Map jrParameters = ORUtil.buildJRDesignParameters(parameters);

        pStmt = JRQueryExecuter.getStatement(query, jrParameters, parameters, conn);

        rs = pStmt.executeQuery();

        Vector v = new Vector();

        int chartType = reportChart.getChartType();
        if (chartType == ReportChart.BAR_CHART) {
            while (rs.next()) {
                CategoryChartValue catValue = new CategoryChartValue();

                catValue.setValue(rs.getDouble(1));
                catValue.setSeries(rs.getString(2));
                catValue.setCategory(rs.getString(3));

                v.add(catValue);
            }
        } else if (chartType == ReportChart.PIE_CHART || chartType == ReportChart.RING_CHART) {
            while (rs.next()) {
                PieChartValue pieValue = new PieChartValue();

                pieValue.setValue(rs.getDouble(1));
                pieValue.setKey(rs.getString(2));

                v.add(pieValue);
            }
        } else if (chartType == ReportChart.XY_CHART) {
            while (rs.next()) {
                XYChartValue xyValue = new XYChartValue();

                xyValue.setSeries(rs.getString(1));
                xyValue.setValue(rs.getDouble(2));
                xyValue.setSecondValue(rs.getDouble(3));

                v.add(xyValue);
            }
        } else if (chartType == ReportChart.TIME_CHART) {
            while (rs.next()) {
                TimeChartValue timeValue = new TimeChartValue();

                timeValue.setSeries(rs.getString(1));
                timeValue.setValue(rs.getDouble(2));
                timeValue.setTime(rs.getTimestamp(3));

                v.add(timeValue);
            }
        }

        ChartValue[] values = new ChartValue[v.size()];
        v.copyInto(values);

        return values;
    } catch (Exception e) {
        e.printStackTrace();
        throw new ProviderException(
                LocalStrings.getString(LocalStrings.ERROR_CHARTQUERY_INVALID) + ": " + e.toString());
    } finally {
        try {
            if (rs != null)
                rs.close();
            if (pStmt != null)
                pStmt.close();
            if (conn != null)
                conn.close();
        } catch (Exception c) {
            log.error("Error closing");
        }
    }
}

From source file:EditorPaneExample16.java

public URL[] findLinks(Document doc, String protocol) {
    Vector links = new Vector();
    Vector urlNames = new Vector();
    URL baseURL = (URL) doc.getProperty(Document.StreamDescriptionProperty);

    if (doc instanceof HTMLDocument) {
        Element elem = doc.getDefaultRootElement();
        ElementIterator iterator = new ElementIterator(elem);

        while ((elem = iterator.next()) != null) {
            AttributeSet attrs = elem.getAttributes();
            Object link = attrs.getAttribute(HTML.Tag.A);
            if (link instanceof AttributeSet) {
                Object linkAttr = ((AttributeSet) link).getAttribute(HTML.Attribute.HREF);
                if (linkAttr instanceof String) {
                    try {
                        URL linkURL = new URL(baseURL, (String) linkAttr);
                        if (protocol == null || protocol.equalsIgnoreCase(linkURL.getProtocol())) {
                            String linkURLName = linkURL.toString();
                            if (urlNames.contains(linkURLName) == false) {
                                urlNames.addElement(linkURLName);
                                links.addElement(linkURL);
                            }//  w w  w .ja  v a2s.  co m
                        }
                    } catch (MalformedURLException e) {
                        // Ignore invalid links
                    }
                }
            }
        }
    }

    URL[] urls = new URL[links.size()];
    links.copyInto(urls);
    links.removeAllElements();
    urlNames.removeAllElements();

    return urls;
}

From source file:net.longfalcon.newsj.nntp.client.CustomNNTPClient.java

private NewsgroupInfo[] __readNewsgroupListing() throws IOException {

    BufferedReader reader = new DotTerminatedMessageReader(_reader_);
    // Start of with a big vector because we may be reading a very large
    // amount of groups.
    Vector<NewsgroupInfo> list = new Vector<NewsgroupInfo>(2048);

    String line;//from  w w  w. jav  a 2  s . co  m
    try {
        while ((line = reader.readLine()) != null) {
            NewsgroupInfo tmp = __parseNewsgroupListEntry(line);
            if (tmp != null) {
                list.addElement(tmp);
            } else {
                throw new MalformedServerReplyException(line);
            }
        }
    } finally {
        reader.close();
    }
    int size;
    if ((size = list.size()) < 1) {
        return new NewsgroupInfo[0];
    }

    NewsgroupInfo[] info = new NewsgroupInfo[size];
    list.copyInto(info);

    return info;
}

From source file:com.jada.content.template.TemplateEngine.java

protected ContentFilterBean[] getContentFilterBeans(HttpServletRequest request) throws Exception {
    Vector<ContentFilterBean> vector = new Vector<ContentFilterBean>();
    String filters[] = request.getParameterValues("filter");
    if (filters != null) {
        for (String filter : filters) {
            int pos = filter.indexOf(',');
            String customAttribId = filter.substring(0, pos);
            String customAttribOptionId = filter.substring(pos + 1);
            ContentFilterBean bean = new ContentFilterBean();
            bean.setCustomAttribId(Long.valueOf(customAttribId));
            bean.setCustomAttribOptionId(Long.valueOf(customAttribOptionId));
            CustomAttribute customAttribute = CustomAttributeDAO.load(siteDomain.getSite().getSiteId(),
                    Long.valueOf(customAttribId));
            bean.setSystemRecord(customAttribute.getSystemRecord());
            vector.add(bean);/*from  w w w  .  j a  v a  2 s.c  om*/
        }
    }
    ContentFilterBean contentFilterBeans[] = new ContentFilterBean[vector.size()];
    vector.copyInto(contentFilterBeans);
    return contentFilterBeans;
}