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:de.juwimm.cms.components.remote.ComponentsServiceSpringImpl.java

/**
 * @see de.juwimm.cms.components.remote.ComponentsServiceSpring#getUnits4Name(java.lang.String)
 *///from   ww  w.  ja v  a 2  s.c  o m
@Override
protected UnitValue[] handleGetUnits4Name(String name) throws Exception {
    try {
        Vector<UnitValue> vec = new Vector<UnitValue>();
        UserHbm user = getUserHbmDao().load(AuthenticationHelper.getUserName());
        Iterator it = getUnitHbmDao().findByName(user.getActiveSite().getSiteId(), name).iterator();
        while (it.hasNext()) {
            UnitHbm unit = (UnitHbm) it.next();
            vec.addElement(getUnitHbmDao().getDao(unit));
        }
        return vec.toArray(new UnitValue[0]);
    } catch (Exception e) {
        throw new UserException(e.getMessage());
    }
}

From source file:com.github.maven_nar.cpptasks.CCTask.java

/**
 * Builds a Hashtable to targets needing to be rebuilt keyed by compiler
 * configuration/*from   ww w .  ja  v a  2s.  c  o  m*/
 */
public static Map<CompilerConfiguration, Vector<TargetInfo>> getTargetsToBuildByConfiguration(
        final Map<String, TargetInfo> targets) {
    final Map<CompilerConfiguration, Vector<TargetInfo>> targetsByConfig = new HashMap<>();
    for (final TargetInfo target : targets.values()) {
        if (target.getRebuild()) {
            // FIXME: Types do not match between the key of targetsByConfig and the return value of target.getConfiguration
            Vector<TargetInfo> targetsForSameConfig = targetsByConfig.get(target.getConfiguration());
            if (targetsForSameConfig != null) {
                targetsForSameConfig.addElement(target);
            } else {
                targetsForSameConfig = new Vector<>();
                targetsForSameConfig.addElement(target);
                targetsByConfig.put((CompilerConfiguration) target.getConfiguration(), targetsForSameConfig);
            }
        }
    }
    return targetsByConfig;
}

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  www.  j  a  v a 2  s .  co m*/
 * @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:org.candlepin.util.X509CRLStreamWriter.java

/**
 * Create an entry to be added to the CRL.
 *
 * @param serial/* w w w  .  ja  v a2  s  . c o m*/
 * @param date
 * @param reason
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public void add(BigInteger serial, Date date, int reason) {
    if (locked) {
        throw new IllegalStateException("Cannot add to a locked stream.");
    }

    ASN1EncodableVector v = new ASN1EncodableVector();

    v.add(new DERInteger(serial));
    v.add(new Time(date));

    CRLReason crlReason = new CRLReason(reason);
    Vector extOids = new Vector();
    Vector extValues = new Vector();
    extOids.addElement(X509Extension.reasonCode);
    extValues.addElement(new X509Extension(false, new DEROctetString(crlReason.getDEREncoded())));
    v.add(new X509Extensions(extOids, extValues));

    newEntries.add(new DERSequence(v));
}

From source file:org.esupportail.portal.ws.groups.PortalGroups.java

/**
 * Permet de recuperer le nom du groupe passe en parametre, et recursivement les sous-groupes de celui-ci
 * @param igm un groupe donne de type IGroupMember
 * @return un tableau de 2 elements: le premier est le nom de ce groupe, le second est un vecteur d'autres sous-noeuds (ou sous-groupes). Renvoie null si le parametre n'est pas un groupe
 * @throws GroupsException/*  ww  w .  ja  va 2 s .co m*/
 */
private Object[] getSubGroups(IGroupMember igm) throws GroupsException {

    // on verifie que igm est bien un groupe
    if (igm.isGroup()) {

        // on caste en IEntityGroup pour avoir acces a la methode getKey()
        IEntityGroup egi = (IEntityGroup) igm;

        // on recupere la clef
        String key = egi.getKey();

        // un vecteur qui va contenir tous les noeuds fils de ce noeud
        Vector v = new Vector();

        // on recupere tous les sous-groupes de "name"
        Iterator allgroups = igm.getMembers();

        // on parcourt chacun de ces groupes
        while (allgroups.hasNext()) {

            // un fils de l'arbre
            IGroupMember g = (IGroupMember) allgroups.next();

            // pour chaque groupe fils, on va chercher recursivement ses sous-groupes
            Object[] subs = getSubGroups(g);

            // on ajoute ceci au vecteur
            if (subs != null)
                v.addElement(subs);
        }

        // on construit un tableau d'objets [N,V] ou
        // * N est le nom d'un noeud
        // * V est un vecteur d'autres noeuds
        Object[] res = new Object[2];
        res[0] = key;
        res[1] = v;
        return res;
    }

    // si igm n'est pas un groupe, on retourne null
    else {
        if (log.isDebugEnabled())
            log.debug("getSubGroups" + " :: " + igm.getKey() + " is not a valid group");
        return null;
    }
}

