Example usage for java.util Vector elements

List of usage examples for java.util Vector elements

Introduction

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

Prototype

public Enumeration<E> elements() 

Source Link

Document

Returns an enumeration of the components of this vector.

Usage

From source file:GroupRadio.java

public static Enumeration getSelectedElements(Container container) {
    Vector selections = new Vector();
    Component components[] = container.getComponents();
    for (int i = 0, n = components.length; i < n; i++) {
        if (components[i] instanceof AbstractButton) {
            AbstractButton button = (AbstractButton) components[i];
            if (button.isSelected()) {
                selections.addElement(button.getText());
            }/*from  www . j  a  v a2  s  . c  o  m*/
        }
    }
    return selections.elements();
}

From source file:org.locationtech.jtstest.util.StringUtil.java

/**
 *  Returns the elements of v in uppercase
 *//*w w  w  . j  ava 2s. c  o m*/
public static Vector toUpperCase(Vector v) {
    Vector result = new Vector();
    for (Enumeration e = v.elements(); e.hasMoreElements();) {
        String s = e.nextElement().toString();
        result.add(s.toUpperCase());
    }
    return result;
}

From source file:Main.java

/**
 * Searches parent node for matching child nodes and collects and returns
 * their values./*w w  w. j  a va  2 s .co  m*/
 *
 * @param node     The parent node
 * @param elemName The matching child node element name
 * @return List of node values
 */
public static Enumeration getChildrenNodeValues(Node node, String elemName) {
    Vector vect = new Vector();
    NodeList nl = node.getChildNodes();
    int n = nl.getLength();
    for (int i = 0; i < n; i++) {
        Node nd = nl.item(i);
        if (nd.getNodeName().equals(elemName)) {
            Node child = nd.getFirstChild();
            if (child == null) {
                vect.add("");
            } else {
                vect.add(child.getNodeValue());
            }
        }
    }
    return vect.elements();
}

From source file:org.apache.webdav.ant.Utils.java

public static long getLastModified(HttpClient client, HttpURL url) throws IOException, HttpException {
    Vector props = new Vector(1);
    props.add(GETLASTMODIFIED);/*from  w  ww.  j a  va2 s. co  m*/
    PropFindMethod propFind = new PropFindMethod(url.getEscapedURI(), 0);
    propFind.setPropertyNames(props.elements());
    propFind.setFollowRedirects(true);
    propFind.setAssertHrefsArePathes(true);
    propFind.setDecodeResponseHrefs("UTF-8");

    int status = client.executeMethod(propFind);
    switch (status) {
    case WebdavStatus.SC_MULTI_STATUS:
        Property p = findProperty(propFind, GETLASTMODIFIED, url.getPath());
        if (p != null) {
            try {
                Date d = GETLASTMODIFIED_FORMAT.parse(p.getPropertyAsString());
                return d.getTime();
            } catch (ParseException e) {
                throw new HttpException("Invalid lastmodified property: " + p.getPropertyAsString());
            }
        }
        throw new HttpException("PROPFIND does not return lastmodified.");
    default:
        HttpException ex = new HttpException();
        ex.setReasonCode(status);
        ex.setReason(propFind.getStatusText());
        throw ex;
    }
}

From source file:org.apache.webdav.ant.Utils.java

public static boolean collectionExists(HttpClient client, HttpURL httpURL) throws IOException, HttpException {
    Vector props = new Vector(1);
    props.add(RESOURCETYPE);//from  w ww  .  j  ava2  s .c o m
    PropFindMethod propFind = new PropFindMethod(httpURL.getEscapedURI(), 0, PropFindMethod.BY_NAME);
    propFind.setFollowRedirects(true);
    propFind.setPropertyNames(props.elements());
    propFind.setAssertHrefsArePathes(true);
    propFind.setDecodeResponseHrefs("UTF-8");

    int status = client.executeMethod(propFind);
    switch (status) {
    case WebdavStatus.SC_MULTI_STATUS:
        Property p = findProperty(propFind, RESOURCETYPE, httpURL.getPath());
        if (p instanceof ResourceTypeProperty) {
            return ((ResourceTypeProperty) p).isCollection();
        } else {
            throw new WebdavException("PROPFFIND does not return resourcetype");
        }
    case WebdavStatus.SC_NOT_FOUND:
        return false;
    default:
        HttpException ex = new HttpException();
        ex.setReasonCode(status);
        ex.setReason(propFind.getStatusText());
        throw ex;
    }
}

