Example usage for java.util Vector size

List of usage examples for java.util Vector size

Introduction

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

Prototype

public synchronized int size() 

Source Link

Document

Returns the number of components in this vector.

Usage

From source file:eionet.meta.service.XmlConvServiceImpl.java

@Override
public SchemaConversionsData getSchemaConversionsData(String schemaUrl) throws ServiceException {
    SchemaConversionsData result = new SchemaConversionsData();

    InputStream inputStream = null;
    try {//from  w ww  .ja v a  2s  .c o m
        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();

        // Conversions
        String conversionsUrl = Props.getRequiredProperty(PropsIF.XML_CONV_URL) + "/api/listConversions?schema="
                + schemaUrl;
        URL url = new URL(conversionsUrl);
        inputStream = url.openStream();
        Document doc = docBuilder.parse(inputStream);
        NodeList nodeList = doc.getElementsByTagName("conversion");
        result.setNumberOfConversions(nodeList.getLength());

        // QA Scrpits
        String scriptsUrl = Props.getRequiredProperty(PropsIF.XML_CONV_URL) + "/RpcRouter";
        String scriptsService = "XQueryService";
        ServiceClientIF client = ServiceClients.getServiceClient(scriptsService, scriptsUrl);
        @SuppressWarnings("unchecked")
        Vector<String> scriptsResult = (Vector<String>) client.getValue("listQAScripts",
                new Vector<String>(Collections.singletonList(schemaUrl)));
        result.setNumberOfQAScripts(scriptsResult.size());

        // XML Conv schema page url
        result.setXmlConvUrl(Props.getRequiredProperty(PropsIF.XML_CONV_URL) + "/do/viewSchemaForm");

        return result;
    } catch (Exception e) {
        throw new ServiceException("Failed to get scripts and conversions info from XmlConv: " + e.getMessage(),
                e);
    } finally {
        IOUtils.closeQuietly(inputStream);
    }
}

From source file:edu.ku.brc.specify.dbsupport.AccessionAutoNumberAlphaNum.java

