Example usage for java.util Vector addElement

List of usage examples for java.util Vector addElement

Introduction

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

Prototype

public synchronized void addElement(E obj) 

Source Link

Document

Adds the specified component to the end of this vector, increasing its size by one.

Usage

From source file:net.nosleep.superanalyzer.analysis.views.YearView.java

/**
 * Creates a sample dataset.//from   ww w. j  a  v  a2s. c  o  m
 * 
 * @return The dataset.
 */
private void refreshDataset() {

    // TimeSeries t1 = new TimeSeries("Songs you have", "Year", "Count");
    // TimeSeries t2 = new TimeSeries("Songs you played", "Year", "Count");

    XYSeries t1 = new XYSeries(Misc.getString("SONGS_YOU_HAVE"));
    XYSeries t2 = new XYSeries(Misc.getString("SONGS_YOU_PLAYED"));

    Stat itemStats = null;

    if (_comboBox == null) {
        itemStats = _analysis.getStats(Analysis.KIND_TRACK, null);
    } else {
        ComboItem item = (ComboItem) _comboBox.getSelectedItem();
        itemStats = _analysis.getStats(item.getKind(), item.getValue());
    }

    Vector yearCountListHave = new Vector();

    Hashtable years = itemStats.getYears();
    Enumeration e = years.keys();
    while (e.hasMoreElements()) {
        Integer year = (Integer) e.nextElement();
        Integer count = (Integer) years.get(year);
        // if (count.intValue() > 0)
        yearCountListHave.addElement(new YearCountItem(year.intValue(), count.intValue()));
    }
    Collections.sort(yearCountListHave, new YearCountComparator());
    for (int i = 0; i < yearCountListHave.size(); i++) {
        YearCountItem item = (YearCountItem) yearCountListHave.elementAt(i);
        // _dataset.addValue(item.Count, "Songs you have", new
        // Integer(item.Year));
        t1.add(item.Year, new Integer(item.Count));
    }

    Vector yearCountListPlay = new Vector();

    Hashtable yearPlays = itemStats.getPlayYears();
    e = yearPlays.keys();
    while (e.hasMoreElements()) {
        Integer year = (Integer) e.nextElement();
        Integer count = (Integer) yearPlays.get(year);
        // if (count.intValue() > 0)
        yearCountListPlay.addElement(new YearCountItem(year.intValue(), count.intValue()));
    }
    Collections.sort(yearCountListPlay, new YearCountComparator());
    for (int i = 0; i < yearCountListPlay.size(); i++) {
        YearCountItem item = (YearCountItem) yearCountListPlay.elementAt(i);
        // _dataset.addValue(item.Count, "Songs you've played", new
        // Integer(item.Year));
        t2.add(item.Year, new Integer(item.Count));
    }

    _dataset.removeAllSeries();

    _dataset.addSeries(t1);
    _dataset.addSeries(t2);

    // TimeSeriesCollection tsc = new TimeSeriesCollection(t1);

    XYPlot plot = (XYPlot) _chart.getPlot();
    NumberAxis axis = (NumberAxis) plot.getRangeAxis();

    axis.setAutoRangeStickyZero(false);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();

    renderer.setSeriesPaint(0, Theme.getColorSet()[0]);
    renderer.setSeriesPaint(1, Theme.getColorSet()[2]);

}

From source file:com.geodetix.geo.dao.PostGisGeometryDAOImpl.java