From source file:org.eshark.dctm.gui.model.DQLTableModel.java

/**
 * @param aDQLQuey/*from w w  w  . ja  v a2 s  .  c  o  m*/
 * @throws DfException
 */
public void executeQuery(String aDQLQuey) throws DfException {
    IDfQuery lQuery = new DfQuery();
    IDfCollection lCollection;
    IDfSession lSession = AppSessionManager.getInstance().getSession();
    if (lSession == null)
        return;
    //purge all
    mRows.clear();
    //System.out.println("DQL " + aDQLQuey);
    lQuery.setDQL(aDQLQuey);
    lCollection = lQuery.execute(lSession, IDfQuery.DF_READ_QUERY);
    int maxAttrs = lCollection.getAttrCount();
    mColumnNames = new String[maxAttrs];
    mColumnClasses = new Class[maxAttrs];
    for (int attrIndx = 0; attrIndx < maxAttrs; attrIndx++) {
        mColumnNames[attrIndx] = lCollection.getAttr(attrIndx).getName();
        mColumnClasses[attrIndx] = String.class;
    }
    //for each row
    Vector lRow = null;
    //For the data
    IDfTypedObject typeObject = null;
    IDfAttr typeAttr = null;
    String colValue = EMPTY;
    while (lCollection.next()) {
        typeObject = lCollection.getTypedObject();
        //Go to next row
        lRow = new Vector();
        // process each column in a row
        maxAttrs = typeObject.getAttrCount();
        for (int attrIndx = 0; attrIndx < maxAttrs; attrIndx++) {
            colValue = EMPTY;
            typeAttr = typeObject.getAttr(attrIndx);
            colValue = getColumnAsString(typeObject, typeAttr.getName(), typeAttr.getDataType());
            //System.out.println(colValue);
            lRow.addElement(colValue);
        }
        mRows.addElement(lRow);
    }
    lCollection.close();
    AppSessionManager.getInstance().releaseSession(lSession);
    fireTableChanged(null); // Tell the listeners a new table has arrived.
}

From source file:com.duroty.application.mail.actions.SendAction.java

protected ActionForward doExecute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    ActionMessages errors = new ActionMessages();

    try {// www  . j a va  2s  . c om
        boolean isMultipart = FileUpload.isMultipartContent(request);

        Mail mailInstance = getMailInstance(request);

        if (isMultipart) {
            Map fields = new HashMap();
            Vector attachments = new Vector();

            //Parse the request
            List items = diskFileUpload.parseRequest(request);

            //Process the uploaded items
            Iterator iter = items.iterator();

            while (iter.hasNext()) {
                FileItem item = (FileItem) iter.next();

                if (item.isFormField()) {
                    if (item.getFieldName().equals("forwardAttachments")) {
                        String[] aux = item.getString().split(":");
                        MailPartObj part = mailInstance.getAttachment(aux[0], aux[1]);
                        attachments.addElement(part);
                    } else {
                        fields.put(item.getFieldName(), item.getString());
                    }
                } else {
                    if (!StringUtils.isBlank(item.getName())) {
                        ByteArrayOutputStream baos = null;

                        try {
                            baos = new ByteArrayOutputStream();

                            IOUtils.copy(item.getInputStream(), baos);

                            MailPartObj part = new MailPartObj();
                            part.setAttachent(baos.toByteArray());
                            part.setContentType(item.getContentType());
                            part.setName(item.getName());
                            part.setSize(item.getSize());

                            attachments.addElement(part);
                        } catch (Exception ex) {
                        } finally {
                            IOUtils.closeQuietly(baos);
                        }
                    }
                }
            }

            String body = "";

            if (fields.get("taBody") != null) {
                body = (String) fields.get("taBody");
            } else if (fields.get("taReplyBody") != null) {
                body = (String) fields.get("taReplyBody");
            }

            Preferences preferencesInstance = getPreferencesInstance(request);

            Send sendInstance = getSendInstance(request);

            String mid = (String) fields.get("mid");

            if (StringUtils.isBlank(mid)) {
                request.setAttribute("action", "compose");
            } else {
                request.setAttribute("action", "reply");
            }

            Boolean isHtml = null;

            if (StringUtils.isBlank((String) fields.get("isHtml"))) {
                isHtml = new Boolean(preferencesInstance.getPreferences().isHtmlMessage());
            } else {
                isHtml = Boolean.valueOf((String) fields.get("isHtml"));
            }

            sendInstance.send(mid, Integer.parseInt((String) fields.get("identity")), (String) fields.get("to"),
                    (String) fields.get("cc"), (String) fields.get("bcc"), (String) fields.get("subject"), body,
                    attachments, isHtml.booleanValue(), Charset.defaultCharset().displayName(),
                    (String) fields.get("priority"));
        } else {
            errors.add("general",
                    new ActionMessage(ExceptionCode.ERROR_MESSAGES_PREFIX + "mail.send", "The form is null"));
            request.setAttribute("exception", "The form is null");
            request.setAttribute("newLocation", null);
            doTrace(request, DLog.ERROR, getClass(), "The form is null");
        }
    } catch (Exception ex) {
        String errorMessage = ExceptionUtilities.parseMessage(ex);

        if (errorMessage == null) {
            errorMessage = "NullPointerException";
        }

        errors.add("general", new ActionMessage(ExceptionCode.ERROR_MESSAGES_PREFIX + "general", errorMessage));
        request.setAttribute("exception", errorMessage);
        doTrace(request, DLog.ERROR, getClass(), errorMessage);
    } finally {
    }

    if (errors.isEmpty()) {
        doTrace(request, DLog.INFO, getClass(), "OK");

        return mapping.findForward(Constants.ACTION_SUCCESS_FORWARD);
    } else {
        saveErrors(request, errors);

        return mapping.findForward(Constants.ACTION_FAIL_FORWARD);
    }
}