@Override
protected String getHighestObject(final UIFieldFormatterIFace formatter, final Session session,
        final String value, final Pair<Integer, Integer> yearPos, final Pair<Integer, Integer> pos)
        throws Exception {
    Division currDivision = AppContextMgr.getInstance().getClassObject(Division.class);

    String ansSQL = "SELECT ans.AutonumberingSchemeID, ans.FormatName, ans.IsNumericOnly, ans.SchemeName, dv.Name, dv.DivisionID "
            + "FROM autonumberingscheme ans "
            + "Inner Join autonumsch_div ad ON ans.AutoNumberingSchemeID = ad.AutoNumberingSchemeID "
            + "Inner Join division dv ON ad.DivisionID = dv.UserGroupScopeId WHERE dv.UserGroupScopeId = %d AND FormatName = '%s'";
    String sql = String.format(ansSQL, currDivision.getId(), formatter.getName());
    log.debug(sql);/* w w  w .  j  a va 2  s  .c o m*/

    Vector<Object[]> rows = BasicSQLUtils.query(sql);
    Integer ansID = null;
    if (rows.size() == 1) {
        ansID = (Integer) rows.get(0)[0];

    } else if (rows.size() == 0) {
        errorMsg = "There are NO formatters named [" + formatter.getName() + "]";
    } else {
        errorMsg = "Too many Formatters named [" + formatter.getName() + "]";
    }

    if (ansID == null) {
        log.debug(errorMsg);
        return null;
    }

    //String sql          = "SELECT autonumberingscheme.FormatName, autonumberingscheme.SchemeName, autonumberingscheme.IsNumericOnly, collection.CollectionName, discipline.Name, division.Name, accession.AccessionNumber FROM autonumberingscheme Inner Join autonumsch_coll ON autonumberingscheme.AutoNumberingSchemeID = autonumsch_coll.AutoNumberingSchemeID Inner Join collection ON autonumsch_coll.CollectionID = collection.UserGroupScopeId Inner Join discipline ON collection.DisciplineID = discipline.UserGroupScopeId Inner Join division ON discipline.DivisionID = division.UserGroupScopeId Inner Join accession ON division.UserGroupScopeId = accession.DivisionID ";
    //String ansToDivLong = "SELECT ans.FormatName, ans.SchemeName, ans.IsNumericOnly, c.CollectionName, ds.Name, dv.Name FROM autonumberingscheme ans Inner Join autonumsch_coll ac ON ans.AutoNumberingSchemeID = ac.AutoNumberingSchemeID Inner Join collection c ON ac.CollectionID = c.UserGroupScopeId Inner Join discipline ds ON c.DisciplineID = ds.UserGroupScopeId Inner Join division dv ON ds.DivisionID = dv.UserGroupScopeId ";
    String ansToDivSQL = "SELECT dv.UserGroupScopeId DivID FROM autonumberingscheme ans "
            + "Inner Join autonumsch_div ad ON ans.AutoNumberingSchemeID = ad.AutoNumberingSchemeID "
            + "Inner Join division dv ON ad.DivisionID = dv.UserGroupScopeId "
            + "WHERE ans.AutoNumberingSchemeID = %d";

    ansToDivSQL = String.format(ansToDivSQL, ansID);
    log.debug(ansToDivSQL);

    Vector<Integer> divIds = new Vector<Integer>();
    for (Object[] row : BasicSQLUtils.query(ansToDivSQL)) {
        divIds.add((Integer) row[0]);
    }

    Integer yearVal = null;
    if (yearPos != null && StringUtils.isNotEmpty(value) && value.length() >= yearPos.second) {
        yearVal = extractIntegerValue(yearPos, value).intValue();
    }

    StringBuilder sb = new StringBuilder(
            "SELECT a.accessionNumber FROM Accession a Join a.division dv Join dv.numberingSchemes ans WHERE ans.id = ");
    AutoNumberingScheme accessionAutoNumScheme = currDivision
            .getNumberingSchemesByType(Accession.getClassTableId());
    if (accessionAutoNumScheme != null && accessionAutoNumScheme.getAutoNumberingSchemeId() != null) {
        sb.append(accessionAutoNumScheme.getAutoNumberingSchemeId());
        sb.append(" AND dv.id in (");
        for (Integer dvId : divIds) {
            sb.append(dvId);
            sb.append(',');
        }
        sb.setLength(sb.length() - 1);
        sb.append(')');

    } else {
        UIRegistry.showError("There is no AutonumberingScheme for the Accession formatter!");
        return "";
    }

    if (yearVal != null) {
        sb.append(" AND ");
        sb.append(yearVal);
        sb.append(" = substring(" + fieldName + "," + (yearPos.first + 1) + ","
                + (yearPos.second - yearPos.first) + ")");
    }

    sb.append(" ORDER BY");

    try {
        if (yearPos != null) {
            sb.append(" substring(" + fieldName + "," + (yearPos.first + 1) + ","
                    + (yearPos.second - yearPos.first) + ") desc");
        }

        if (pos != null) {
            if (yearPos != null) {
                sb.append(", ");
            }
            sb.append(" substring(" + fieldName + "," + (pos.first + 1) + "," + (pos.second - pos.first)
                    + ") desc");
        }

        System.out.println("AccessionAutoNumberAlphaNum - " + sb.toString());

        List<?> list = session.createQuery(sb.toString()).setMaxResults(1).list();
        if (list.size() == 1) {
            return list.get(0).toString();
        }
    } catch (Exception ex) {
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(AccessionAutoNumberAlphaNum.class, ex);
        ex.printStackTrace();
    }
    return null;
}

From source file:com.autoparts.buyers.activity.SelectModeActivity.java

public void setData(ResponseModel responseModel) {

    //        {/*  w  ww .ja  v  a2  s . c om*/
    //            "partbandid": 3,
    //                "nam": "",
    //                "pic": "http://123.56.87.239:81/auto/resource/partband/1434756909.png"
    //        }

    Vector<HashMap<String, Object>> maps = responseModel.getMaps();
    if (maps != null && maps.size() > 0) {
        for (int i = 0; i < maps.size(); i++) {
            HashMap<String, Object> map = maps.get(i);
            String bandid = (String) map.get("partbandid");
            String nam = (String) map.get("nam");
            String pic = (String) map.get("pic");
            CommonLetterModel commonLetterModel = new CommonLetterModel();

            commonLetterModel.setUser_id(bandid);
            commonLetterModel.setUser_image(pic);
            commonLetterModel.setUser_name(nam);

            String key = "#";
            if (!TextUtils.isEmpty(nam)) {
                key = new ContactUtils().getPinYinHeadChar(nam.substring(0, 1));
                key = key.toUpperCase();
                if (TextUtils.isEmpty(key)) {
                    key = "#";
                }
            }
            commonLetterModel.setUser_key(key);

            mList.add(commonLetterModel);
        }

        mList = contactUtils.getListKey(mList);
        mIndexer = contactUtils.getmIndexer();
        actionsAdapter.setData(mList);
        actionsAdapter.notifyDataSetChanged();
        setDataNull(false);
    } else {
        setDataNull(true);
    }
}

