Example usage for java.util Vector iterator

List of usage examples for java.util Vector iterator

Introduction

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

Prototype

public synchronized Iterator<E> iterator() 

Source Link

Document

Returns an iterator over the elements in this list in proper sequence.

Usage

From source file:org.kepler.job.JobManager.java

private void formatFiles(String dir, Vector<File> files) throws JobException {
    boolean isMac = System.getProperty("os.name").toLowerCase().contains("mac");
    boolean isWindows = System.getProperty("os.name").toLowerCase().contains("win");
    int exitCode;
    String cdCmd = "cd " + dir + "; ";

    if (files.size() > 0 && !this.host.equals("local") && (isMac || isWindows)) {

        StringBuffer cmd = new StringBuffer(cdCmd);
        ByteArrayOutputStream commandStdout = new ByteArrayOutputStream();
        ByteArrayOutputStream commandStderr = new ByteArrayOutputStream();

        String filename = "*";
        if (files.size() == 1) {
            //if it is just one file use name instead of *
            filename = files.get(0).getName();
        }/*from  ww  w  . j a  v a2 s  . c  o m*/
        // use dos/mac 2unix if available
        if (isMac) {
            cmd.append("mac2unix ");
            cmd.append(filename);
        }
        if (isWindows) {
            cmd.append("dos2unix ");
            cmd.append(filename);
        }
        exitCode = _exec(new String(cmd), commandStdout, commandStderr);

        if (exitCode != 0) { // use sed -i if dos/mac 2unix not
                             // available
            cmd = new StringBuffer(cdCmd);
            if (isMac) {
                cmd.append("sed -i 's/\\r/\\n/g' ");
                cmd.append(filename);
            }
            if (isWindows) {
                cmd.append("sed -i 's/\\r//g' ");
                cmd.append(filename);
            }
            exitCode = _exec(new String(cmd), commandStdout, commandStderr);
            // use tr as last resort
            if (exitCode != 0) {
                cmd = new StringBuffer(cdCmd);
                Iterator<File> it = files.iterator();
                while (it.hasNext()) {
                    File aFile = it.next();
                    String fileName = aFile.getName();

                    cmd.append("cp " + fileName);
                    cmd.append(" tmp" + fileName);

                    if (isMac) {
                        cmd.append("; tr '\\r' '\\n' <tmp" + fileName);
                    }
                    if (isWindows) {
                        cmd.append("; tr -d '\\r' <tmp" + fileName);
                    }

                    cmd.append(" >" + fileName);
                    cmd.append("; rm tmp" + fileName + "; ");
                }
                exitCode = _exec(new String(cmd), commandStdout, commandStderr);
                if (exitCode != 0) {
                    throw new JobException("Error at copying local files into the job directory."
                            + "\nStdout:\n" + commandStdout + "\nStderr:\n" + commandStderr);
                }
            }
        }
    }
}

From source file:org.apache.axis.message.MessageElement.java

/**
 * get an iterator over child elements/*from  ww w  .  ja  va 2  s . c  o  m*/
 * @param qname namespace/element name of parts to find.
 * This iterator is not (currently) susceptible to change in the element
 * list during its lifetime, though changes in the contents of the elements
 * are picked up.
 * @return an iterator.
 */
public Iterator getChildElements(QName qname) {
    initializeChildren();
    int num = children.size();
    Vector c = new Vector(num);
    for (int i = 0; i < num; i++) {
        MessageElement child = (MessageElement) children.get(i);
        Name cname = child.getElementName();
        if (cname.getURI().equals(qname.getNamespaceURI())
                && cname.getLocalName().equals(qname.getLocalPart())) {
            c.add(child);
        }
    }
    return c.iterator();
}

From source file:org.energy_home.jemma.ah.internal.zigbee.InstallationStatus.java

private void unregisterAllDevices() {
    Set keys = ieee2sr.keySet();/*from ww  w.ja va  2  s .c  om*/
    for (Iterator iterator = keys.iterator(); iterator.hasNext();) {
        try {
            String nodePid = (String) iterator.next();
            Vector deviceRegs = (Vector) this.ieee2sr.get(nodePid);
            if (deviceRegs != null) {
                this.ieee2devices.remove(nodePid);
                for (Iterator iterator2 = deviceRegs.iterator(); iterator2.hasNext();) {
                    ServiceRegistration deviceReg = (ServiceRegistration) iterator2.next();
                    deviceReg.unregister();
                }
            }
        } catch (ConcurrentModificationException e) {
            e.printStackTrace();
            return;
        }
    }
    ieee2sr.clear();
}

From source file:org.energy_home.jemma.ah.internal.zigbee.InstallationStatus.java

