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:com.modeln.build.ctrl.charts.CMnPatchCountChart.java

/**
 * Create a chart representing an arbitrary collection of name/value pairs. 
 * The data is passed in as a hashtable where the key is the name and the  
 * value is the number items. //from  w ww . ja v a 2  s .com
 */
public static final JFreeChart getBarChart(Hashtable<String, Integer> data, String title, String nameLabel,
        String valueLabel) {
    JFreeChart chart = null;

    // Sort the data by name
    Vector<String> names = new Vector<String>();
    Enumeration nameList = data.keys();
    while (nameList.hasMoreElements()) {
        names.add((String) nameList.nextElement());
    }
    Collections.sort(names);

    // Populate the dataset with data
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    Iterator keyIter = names.iterator();
    while (keyIter.hasNext()) {
        String name = (String) keyIter.next();
        Integer value = data.get(name);
        dataset.addValue(value, valueLabel, name);
    }

    // Create the chart
    chart = ChartFactory.createBarChart(title, /*title*/
            nameLabel, /*categoryAxisLabel*/
            valueLabel, /*valueAxisLabel*/
            dataset, /*dataset*/
            PlotOrientation.VERTICAL, /*orientation*/
            false, /*legend*/
            false, /*tooltips*/
            false /*urls*/
    );

    // get a reference to the plot for further customization...
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    //chartFormatter.formatMetricChart(plot, "min");

    // Set the chart colors
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);

    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    renderer.setShadowVisible(false);
    final GradientPaint gp = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.blue);
    renderer.setSeriesPaint(0, gp);

    // Set the label orientation
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    return chart;
}

From source file:org.ariadne.oai.utils.HarvesterUtils.java

public static void resetHarvestingDate(String repos) {
    if (repos.equals("ALL")) {
        Vector<String> list = HarvesterUtils.getReposList();
        Iterator<String> iter = list.iterator();
        while (iter.hasNext()) {
            String repoString = (String) iter.next();
            resetHarvestingDate(repoString);
        }/*from   w  w  w. ja  va 2  s.c  o m*/
    } else {

        OAIRepository repository = new OAIRepository();
        try {
            repository.setBaseURL(PropertiesManager.getInstance().getProperty(repos + ".baseURL"));
            String date = repository.getEarliestDatestamp();
            PropertiesManager.getInstance().saveProperty(repos + ".latestHarvestedDatestamp", date);
        } catch (OAIException e) {
            // NOOP
        }

    }
}

From source file:org.globus.wsrf.tools.wsdl.WSDLPreprocessor.java

private static void addImports(Definition definition, Definition parentDefinition) throws Exception {
    Collection imports = definition.getImports().values();
    Iterator importsIterator = imports.iterator();

    while (importsIterator.hasNext()) {
        Vector importsVector = (Vector) importsIterator.next();
        Iterator importsVectorIterator = importsVector.iterator();
        boolean addImport = true;
        while (importsVectorIterator.hasNext()) {
            Import currentImport = (Import) importsVectorIterator.next();
            String location = currentImport.getLocationURI();
            if (location != null && (location.startsWith(".") || location.indexOf('/') == -1)) {
                location = getRelativePath(parentDefinition.getDocumentBaseURI(),
                        currentImport.getDefinition().getDocumentBaseURI());
                currentImport.setLocationURI(location);
            }//from   w  w  w.  j av a 2 s  . c o  m
            List parentImports = parentDefinition.getImports(currentImport.getNamespaceURI());
            if (parentImports != null) {
                Iterator parentImportsIterator = parentImports.iterator();
                while (parentImportsIterator.hasNext()) {
                    Import parentImport = (Import) parentImportsIterator.next();
                    if (parentImport.getLocationURI().equals(location)) {
                        addImport = false;
                        break;
                    }
                }
            }
            if (addImport) {
                parentDefinition.addImport(currentImport);
            }
            addImport = true;
        }
    }
}

From source file:com.modeln.build.ctrl.charts.CMnPatchCountChart.java

/**
 * Create a chart representing the number patches grouped by time interval.
 * The data passed in the hashtable is a list of the time intervals and
 * the value is the number of patch requests for each interval.
 *
 * @param  data   Hashtable cnotaining the time intervals and corresponding counts
 * @param  label  Count label// w ww . j  ava2 s . co  m
 *
 * @return Bar chart representing the interval and count information
 */