From source file:edu.ku.brc.af.ui.db.TextFieldFromPickListTable.java

public void setValue(final Object value, final String defaultValue) {
    dataObj = value;/*from  www  .  j  a v  a 2s  .c om*/

    if (value != null) {
        if (adapter == null) {
            setText(value.toString());
            return;
        }

        if (adapter.isTabledBased()) {
            String data = null;

            boolean isFormObjIFace = value instanceof FormDataObjIFace;
            Vector<PickListItemIFace> items = adapter.getList();

            for (int i = 0; i < items.size(); i++) {
                PickListItemIFace pli = items.get(i);
                Object valObj = pli.getValueObject();

                if (valObj != null) {
                    if (isFormObjIFace && valObj instanceof FormDataObjIFace) {
                        //System.out.println(((FormDataObjIFace)value).getId().longValue()+"  "+(((FormDataObjIFace)valObj).getId().longValue()));
                        if (((FormDataObjIFace) value).getId()
                                .intValue() == (((FormDataObjIFace) valObj).getId().intValue())) {
                            data = pli.getTitle();
                            break;
                        }
                    } else if (pli.getValue().equals(value.toString())) {
                        data = pli.getTitle();
                        break;
                    }
                }
            }

            if (data == null) {
                data = StringUtils.isNotEmpty(defaultValue) ? defaultValue : ""; //$NON-NLS-1$
            }

            setText(data);

        } else {
            boolean fnd = false;
            setText("");
            for (PickListItemIFace item : adapter.getList()) {
                if (item.getValue() == null && value == null) {
                    break;

                } else if (item.getValue() != null && value != null
                        && item.getValue().equals(value.toString())) {
                    setText(item.getTitle());
                    fnd = true;
                    break;
                }
            }

            if (!fnd && !adapter.isReadOnly()) {
                setText(value != null ? value.toString() : defaultValue);
            }
        }

        repaint();
    } else {
        if (nullIndex == null) {
            if (adapter != null) {
                int inx = 0;
                for (PickListItemIFace item : adapter.getList()) {
                    if (item != null && item.getValue() != null && item.getValue().equals("|null|")) {
                        nullIndex = inx;
                        setText(item.getTitle());
                        break;
                    }
                    inx++;
                }
                if (nullIndex == null) {
                    nullIndex = -1;
                }
            }
        } else if (nullIndex > -1) {
            PickListItemIFace item = adapter.getList().get(nullIndex);
            if (item != null) {
                setText(item.getTitle());
            }
            return;
        } else if (nullIndex == -1) {
            setText("");
        }
    }
}

From source file:com.substanceofcode.twitter.model.Status.java

private String aboutStr(JSONObject user) {
    String accum = "";
    Vector a = aboutVec(user);
    for (int i = 0; i < a.size(); i++) {
        String[] kv = (String[]) a.elementAt(i);
        accum += kv[0] + ": " + kv[1] + "\n\n";
    }/*from w  w w .  j av  a  2 s. co m*/
    return accum;
}

From source file:JavaSort.java

public JavaSort() {
    Vector list = new Vector();
    list.add("\u00e4pple");
    list.add("banan");
    list.add("p\u00e4ron");
    list.add("orange");

    // Obtain a Swedish collator
    Collator collate = Collator.getInstance(new Locale("sv", ""));
    Collections.sort(list, collate);

    StringBuffer result = new StringBuffer();
    for (int i = 0; i < list.size(); i++) {
        result.append(list.elementAt(i));
        result.append(" ");
    }/*from w  w w .j ava  2s .c  o  m*/
    add(new JLabel(result.toString()));
}

From source file:com.xpn.xwiki.plugin.comments.internal.DefaultCommentsManager.java

public int getNumberOfCommentsInThread(XWikiDocument document, XWikiContext context) throws CommentsException {
    Vector objects = document.getObjects(getCommentsClassName(context));
    return (objects == null) ? 0 : objects.size();
}