From source file:com.adobe.aem.demomachine.gui.AemDemoUtils.java

public static String calcMD5HashForDir(File dirToHash, boolean includeSubFolders, boolean includeHiddenFiles) {

    assert (dirToHash.isDirectory());
    Vector<FileInputStream> fileStreams = new Vector<FileInputStream>();

    logger.debug("Found files for hashing:");
    collectInputStreams(dirToHash, fileStreams, includeSubFolders, includeHiddenFiles);

    SequenceInputStream seqStream = new SequenceInputStream(fileStreams.elements());

    try {/*from  w  ww . ja  va 2  s .c  o m*/
        String md5Hash = DigestUtils.md5Hex(seqStream);
        seqStream.close();
        return md5Hash;
    } catch (IOException e) {
        throw new RuntimeException("Error reading files to hash in " + dirToHash.getAbsolutePath(), e);
    }

}

From source file:com.nary.Debug.java

/**
 * This method prints all the elements in a Vector marking each with
 * the index it's at.//from  w  w  w .  ja  v  a2s .  c  om
 *
 * @param _vector The Vector to go through
 */

public static void println(Vector<Object> _vector) {
    checkCurrentInstance();
    if (_vector == null)
        return;

    Enumeration<Object> E = _vector.elements();
    int x = 0;

    while (E.hasMoreElements()) {
        newInstance.intPrintln("element[" + (x++) + "]=" + E.nextElement());
    }
}

From source file:org.openqa.selenium.server.browserlaunchers.WindowsUtils.java

/** Returns the current process environment variables
 * /*w  w w .  j  a v  a  2 s  .co m*/
 * @return the current process environment variables
 */
public static synchronized Properties loadEnvironment() {
    if (env != null)
        return env;
    // DGF lifted directly from Ant's Property task
    env = new Properties();
    Vector osEnv = Execute.getProcEnvironment();
    for (Enumeration e = osEnv.elements(); e.hasMoreElements();) {
        String entry = (String) e.nextElement();
        int pos = entry.indexOf('=');
        if (pos == -1) {
            log.warn("Ignoring: " + entry);
        } else {
            env.put(entry.substring(0, pos), entry.substring(pos + 1));
        }
    }
    return env;
}

From source file:org.floggy.synchronization.jme.core.impl.JSONSerializationManager.java

/**
* DOCUMENT ME!// ww w  .j av a  2  s . c  o  m
*
* @param value DOCUMENT ME!
* @param stringer DOCUMENT ME!
*
* @throws Exception DOCUMENT ME!
*/
public static void toJSON(Vector value, JSONStringer stringer) throws Exception {
    if (value == null) {
        stringer.value(null);
    } else {
        stringer.array();

        Enumeration elements = value.elements();

        while (elements.hasMoreElements()) {
            Object object = elements.nextElement();
            sendObject(object, stringer);
        }

        stringer.endArray();
    }
}

From source file:eu.crowdrec.contest.sender.RequestSenderORP.java

/**
 * read logFile then sends line by line to server.
 * //from w  w w . j  a  va  2s .c  om
 * @param inLogFileName
 *            path to log file. That can be a zip file or text file.
 * @param outLogFile
 *            path to outLog file. The outLog file should be analyzed by the evaluator.
 *            if the filename is null; no output will be generated
 * @param serverURL
 *            URL of the server
 */