/**
 * PostGIS implementation of the  /*from  w w w  . ja  va  2s .c  o m*/
 * {@link com.geodetix.geo.interfaces.GeometryLocalHome#findByPolygon(org.postgis.Polygon)}
 * method
 * 
 * @return a collection of bean's primary key beeing found.
 * @param polygon the {@link org.postgis.Polygon} to search in.
 * @throws javax.ejb.FinderException launched if an error occours during the search operation.
 */
public java.util.Collection findByPolygon(org.postgis.Polygon polygon) throws javax.ejb.FinderException {

    PreparedStatement pstm = null;
    Connection con = null;
    ResultSet result = null;

    try {

        con = this.dataSource.getConnection();

        pstm = con.prepareStatement(PostGisGeometryDAO.FIND_BY_POLYGON_STATEMENT);

        pstm.setObject(1, new PGgeometry(polygon));

        result = pstm.executeQuery();

        Vector keys = new Vector();

        while (result.next()) {
            keys.addElement(result.getObject("id"));
        }

        return keys;

    } catch (SQLException se) {
        throw new EJBException(se);

    } finally {
        try {
            if (result != null) {
                result.close();
            }
        } catch (Exception e) {
        }

        try {
            if (pstm != null) {
                pstm.close();
            }
        } catch (Exception e) {
        }

        try {
            if (con != null) {
                con.close();
            }
        } catch (Exception e) {
        }
    }
}

From source file:com.globalsight.everest.usermgr.UserLdapHelper.java

/**
 * Get the Uset ID array from a NamingEnumeration
 */// ww w .j  a va2  s  .c o m
static Vector getUIDsVectorFromSearchResults(NamingEnumeration p_SearchResults) throws NamingException {

    Vector uids = new Vector();

    while (p_SearchResults.hasMoreElements()) {
        /* Next directory entry */
        Object searchResultObj = p_SearchResults.nextElement();
        if (searchResultObj instanceof SearchResult) {
            SearchResult tempSearchResult = (SearchResult) searchResultObj;
            Attributes entry = tempSearchResult.getAttributes();
            String uid = getSingleAttributeValue(entry.get(LDAP_ATTR_USERID));
            uids.addElement(uid);
        }
    }

    p_SearchResults.close();

    return uids;
}

From source file:com.instantme.model.PhotoEntryModel.java

public boolean fromJSONObject(JSONObject jobj, IAnimation anim) {
    boolean result = false;
    setAnimation(anim);/*from w  ww. j a  va2  s .co  m*/
    try {
        Vector _data = new Vector();
        JSONArray feeds = jobj.getJSONArray("data");
        int numElements = feeds.length();

        if (feeds != null) {
            for (int n = 0; n < numElements; n++) {
                //updateProgress( "Reading photo " + String.valueOf(n+1) + "/" + String.valueOf(numElements) + " ..." );
                JSONObject entry = feeds.getJSONObject(n);
                PhotoEntry pe = new PhotoEntry();
                pe.fromJSONObject(entry, anim);
                _data.addElement(pe);
            }
        }
        data = _data;
        String url = jobj.getJSONObject("pagination").getString("next_url");
        cursor.push(url);
        //System.out.println("Stack [" + cursor.size() + "] = " + url);
        result = true;

    } catch (JSONException ex) {
        ex.printStackTrace();
    }

    return result;
}

From source file:Importers.ImportReportCompiler.java

private Vector getHosts(Node node) {
    Vector hosts = new Vector();
    NodeList children = node.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node n = children.item(i);
        if (n.getNodeType() == Node.ELEMENT_NODE) {
            String name = n.getNodeName();
            String value = n.getTextContent();
            if (name.equalsIgnoreCase("host")) {
                Host host = getHost(n);/*www .j  av  a  2s .  c  o m*/
                hosts.addElement(host);
            }
        }
    }
    return hosts;
}

From source file:com.globalsight.everest.usermgr.UserLdapHelper.java

static Vector getNamesVectorFromSearchResults(NamingEnumeration p_SearchResults) throws NamingException {
    Vector userNames = new Vector();

    while (p_SearchResults.hasMoreElements()) {
        /* Next directory entry */
        Object searchResultObj = p_SearchResults.nextElement();
        if (searchResultObj instanceof SearchResult) {
            SearchResult tempSearchResult = (SearchResult) searchResultObj;
            Attributes entry = tempSearchResult.getAttributes();
            String userName = getSingleAttributeValue(entry.get(LDAP_ATTR_USER_NAME));
            userNames.addElement(userName);
        }/*  w w w  .jav a 2s .  c om*/
    }

    p_SearchResults.close();

    return userNames;
}

From source file:DatabaseBrowser.java

public ResultSetTableModel(ResultSet rset) throws SQLException {
    Vector rowData;
    ResultSetMetaData rsmd = rset.getMetaData();
    int count = rsmd.getColumnCount();
    columnHeaders = new Vector(count);
    tableData = new Vector();
    for (int i = 1; i <= count; i++) {
        columnHeaders.addElement(rsmd.getColumnName(i));
    }//from w w w.  ja  v a2 s.co m
    while (rset.next()) {
        rowData = new Vector(count);
        for (int i = 1; i <= count; i++) {
            rowData.addElement(rset.getObject(i));
        }
        tableData.addElement(rowData);
    }
}

From source file:de.juwimm.cms.components.remote.ComponentsServiceSpringImpl.java

/**
 * @see de.juwimm.cms.components.remote.ComponentsServiceSpring#getDepartments4Name(java.lang.String)
 *//*w w  w  . j  a  va  2s . c  o m*/
@Override
protected DepartmentValue[] handleGetDepartments4Name(String name) throws Exception {
    UserHbm user = null;
    Iterator<DepartmentHbm> it = null;
    try {
        user = getUserHbmDao().load(AuthenticationHelper.getUserName());
        it = getDepartmentHbmDao().findByName(user.getActiveSite().getSiteId(), name).iterator();
    } catch (Exception e) {
        throw new UserException(e.getMessage());
    }
    Vector<DepartmentValue> vec = new Vector<DepartmentValue>();
    while (it.hasNext()) {
        vec.addElement(it.next().getDao(0));
    }
    return vec.toArray(new DepartmentValue[0]);
}