From source file:eionet.gdem.services.db.dao.StylesheetDaoTest.java

@Test
public void updateStylesheet() throws SQLException {
    Stylesheet initialStylesheet = createStylesheetObject();
    String id = stylesheetDao.addStylesheet(initialStylesheet);

    Stylesheet addedStylesheet = stylesheetDao.getStylesheet(id);
    String[] schemaUrls = { "uniqueSchema3", "uniqueSchema4" };
    addedStylesheet.setSchemaUrls(Arrays.asList(schemaUrls));
    addedStylesheet.setDescription("newDescription");
    addedStylesheet.setDependsOn("9999");
    addedStylesheet.setType("EXCEL");

    stylesheetDao.updateStylesheet(addedStylesheet);
    Stylesheet updatedStylesheet = stylesheetDao.getStylesheet(id);
    assertStylesheet(addedStylesheet, updatedStylesheet);
    assertStylesheetSchemas(addedStylesheet, updatedStylesheet);

    //remove uniqueSchema3 and add uniqueSchema5
    String[] addedSchemaUrls = { "uniqueSchema4", "uniqueSchema5" };
    updatedStylesheet.setSchemaUrls(Arrays.asList(addedSchemaUrls));
    String deletedSchemaId = null;
    for (Schema schema : updatedStylesheet.getSchemas()) {
        if (schema.getSchema().equals("uniqueSchema4")) {
            String[] schemaIds = { schema.getId() };
            updatedStylesheet.setSchemaIds(Arrays.asList(schemaIds));
        } else if (schema.getSchema().equals("uniqueSchema3")) {
            deletedSchemaId = schema.getId();
        }//from  w w w.  j  a v a  2  s  . c  om
    }
    stylesheetDao.updateStylesheet(updatedStylesheet);
    Stylesheet reUpdatedStylesheet = stylesheetDao.getStylesheet(id);
    assertStylesheet(addedStylesheet, reUpdatedStylesheet);

    // check updated schemas
    assertEquals(reUpdatedStylesheet.getSchemas().size(), 2);
    List<String> remaingSchemaUrls = Arrays.asList(new String[] { "uniqueSchema4", "uniqueSchema5" });
    for (Schema schema : reUpdatedStylesheet.getSchemas()) {
        assertTrue(remaingSchemaUrls.contains(schema.getSchema()));
    }

    // check that deleted schema does not have relations anymore
    Vector<?> schemaStylesheets = schemaDao.getSchemaStylesheets(deletedSchemaId);
    assertEquals(schemaStylesheets.size(), 0);

}

From source file:com.yahoo.messenger.data.json.UserList.java

public void unserializeJSON(JSONArray a) throws JSONException {

    Vector v = new Vector();

    //  Mandatory fields

    for (int i = 0; i < a.length(); i++) {

        JSONObject o = a.getJSONObject(i);
        User c = new User();
        c.unserializeJSON(o.getJSONObject("user"));
        v.addElement(c);/*from   ww w .  jav  a  2s  .  com*/
    }

    users = new User[v.size()];
    v.copyInto(users);

}

From source file:Main.java

private DefaultMutableTreeNode addNodes(DefaultMutableTreeNode curTop, File dir) {
    String curPath = dir.getPath();
    DefaultMutableTreeNode curDir = new DefaultMutableTreeNode(curPath);
    if (curTop != null) {
        curTop.add(curDir);//  w  w w  .  ja  v a  2s.c  om
    }
    Vector<String> ol = new Vector<String>();
    String[] tmp = dir.list();
    for (int i = 0; i < tmp.length; i++) {
        ol.addElement(tmp[i]);
    }
    Collections.sort(ol, String.CASE_INSENSITIVE_ORDER);
    File f;
    Vector<Object> files = new Vector<Object>();
    for (int i = 0; i < ol.size(); i++) {
        String thisObject = ol.elementAt(i);
        String newPath;
        if (curPath.equals(".")) {
            newPath = thisObject;
        } else {
            newPath = curPath + File.separator + thisObject;
        }
        if ((f = new File(newPath)).isDirectory()) {
            addNodes(curDir, f);
        } else {
            files.addElement(thisObject);
        }
    }
    for (int fnum = 0; fnum < files.size(); fnum++) {
        curDir.add(new DefaultMutableTreeNode(files.elementAt(fnum)));
    }
    return curDir;
}