private void unregisterDevice(String nodePid) {
    Vector deviceRegs = (Vector) this.ieee2sr.get(nodePid);
    if (deviceRegs != null) {
        this.ieee2sr.remove(nodePid);
        this.ieee2devices.remove(nodePid);
        for (Iterator iterator = deviceRegs.iterator(); iterator.hasNext();) {
            ServiceRegistration deviceReg = (ServiceRegistration) iterator.next();
            deviceReg.unregister();//from   w w w . j  a  va  2 s.  c  o m
        }
    }

    if (cacheDiscoveryInfos) {
        InstallationStatus installationStatus = (InstallationStatus) this.installedDevices.remove(nodePid);
        if (this.enableDiscoveryLogs && installationStatus != null)
            log.debug(nodePid + ": removed Node from installedDevices table");

        if (dumpDiscoveryInfos && (installationStatus != null)) {
            this.dumpDiscoveredDevicesDb(dumpAllDevices);
        }
    }
}

From source file:org.biojava.bio.view.MotifAnalyzer.java

/**
 * //from w ww  .j  a v a2 s  .  com
 * @param f1 sequence file
 * @param motifs list of motifs to display
 */
public void showMotifs(SequenceIterator seqItr, List<Motif> motifs) {
    seqViewerTab.removeAll();
    seqViewerTab.setLayout(new BorderLayout());

    try {
        Vector<Sequence> seqs = new Vector<Sequence>();
        Set<MotifFinder> finders = new HashSet<MotifFinder>();

        while (seqItr.hasNext())
            seqs.add(seqItr.nextSequence());

        // labels panel

        JPanel labelPanel = new JPanel();
        seqViewerTab.add(labelPanel, BorderLayout.NORTH);

        // Sequence panels array
        JPanel seqViewer = new JPanel(new GridLayout(seqs.size(), 1));
        seqViewerTab.add(seqViewer, BorderLayout.CENTER);

        SequencePanel[] seqPanel = new SequencePanel[seqs.size()];
        GridLayout seqPanelLayout = new GridLayout(2, 1);
        seqPanelLayout.setColumns(1);
        seqPanelLayout.setHgap(5);
        seqPanelLayout.setVgap(5);
        seqPanelLayout.setRows(2);
        int i = 0;

        for (Iterator<Sequence> itr = seqs.iterator(); itr.hasNext(); i++) {
            Sequence sourceSeq = itr.next();
            String name = sourceSeq.getName().substring(sourceSeq.getName().indexOf("_") + 1);
            seqPanel[i] = new SequencePanel();
            seqPanel[i].setLayout(seqPanelLayout);
            int num = 0;
            String[] f = new String[motifs.size()];
            for (Iterator<Motif> m = motifs.iterator(); m.hasNext();) {
                Motif motif = m.next();
                if (motif.getSites().get(name) == null)
                    continue;
                for (Iterator<Site> itr2 = motif.getSites().get(name).iterator(); itr2.hasNext();) {
                    Site seq = itr2.next();
                    finders.add(motif.getFinder());
                    seq.location = new RangeLocation(sourceSeq.length() + seq.location.getMin(),
                            sourceSeq.length() + seq.location.getMax());
                    seq.type = motif.getFinder().name() + "_" + num;
                    sourceSeq.createFeature(seq);
                }
                f[num] = motif.getFinder().name() + "_" + num;
                num++;
            }

            seqPanel[i].setSequence(sourceSeq);
            seqPanel[i].setRange(new RangeLocation(1, sourceSeq.length()));
            // Magic number from EmblViewer
            seqPanel[i].setScale(Math.exp(-INITIAL_SCALE / 7.0) * 20.0);
            seqPanel[i].setDirection(SequencePanel.HORIZONTAL);

            OptimizableFilter[] optFilter = new OptimizableFilter[num];//MotifFinder.values().length];
            FeatureBlockSequenceRenderer[] renderer = new FeatureBlockSequenceRenderer[num];//MotifFinder.values().length];

            for (int k = 0; k < num; k++)//MotifFinder.values().length; k++)
            {
                optFilter[k] = new FeatureFilter.ByType(f[k]);//MotifFinder.values()[k].name());
                renderer[k] = new FeatureBlockSequenceRenderer(new RectangularBeadRenderer(10.0f, 5.0f,
                        Color.black, MotifFinder.valueOf(f[k].substring(0, f[k].indexOf('_'))).color,
                        new BasicStroke()));
            }

            MultiLineRenderer multi = new MultiLineRenderer();

            for (int k = 0; k < renderer.length; k++)
                multi.addRenderer(new FilteringRenderer(renderer[k], optFilter[k], false));

            multi.addRenderer(new SymbolSequenceRenderer());
            multi.addRenderer(new RulerRenderer());

            seqPanel[i].setRenderer(multi);
            seqPanel[i].setEnabled(false);

            JScrollPane seqScroll = new JScrollPane(seqPanel[i]);

            JPanel temp = new JPanel(new BorderLayout());

            temp.add(getControlBox(seqPanel[i], sourceSeq.getName()), BorderLayout.NORTH);
            temp.add(seqScroll, BorderLayout.CENTER);

            seqViewer.add(temp);
        }

        for (Iterator<MotifFinder> itr = finders.iterator(); itr.hasNext();) {
            MotifFinder finder = itr.next();
            // Add label of this MotifFinder
            labelPanel.add(new JLabel(finder.name()));
            JLabel l = new JLabel("      ");
            l.setOpaque(true);
            l.setBackground(finder.color);
            l.setBorder(BorderFactory.createLineBorder(Color.black));
            labelPanel.add(l);
        }
        mainFrame.setVisible(true);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.apache.axis.message.MessageElement.java

/**
 * Get an interator to all the attributes of the node.
 * The iterator is over a static snapshot of the node names; if attributes
 * are added or deleted during the iteration, this iterator will be not
 * be updated to follow the changes.//from  w  w w . j  a  v a2s.com
 * @return an iterator of the attributes.
 * @see javax.xml.soap.SOAPElement#getAllAttributes()
 */
public Iterator getAllAttributes() {
    int num = attributes.getLength();
    Vector attrs = new Vector(num);
    for (int i = 0; i < num; i++) {
        String q = attributes.getQName(i);
        String prefix = "";
        if (q != null) {
            int idx = q.indexOf(":");
            if (idx > 0) {
                prefix = q.substring(0, idx);
            } else {
                prefix = "";
            }
        }

        attrs.add(new PrefixedQName(attributes.getURI(i), attributes.getLocalName(i), prefix));
    }
    return attrs.iterator();
}

From source file:org.energy_home.jemma.ah.internal.zigbee.InstallationStatus.java

public void nodeRemoved(Status status, WSNNode node) {
    rwLock.writeLock().lock();/*ww  w.  j  av  a  2 s  . co m*/
    try {
        // notifies the node
        // TODO: if the node has short address 0 it means that the dongle is
        // crashed.
        if (status.getCode() == 0) {
            String nodePid = getNodePid(node.getAddress());
            Vector deviceRegs = (Vector) this.ieee2sr.get(nodePid);
            if (deviceRegs != null) {
                log.debug(getIeeeAddressHex(node.getAddress()) + ": node has been removed");
                this.ieee2sr.remove(nodePid);
                this.ieee2devices.remove(nodePid);
                for (Iterator iterator = deviceRegs.iterator(); iterator.hasNext();) {
                    ServiceRegistration deviceReg = (ServiceRegistration) iterator.next();
                    deviceReg.unregister();
                }
            } else {
                log.warn(nodePid + ": unknown node has been removed");
            }

            if (cacheDiscoveryInfos) {
                this.installedDevices.remove(nodePid);
                if (dumpDiscoveryInfos) {
                    this.dumpDiscoveredDevicesDb(dumpAllDevices);
                }
            }
        }
    } finally {
        rwLock.writeLock().unlock();
    }
}

From source file:org.apache.axis.message.MessageElement.java

/**
 * get an iterator over visible prefixes. This includes all declared in
 * parent elements/*from www  .  j  av  a2 s  . co m*/
 * @return an iterator.
 */
public Iterator getVisibleNamespacePrefixes() {
    Vector prefixes = new Vector();

    // Add all parents namespace definitions
    if (parent != null) {
        Iterator parentsPrefixes = ((MessageElement) parent).getVisibleNamespacePrefixes();
        if (parentsPrefixes != null) {
            while (parentsPrefixes.hasNext()) {
                prefixes.add(parentsPrefixes.next());
            }
        }
    }
    Iterator mine = getNamespacePrefixes();
    if (mine != null) {
        while (mine.hasNext()) {
            prefixes.add(mine.next());
        }
    }
    return prefixes.iterator();
}

From source file:org.safs.selenium.webdriver.lib.WDLibrary.java

/**
 * Does NOT clear any existing text in the control, but does attempt to insure the window/control has focus.
 * <br><em>Purpose:</em>
 * <a href="http://safsdev.sourceforge.net/sqabasic2000/SeleniumGenericMasterFunctionsReference.htm#detail_InputKeys" alt="inputKeys Keyword Reference" title="inputKeys Keyword Reference">inputKeys</a>
 * <p>//from  ww  w  .  j a  v  a  2  s . c om
 * Bypasses attempts to use AWT Robot for keystrokes.
 * Attempts to convert SAFS keystrokes to Selenium low-level Actions keystrokes.
 * @param we WebElement to send SAFS keystrokes (or plain text).
 * @param keystrokes SAFS keystrokes or plain text to type.
 * @throws SeleniumPlusException if we are unable to process the keystrokes successfully.
 **/
public static void inputKeysSAFS2Selenium(WebElement we, String keystrokes) throws SeleniumPlusException {
    String debugmsg = StringUtils.debugmsg(false);
    IndependantLog.debug(debugmsg + " processing '" + keystrokes + "' on webelement " + we);
    if (!focus(we))
        IndependantLog.warn(debugmsg + " Fail to set focus to webelement " + we);

    RemoteDriver wd = null;
    try {
        wd = (RemoteDriver) getWebDriver();
    } catch (Exception x) {
    }
    // convert to Selenium low-level Action keystrokes.
    if (keysparser != null) {
        Vector keys = keysparser.parseInput(keystrokes);
        Actions actions = new Actions(wd);

        if (we != null)
            actions = actions.moveToElement(we);

        Iterator events = keys.iterator();
        RobotKeyEvent event;
        Keys k = null;
        CharSequence c = null;
        while (events.hasNext()) {
            try {
                event = (RobotKeyEvent) events.next();
                c = null;
                k = convertToKeys(event);
                if (k == null) {
                    c = convertToCharacter(event);
                } else {

                }
                switch (event.get_event()) {

                case RobotKeyEvent.KEY_PRESS:
                    if (k != null) {
                        IndependantLog.debug(debugmsg + " handling keyDown '" + k.name() + "'");
                        actions = actions.keyDown(k);
                    } else {
                        IndependantLog.debug(debugmsg + " send char '" + c + "'");
                        actions = actions.sendKeys(c);
                    }
                    break;

                case RobotKeyEvent.KEY_RELEASE:
                    if (k != null) {
                        IndependantLog.debug(debugmsg + " handling keyUp '" + k.name() + "'");
                        actions = actions.keyUp(k);
                    } else {
                        IndependantLog.debug(debugmsg + " send char '" + c + "'");
                        actions = actions.sendKeys(c);
                    }
                    break;

                case RobotKeyEvent.KEY_TYPE:
                    if (k != null) {
                        IndependantLog.debug(debugmsg + " send Key '" + k.name() + "'");
                        actions = actions.sendKeys(k);
                    } else {
                        IndependantLog.debug(debugmsg + " send char '" + c + "'");
                        actions = actions.sendKeys(c);
                    }
                    break;
                default:
                }
            } catch (Exception x) {
                IndependantLog.debug(debugmsg + " IGNORING RobotKeyEvent exception:", x);
            }
        }
        try {
            actions.build().perform();
        } catch (StaleElementReferenceException x) {
            // the click probably was successful because the elements have changed!
            IndependantLog.debug(debugmsg + " StaleElementException (not found).");
        } catch (Throwable x) {
            IndependantLog.debug(debugmsg + " " + x.getClass().getName() + ", " + x.getMessage());
        } finally {
            IndependantLog.debug(debugmsg + " selenium actions.build().perform() complete.");
        }
    } else {
        // TODO what if keyparser cannot load a keys converter???
    }
}

From source file:de.juwimm.cms.remote.ViewServiceSpringImpl.java

/**
 * Returns all children of a ViewComponent, that contains a unit.
 * /*from   w ww  .  j av a2 s .co  m*/
 * @param viewComponentId
 *            The viewComponentId
 * @return Array of ViewIdAndUnitIdValue
 *         <ul>
 *         <li>[i][0] contains ViewComponentId</li>
 *         <li>[i][1] contains UnitId</li>
 *         <li>[i][2] contains UnitName</li>
 *         </ul>
 * 
 * @see de.juwimm.cms.remote.ViewServiceSpring#getAllViewComponentsWithUnits(java.lang.Integer)
 */
@Override
protected ViewIdAndUnitIdValue[] handleGetAllViewComponentsWithUnits(Integer viewComponentId) throws Exception {
    try {
        ViewIdAndUnitIdValue[] retarr = null;
        ViewComponentHbm root = super.getViewComponentHbmDao().load(viewComponentId);
        Vector<ViewComponentHbm> vec = new Vector<ViewComponentHbm>(root.getAllChildrenWithUnits());
        Iterator it = vec.iterator();
        retarr = new ViewIdAndUnitIdValue[vec.size()];
        int i = 0;
        while (it.hasNext()) {
            ViewComponentHbm vcl = (ViewComponentHbm) it.next();
            retarr[i] = new ViewIdAndUnitIdValue();
            retarr[i].setViewComponentId(vcl.getViewComponentId());
            retarr[i].setUnitId(vcl.getAssignedUnit().getUnitId());
            retarr[i].setUnitName(vcl.getAssignedUnit().getName());
            i++;
        }
        return retarr;
    } catch (Exception e) {
        throw new UserException(e.getMessage());
    }
}