From source file:edu.indiana.lib.osid.base.repository.http.RepositoryManager.java

public org.osid.repository.RepositoryIterator getRepositoriesByType(org.osid.shared.Type repositoryType)
        throws org.osid.repository.RepositoryException {
    if (repositoryType == null) {
        throw new org.osid.repository.RepositoryException(org.osid.shared.SharedException.NULL_ARGUMENT);
    }//from   w ww .j  a  va  2 s  .  c  om

    java.util.Vector result = new java.util.Vector();
    org.osid.repository.RepositoryIterator repositoryIterator = getRepositories();

    while (repositoryIterator.hasNextRepository()) {
        org.osid.repository.Repository nextRepository = repositoryIterator.nextRepository();

        if (nextRepository.getType().isEqual(repositoryType)) {
            result.addElement(nextRepository);
        }
    }
    return new RepositoryIterator(result);
}

From source file:net.wastl.webmail.storage.FileStorage.java

protected void initLanguages() {
    log.info("Initializing available languages ... ");
    File f = new File(parent.getProperty("webmail.template.path") + System.getProperty("file.separator"));
    String[] flist = f.list(new FilenameFilter() {
        public boolean accept(File myf, String s) {
            if (myf.isDirectory() && s.equals(s.toLowerCase()) && (s.length() == 2 || s.equals("default"))) {
                return true;
            } else {
                return false;
            }/*from  ww  w  .  ja  v a 2s  .  com*/
        }
    });

    File cached = new File(
            parent.getProperty("webmail.data.path") + System.getProperty("file.separator") + "locales.cache");
    Locale[] available1 = null;

    /* Now we try to cache the Locale list since it takes really long to gather it! */
    boolean exists = cached.exists();
    if (exists) {
        try {
            ObjectInputStream in = new ObjectInputStream(new FileInputStream(cached));
            available1 = (Locale[]) in.readObject();
            in.close();
            log.info("Using disk cache for langs... ");
        } catch (Exception ex) {
            exists = false;
        }
    }
    if (!exists) {
        // We should cache this on disk since it is so slow!
        available1 = Collator.getAvailableLocales();
        ObjectOutputStream os = null;
        try {
            os = new ObjectOutputStream(new FileOutputStream(cached));
            os.writeObject(available1);
        } catch (IOException ioe) {
            log.error("Failed to write to storage", ioe);
        } finally {
            try {
                os.close();
            } catch (IOException ioe) {
                log.error("Failed to close stream", ioe);
            }
        }
    }

    // Do this manually, as it is not JDK 1.1 compatible ...
    //Vector available=new Vector(Arrays.asList(available1));
    Vector<Locale> available = new Vector<Locale>(available1.length);
    for (int i = 0; i < available1.length; i++) {
        available.addElement(available1[i]);
    }
    String s = "";
    int count = 0;
    for (int i = 0; i < flist.length; i++) {
        String cur_lang = flist[i];
        Locale loc = new Locale(cur_lang, "", "");
        Enumeration<Locale> enumVar = available.elements();
        boolean added = false;
        while (enumVar.hasMoreElements()) {
            Locale l = (Locale) enumVar.nextElement();
            if (l.getLanguage().equals(loc.getLanguage())) {
                s += l.toString() + " ";
                count++;
                added = true;
            }
        }
        if (!added) {
            s += loc.toString() + " ";
            count++;
        }
    }
    log.info(count + " languages initialized.");
    cs.configRegisterStringKey(this, "LANGUAGES", s, "Languages available in WebMail");
    setConfig("LANGUAGES", s);

    /*
      Setup list of themes for each language
    */
    for (int j = 0; j < flist.length; j++) {
        File themes = new File(parent.getProperty("webmail.template.path")
                + System.getProperty("file.separator") + flist[j] + System.getProperty("file.separator"));
        String[] themelist = themes.list(new FilenameFilter() {
            public boolean accept(File myf, String s3) {
                if (myf.isDirectory() && !s3.equals("CVS")) {
                    return true;
                } else {
                    return false;
                }
            }
        });
        String s2 = "";
        for (int k = 0; k < themelist.length; k++) {
            s2 += themelist[k] + " ";
        }
        cs.configRegisterStringKey(this, "THEMES_" + flist[j].toUpperCase(), s2,
                "Themes for language " + flist[j]);
        setConfig("THEMES_" + flist[j].toUpperCase(), s2);
    }
}