From source file:FileTree2.java

public boolean expand(DefaultMutableTreeNode parent) {
    DefaultMutableTreeNode flag = (DefaultMutableTreeNode) parent.getFirstChild();
    if (flag == null) // No flag
        return false;
    Object obj = flag.getUserObject();
    if (!(obj instanceof Boolean))
        return false; // Already expanded

    parent.removeAllChildren(); // Remove Flag

    File[] files = listFiles();/*from  w ww.  jav  a 2  s . c o m*/
    if (files == null)
        return true;

    Vector v = new Vector();

    for (int k = 0; k < files.length; k++) {
        File f = files[k];
        if (!(f.isDirectory()))
            continue;

        FileNode newNode = new FileNode(f);

        boolean isAdded = false;
        for (int i = 0; i < v.size(); i++) {
            FileNode nd = (FileNode) v.elementAt(i);
            if (newNode.compareTo(nd) < 0) {
                v.insertElementAt(newNode, i);
                isAdded = true;
                break;
            }
        }
        if (!isAdded)
            v.addElement(newNode);
    }

    for (int i = 0; i < v.size(); i++) {
        FileNode nd = (FileNode) v.elementAt(i);
        IconData idata = new IconData(FileTree2.ICON_FOLDER, FileTree2.ICON_EXPANDEDFOLDER, nd);
        DefaultMutableTreeNode node = new DefaultMutableTreeNode(idata);
        parent.add(node);

        if (nd.hasSubDirs())
            node.add(new DefaultMutableTreeNode(new Boolean(true)));
    }

    return true;
}

From source file:FileTree3.java

public boolean expand(DefaultMutableTreeNode parent) {
    DefaultMutableTreeNode flag = (DefaultMutableTreeNode) parent.getFirstChild();
    if (flag == null) // No flag
        return false;
    Object obj = flag.getUserObject();
    if (!(obj instanceof Boolean))
        return false; // Already expanded

    parent.removeAllChildren(); // Remove Flag

    File[] files = listFiles();//w w w.  j  a  va 2  s  .  com
    if (files == null)
        return true;

    Vector v = new Vector();

    for (int k = 0; k < files.length; k++) {
        File f = files[k];
        if (!(f.isDirectory()))
            continue;

        FileNode newNode = new FileNode(f);

        boolean isAdded = false;
        for (int i = 0; i < v.size(); i++) {
            FileNode nd = (FileNode) v.elementAt(i);
            if (newNode.compareTo(nd) < 0) {
                v.insertElementAt(newNode, i);
                isAdded = true;
                break;
            }
        }
        if (!isAdded)
            v.addElement(newNode);
    }

    for (int i = 0; i < v.size(); i++) {
        FileNode nd = (FileNode) v.elementAt(i);
        IconData idata = new IconData(FileTree3.ICON_FOLDER, FileTree3.ICON_EXPANDEDFOLDER, nd);
        DefaultMutableTreeNode node = new DefaultMutableTreeNode(idata);
        parent.add(node);

        if (nd.hasSubDirs())
            node.add(new DefaultMutableTreeNode(new Boolean(true)));
    }

    return true;
}

From source file:com.instantme.api.InstagramAPI.java

private Vector split(String str, String sep) {
    Vector tokens = new Vector();
    int pos = 0;//w w w.  j a  v a2s.c  o m
    int lastPos = 0;
    pos = str.indexOf(sep, lastPos);
    while (pos != -1) {
        tokens.addElement(str.substring(lastPos, pos));
        lastPos = pos + 1;
        pos = str.indexOf(sep, lastPos);
        if (pos == -1) {
            tokens.addElement(str.substring(lastPos, str.length()));
        }
    }

    return tokens;
}