public static final JFreeChart getPatchesByIntervalChart(Hashtable<CMnTimeInterval, Integer> data,
        String label) {
    JFreeChart chart = null;

    String title = "Patches per " + label;
    String nameLabel = label;
    String valueLabel = "Patches";

    // Sort the data by date
    Vector<CMnTimeInterval> intervals = new Vector<CMnTimeInterval>();
    Enumeration intervalList = data.keys();
    while (intervalList.hasMoreElements()) {
        intervals.add((CMnTimeInterval) intervalList.nextElement());
    }
    Collections.sort(intervals);

    // Populate the dataset with data
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    Iterator keyIter = intervals.iterator();
    while (keyIter.hasNext()) {
        CMnTimeInterval interval = (CMnTimeInterval) keyIter.next();
        Integer value = data.get(interval);
        dataset.addValue(value, valueLabel, interval.getName());
    }

    // Create the chart
    chart = ChartFactory.createBarChart(title, /*title*/
            nameLabel, /*categoryAxisLabel*/
            valueLabel, /*valueAxisLabel*/
            dataset, /*dataset*/
            PlotOrientation.VERTICAL, /*orientation*/
            false, /*legend*/
            false, /*tooltips*/
            false /*urls*/
    );

    // get a reference to the plot for further customization...
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    //chartFormatter.formatMetricChart(plot, "min");

    // Set the chart colors
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);

    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    renderer.setShadowVisible(false);
    final GradientPaint gp = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.blue);
    renderer.setSeriesPaint(0, gp);

    // Set the label orientation
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    return chart;
}

From source file:org.globus.wsrf.tools.wsdl.WSDLPreprocessor.java

public static Map getResourceProperties(QName resourceProperties, Definition def, Map documentLocations,
        boolean quiet) throws Exception {
    HashMap resourcePropertyElements = new HashMap();

    if (resourceProperties != null) {
        Types types = def.getTypes();
        if (types == null) {
            if (!quiet) {
                log.warn("The " + def.getDocumentBaseURI() + " definition does not have a types section");
            }// w  ww  .  ja v  a 2  s .  c om
            return resourcePropertyElements;
        }

        List elementList = types.getExtensibilityElements();
        // assume only on schema element for now
        if (elementList.size() > 1) {
            if (!quiet) {
                System.err.println("WARNING: The types section in " + def.getDocumentBaseURI()
                        + " contains more than one top level element.");
            }
            // maybe throw error
        }
        Element schema = ((UnknownExtensibilityElement) elementList.get(0)).getElement();

        XSModel schemaModel = loadSchema(schema, def);

        XSElementDeclaration resourcePropertiesElement = schemaModel
                .getElementDeclaration(resourceProperties.getLocalPart(), resourceProperties.getNamespaceURI());

        if (resourcePropertiesElement != null) {
            XSComplexTypeDecl type = (XSComplexTypeDecl) resourcePropertiesElement.getTypeDefinition();
            XSParticle particle = type.getParticle();
            XSModelGroup sequence = (XSModelGroup) particle.getTerm();
            XSObjectList objectList = sequence.getParticles();

            for (int i = 0; i < objectList.getLength(); i++) {
                XSParticle part = (XSParticle) objectList.item(i);
                Object term = part.getTerm();
                if (term instanceof XSElementDeclaration) {
                    XSElementDeclaration resourceProperty = (XSElementDeclaration) term;
                    resourcePropertyElements
                            .put(new QName(resourceProperty.getNamespace(), resourceProperty.getName()), part);
                } else {
                    throw new Exception(
                            "Invalid resource properties document " + resourceProperties.toString());
                }
            }
        } else {
            Map imports = def.getImports();
            Iterator importNSIterator = imports.values().iterator();
            while (importNSIterator.hasNext() && resourcePropertyElements.isEmpty()) {
                Vector importVector = (Vector) importNSIterator.next();
                Iterator importIterator = importVector.iterator();
                while (importIterator.hasNext() && resourcePropertyElements.isEmpty()) {
                    Import importDef = (Import) importIterator.next();
                    // process imports
                    resourcePropertyElements.putAll(getResourceProperties(resourceProperties,
                            importDef.getDefinition(), documentLocations, quiet));
                }
            }

            if (resourcePropertyElements.isEmpty()) {
                throw new Exception("Unable to resolve resource properties " + resourceProperties.toString());
            }
        }

        populateLocations(schemaModel, documentLocations, def);
    }
    return resourcePropertyElements;
}

From source file:org.lockss.util.Logger.java

/** Convert semicolon-separated string of log target class names to a
 * list of log target instances//  w ww. j a va  2  s  . c  o  m
 * @return List of instances, or null if any errors occurred
 */