public static void sender(final String inLogFileName, final String outLogFile, final String serverURL) {

    // handle the log file
    // check type of file

    // try to read the defined logFile
    BufferedReader br = null;
    BufferedWriter bw = null;
    try {
        // if outLogFile name is not null, create an output file
        if (outLogFile != null && outLogFile.length() > 0) {
            bw = new BufferedWriter(new FileWriter(new File(outLogFile), false));
        }

        // support a list of files in a directory
        File inLogFile = new File(inLogFileName);
        InputStream is;
        if (inLogFile.isFile()) {
            is = new FileInputStream(inLogFileName);
            // support gZip files
            if (inLogFile.getName().toLowerCase().endsWith(".gz")) {
                is = new GZIPInputStream(is);
            }
        } else {
            // if the input is a directory, consider all files based on a pattern
            File[] childs = inLogFile.listFiles(new FilenameFilter() {

                @Override
                public boolean accept(File dir, String name) {
                    final String fileName = name.toLowerCase();
                    return fileName.startsWith("contest.log");
                }
            });
            if (childs == null || childs.length == 0) {
                throw new IOException("invalid inLogFileName or empty directory");
            }
            Arrays.sort(childs, new Comparator<File>() {

                @Override
                public int compare(File o1, File o2) {
                    return o1.getName().compareTo(o2.getName());
                }
            });
            Vector<InputStream> isChilds = new Vector<InputStream>();
            for (int i = 0; i < childs.length; i++) {
                InputStream tmpIS = new FileInputStream(childs[i]);
                // support gZip files
                if (childs[i].getName().toLowerCase().endsWith(".gz")) {
                    tmpIS = new GZIPInputStream(tmpIS);
                }
                isChilds.add(tmpIS);
            }
            is = new SequenceInputStream(isChilds.elements());
        }

        // read the log file line by line
        br = new BufferedReader(new InputStreamReader(is));
        try {
            for (String line = br.readLine(); line != null; line = br.readLine()) {

                // ignore invalid lines and header
                if (line.startsWith("null") || line.startsWith("#")) {
                    continue;
                }

                String[] token = parseLogLine(line);
                if (token == null) {
                    System.err.println(
                            "HHHHHHHHHHHHHHHHHHHHHHHHHHEEEEEEEEEEEEEEEEEEELLLLLLLLLLLLLLLLPPPPPPPPPPPPPPP");
                    System.err.println(
                            "HHHHHHHHHHHHHHHHHHHHHHHHHHEEEEEEEEEEEEEEEEEEELLLLLLLLLLLLLLLLPPPPPPPPPPPPPPP");
                    System.err.println(
                            "HHHHHHHHHHHHHHHHHHHHHHHHHHEEEEEEEEEEEEEEEEEEELLLLLLLLLLLLLLLLPPPPPPPPPPPPPPP");
                    System.err.println(
                            "HHHHHHHHHHHHHHHHHHHHHHHHHHEEEEEEEEEEEEEEEEEEELLLLLLLLLLLLLLLLPPPPPPPPPPPPPPP");
                    System.err.println(line);
                    System.err.println(
                            "HHHHHHHHHHHHHHHHHHHHHHHHHHEEEEEEEEEEEEEEEEEEELLLLLLLLLLLLLLLLPPPPPPPPPPPPPPP");
                    System.err.println(
                            "HHHHHHHHHHHHHHHHHHHHHHHHHHEEEEEEEEEEEEEEEEEEELLLLLLLLLLLLLLLLPPPPPPPPPPPPPPP");
                    System.err.println(
                            "HHHHHHHHHHHHHHHHHHHHHHHHHHEEEEEEEEEEEEEEEEEEELLLLLLLLLLLLLLLLPPPPPPPPPPPPPPP");
                    continue;
                }

                // use a threadPool
                RequestSenderThread t = new RequestSenderThread(token[0], token[1], token[2], serverURL, bw);
                try {
                    // try to limit the speed of sending requests
                    if (Thread.activeCount() > 1000) {
                        if (logger.isDebugEnabled()) {
                            logger.debug("Thread.activeCount() = " + Thread.activeCount());
                        }
                        Thread.sleep(200);
                    }
                } catch (Exception e) {
                    logger.info(e.toString());
                }
                t.start();
            }

        } catch (IOException e) {
            logger.warn(e.toString(), e);
        }
    } catch (FileNotFoundException e) {
        logger.error("logFile not found e:" + e.toString());
    } catch (IOException e) {
        logger.error("reading the logFile failed e:" + e.toString());
    } finally {
        if (br != null) {
            try {
                br.close();
            } catch (IOException e) {
                logger.debug("close read-log file failed");
            }
        }
        if (bw != null) {
            try {
                // wait for ensuring that all request are finished
                // this simplifies the management of thread and worked fine for all test machines
                Thread.sleep(5000);
                bw.flush();
            } catch (Exception e) {
                logger.debug("close write-log file failed");
            }
        }
    }
}