static List<LogTarget> targetListFromString(String s) {
    boolean err = false;
    List<LogTarget> tgts = new ArrayList<LogTarget>();
    Vector names = StringUtil.breakAt(s, ';');
    for (Iterator iter = names.iterator(); iter.hasNext();) {
        String targetName = (String) iter.next();
        try {
            Class targetClass = Class.forName(targetName);
            LogTarget target = (LogTarget) targetClass.newInstance();
            tgts.add(target);
        } catch (Exception e) {
            myLog.error("Can't create log target \"" + targetName + "\": " + e.toString());
            err = true;
        }
    }
    return err ? null : tgts;
}

From source file:it.eng.spagobi.tools.downloadFiles.service.DownloadZipAction.java

/** getSortedArray.
 * /* ww w  .j a v a 2s.c  om*/
 * @return File[]
 */
static public final File[] getSortedArray(File directory, String prefix) {
    File[] allFiles = directory.listFiles();
    Vector labelFilesVector = new Vector<File>();
    for (int i = 0; i < allFiles.length; i++) {
        String fileName = allFiles[i].getName();
        if (fileName.startsWith(prefix)) {
            labelFilesVector.add(allFiles[i]);
        }
    }

    if (labelFilesVector.size() == 0) {
        return null;
    }

    // I need an array
    int j = 0;
    File[] labelFiles = new File[labelFilesVector.size()];
    for (Iterator iterator = labelFilesVector.iterator(); iterator.hasNext();) {
        File object = (File) iterator.next();
        labelFiles[j] = object;
        j++;
    }

    Arrays.sort(labelFiles, new Comparator() {
        public int compare(final Object o1, final Object o2) {

            if (((File) o1).lastModified() > ((File) o2).lastModified()) {
                return +1;
            } else if (((File) o1).lastModified() < ((File) o2).lastModified()) {
                return -1;
            } else {
                return 0;
            }
        }

    });

    return labelFiles;
}

From source file:sdn_competition.PcapReader_Main.java

public static void readFile(String filename) {
    //System.out.println("path"+System.getProperty(java.library.path));
    System.out.println("Reading file " + filename);

    JpcapCaptor jpcap = null;//from   w  w  w. j av a  2  s  .c  o  m
    // third argument is true for promiscuous mode
    try {

        jpcap = JpcapCaptor.openFile(filename);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        System.out.println("Could not read pcap file " + filename);
        e.printStackTrace();
    }

    // we only consider network layer traffic
    // this of course means we don't see things like ARP poisoning
    try {
        jpcap.setFilter("ip", true);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        System.out.println("Error in setting packet capture filter");
        e.printStackTrace();
    }

    final Data d = Data.getData();
    final Vector<SimplePacket> packet_set = new Vector<SimplePacket>();
    jpcap.loopPacket(-1, new PacketReceiver() {
        public void receivePacket(Packet p) {
            if (p instanceof IPPacket)
                packet_set.add(new SimplePacket((IPPacket) p));
        }
    });
    d.addPackets(packet_set.iterator());
}

From source file:fr.eolya.utils.http.HttpUtils.java

public static String getHtmlDeclaredLanguage(String rawData) {
    if (rawData == null || "".equals(rawData))
        return "";

    Hashtable<String, Integer> langFreq = new Hashtable<String, Integer>();
    BufferedReader in = new BufferedReader(new StringReader(rawData));
    String line;/*from  w w  w . j  a  v a2 s.c  o m*/
    try {
        while ((line = in.readLine()) != null) {
            line = line.toLowerCase();

            //<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr-fr">
            if (line.indexOf("<html") >= 0 && line.toLowerCase().indexOf(" xml:lang") >= 0) {
                String lang = parseAttributeValue(line, "xml:lang=");
                if (lang != null && lang.length() >= 2) {
                    lang = lang.substring(0, 2);

                    if (langFreq.containsKey(lang))
                        langFreq.put(lang, langFreq.get(lang) + 1);
                    else
                        langFreq.put(lang, 1);
                }
            }

            //<html lang="fr">
            if (line.indexOf("<html") >= 0 && line.toLowerCase().indexOf(" lang") >= 0) {
                String lang = parseAttributeValue(line, "lang=");
                if (lang != null && lang.length() >= 2) {
                    lang = lang.substring(0, 2);

                    if (langFreq.containsKey(lang))
                        langFreq.put(lang, langFreq.get(lang) + 1);
                    else
                        langFreq.put(lang, 1);
                }
            }

            //<meta http-equiv="content-language" content="fr-fr" />
            if (line.indexOf("<meta") >= 0 && line.toLowerCase().indexOf(" http-equiv") >= 0
                    && line.toLowerCase().indexOf("content-language") >= 0) {
                String lang = parseAttributeValue(line, "content=");
                if (lang != null && lang.length() >= 2) {
                    lang = lang.substring(0, 2);

                    if (langFreq.containsKey(lang))
                        langFreq.put(lang, langFreq.get(lang) + 1);
                    else
                        langFreq.put(lang, 1);
                }
            }

            //<meta name="language" content="fr-fr" />
            if (line.indexOf("<meta") >= 0 && line.toLowerCase().indexOf(" name") >= 0
                    && line.toLowerCase().indexOf("language") >= 0
                    && line.toLowerCase().indexOf(" content") >= 0) {
                String lang = parseAttributeValue(line, "content=");
                if (lang != null && lang.length() >= 2) {
                    lang = lang.substring(0, 2);

                    if (langFreq.containsKey(lang))
                        langFreq.put(lang, langFreq.get(lang) + 1);
                    else
                        langFreq.put(lang, 1);
                }
            }

            //<meta name="content-language" content="fr-fr" />
            if (line.indexOf("<meta") >= 0 && line.toLowerCase().indexOf(" name") >= 0
                    && line.toLowerCase().indexOf("content-language") >= 0
                    && line.toLowerCase().indexOf(" content") >= 0) {
                String lang = parseAttributeValue(line, "content=");
                if (lang != null && lang.length() >= 2) {
                    lang = lang.substring(0, 2);

                    if (langFreq.containsKey(lang))
                        langFreq.put(lang, langFreq.get(lang) + 1);
                    else
                        langFreq.put(lang, 1);
                }
            }
        }

        // Get the best candidate
        Vector<String> v = new Vector<String>(langFreq.keySet());
        Iterator<String> it = v.iterator();
        int max = 0;
        String lang = "";
        while (it.hasNext()) {
            String element = (String) it.next();
            //System.out.println( element + " " + encodingFreq.get(element));
            if (langFreq.get(element) > max) {
                max = langFreq.get(element);
                lang = element;
            }
        }

        return lang;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return "";
}

From source file:pagecode.jsp.actions.scheduling.RequestForTrialAction.java

private static ArrayList processNoticeOfTrial(Vector requestForTrialToPrintVector,
        NoticeOfTrialParameterFields noticeOfTrialParameterFields, HttpServletRequest request) {
    logger.info("In RequestForTrialAction::processNoticeOfTrial");
    ArrayList notices = new ArrayList();
    NoticeOfTrialSchema notice;/* w  w  w  . j ava 2 s.  co  m*/

    String crt, jur, yr, info1, info2;

    for (Iterator iter = requestForTrialToPrintVector.iterator(); iter.hasNext();) {
        RequestForTrialAdditionalCaseNumber additionalCaseNumber = (RequestForTrialAdditionalCaseNumber) iter
                .next();

        crt = additionalCaseNumber.getCrt();
        jur = additionalCaseNumber.getJur();
        yr = additionalCaseNumber.getYr();
        info1 = additionalCaseNumber.getInfoPart1();
        info2 = additionalCaseNumber.getInfoPart2();

        //if there is a case number i.e. it might be empty thus must check
        if (null != crt && !crt.equals("") && null != jur && !jur.equals("")) {

            noticeOfTrialParameterFields = new NoticeOfTrialParameterFields();

            try {
                noticeOfTrialParameterFields.setTrailScheduleDetails(crt, jur, yr, info1, info2,
                        //TODO set boolean runAsStandAlone properly
                        false, request);

                noticeOfTrialParameterFields.processParameterFieldsData();

                notice = new NoticeOfTrialSchema();
                notice.setOffenceNumber(noticeOfTrialParameterFields.getParamOffenceNumber());
                notice.setOffenceDate(noticeOfTrialParameterFields.getParamOffenceDate());
                notice.setOfficerNumber(noticeOfTrialParameterFields.getParamOfficerNumber());
                notice.setDriversLicenseNumber(noticeOfTrialParameterFields.getParamDriversLicenseNumber());
                notice.setPlateNumber(noticeOfTrialParameterFields.getParamPlateNumber());
                notice.setEnforcementAgency(noticeOfTrialParameterFields.getParamEnforcementAgency());
                notice.setSex(noticeOfTrialParameterFields.getParamSex());
                notice.setDateOfBirth(noticeOfTrialParameterFields.getParamDateOfBirth());
                notice.setCvor(noticeOfTrialParameterFields.getParamCVOR());
                notice.setUnit(noticeOfTrialParameterFields.getParamUnit());
                notice.setOffenderFullName(noticeOfTrialParameterFields.getParamOffenderFullName());
                notice.setAddressLine1(noticeOfTrialParameterFields.getParamAddressLine1());
                notice.setAddressLine2(noticeOfTrialParameterFields.getParamAddressLine2());
                notice.setAddressLine3(noticeOfTrialParameterFields.getParamAddressLine3());
                notice.setOffenceDay(noticeOfTrialParameterFields.getParamOffenceDay());
                notice.setOffenceMonth(noticeOfTrialParameterFields.getParamOffenceMonth());
                notice.setOffenceYear(noticeOfTrialParameterFields.getParamOffenceYear());
                notice.setOffenceTime(noticeOfTrialParameterFields.getParamOffenceTime());
                notice.setOffenceLocation(noticeOfTrialParameterFields.getParamOffenceLocation());
                /* 2010-11-23 CR4372 French NoT FORM modifications
                 * Added offenceDescLine2 to the NoticeOfTrialSchema class
                 * This is the best place to manipulate the data i.e. split the 
                 * Offence Desc param into two lines.  At this point the logic 
                 * is concerned with the View (in the MVC) so we are massaging 
                 * the data to meet the View requirements. Again the only place 
                 * concerned with the View business logic is this part and 
                 * isolating it from affecting other business logic not concerned 
                 * with the View requirements and how we display the data.
                 */

                String offenceDescLine1 = "", offenceDescLine2 = "";
                String setOffenceDesc = noticeOfTrialParameterFields.getParamOffenceDesc();
                logger.info("setOffenceDesc.length: " + setOffenceDesc.length());

                //Line accommodates exactly 88 chars
                if (null != setOffenceDesc && setOffenceDesc.trim().length() <= 88) {
                    offenceDescLine1 = setOffenceDesc;
                } else {
                    setOffenceDesc = setOffenceDesc.trim();
                    StringTokenizer tokens = new StringTokenizer(setOffenceDesc);
                    String token = "";

                    //build offenceDescLine1 first then offenceDescLine2
                    while (tokens.hasMoreTokens()) {
                        token = tokens.nextToken();

                        if ((offenceDescLine1.length() + token.length()) <= 88) {
                            offenceDescLine1 += " " + token;
                        } else {
                            //add token to next line since we already fetched it
                            offenceDescLine2 += token;
                            break;
                        }
                    }

                    while (tokens.hasMoreTokens()) {
                        token = tokens.nextToken();
                        offenceDescLine2 += " " + token;
                    }
                    logger.info("setOffenceDesc--: " + setOffenceDesc);
                    logger.info("offenceDescLine1: " + offenceDescLine1);
                    logger.info("offenceDescLine2: " + offenceDescLine2);
                }

                notice.setOffenceDesc(offenceDescLine1);
                notice.setOffenceDescLine2(offenceDescLine2);

                notice.setOffenceStatue(noticeOfTrialParameterFields.getParamOffenceStatue());
                notice.setOffenceSection(noticeOfTrialParameterFields.getParamOffenceSection());
                notice.setOffenceTotalPayable(noticeOfTrialParameterFields.getParamOffenceTotalPayable());
                notice.setTrialDay(noticeOfTrialParameterFields.getParamTrialDay());
                notice.setTrialMonth(noticeOfTrialParameterFields.getParamTrialMonth());
                notice.setTrailYear(noticeOfTrialParameterFields.getParamTrailYear());
                notice.setTrailTime(noticeOfTrialParameterFields.getParamTrailTime());
                notice.setTrailLocationCourtOffice(
                        noticeOfTrialParameterFields.getParamTrailLocationCourtOfficeId());
                notice.setIssuedAt(noticeOfTrialParameterFields.getParamIssuedAt());
                notice.setIssuedDay(noticeOfTrialParameterFields.getParamIssuedDay());
                notice.setIssuedMonth(noticeOfTrialParameterFields.getParamIssuedMonth());
                notice.setIssuedYear(noticeOfTrialParameterFields.getParamIssuedYear());
                notice.setFormNumberLabel(noticeOfTrialParameterFields.getParamFormNumberLabel());
                //Added Sep 13. 2011 - Anan
                notice.setNoticeHeaderEN(noticeOfTrialParameterFields.getParamNoticeHeaderEN());
                notice.setNoticeHeaderFR(noticeOfTrialParameterFields.getParamNoticeHeaderFR());
                notices.add(notice);

            } catch (Exception e) {
                e.printStackTrace();
                //returnMessage = "Request for Trial Was Not Retrieving Successful";
            }

        } //END if (null != crt && !crt.equals("")...
    } //END for (Iterator iter = requestForTrialToPrintVector.iterator()...

    return notices;
}