Example usage for java.util StringTokenizer hasMoreElements

List of usage examples for java.util StringTokenizer hasMoreElements

Introduction

In this page you can find the example usage for java.util StringTokenizer hasMoreElements.

Prototype

public boolean hasMoreElements() 

Source Link

Document

Returns the same value as the hasMoreTokens method.

Usage

From source file:org.globus.ftp.GridFTPRestartMarker.java

/**
   Constructs the restart marker by parsing the parameter string.
   @param msg The string in the format of FTP reply 111 message,
   for instance "Range Marker 0-29,30-89"
   @throws IllegalArgumentException if the parameter is in bad format
 **//*w w w  . j  a v a2 s  . com*/
public GridFTPRestartMarker(String msg) throws IllegalArgumentException {

    // expecting msg like "Range Marker 0-29,30-89"

    vector = new Vector();
    StringTokenizer tokens = new StringTokenizer(msg);

    if (!tokens.hasMoreTokens()) {
        badMsg("message empty", msg);
    }

    if (!tokens.nextToken(" ").equals("Range")) {
        badMsg("should start with Range Marker", msg);
    }
    if (!tokens.nextToken(" ").equals("Marker")) {
        badMsg("should start with Range Marker", msg);
    }

    while (tokens.hasMoreTokens()) {
        long from = 0;
        long to = 0;
        try {

            String rangeStr = tokens.nextToken(",");
            StringTokenizer rangeTok = new StringTokenizer(rangeStr, "-");
            from = Long.parseLong(rangeTok.nextToken().trim());
            to = Long.parseLong(rangeTok.nextToken().trim());

            if (rangeTok.hasMoreElements()) {
                badMsg("A range is followed by '-'", msg);
            }

        } catch (NoSuchElementException nse) {
            // range does not look like "from-to"
            badMsg("one of the ranges is malformatted", msg);
        } catch (NumberFormatException nfe) {
            badMsg("one of the integers is malformatted", msg);
        }

        try {

            vector.add(new ByteRange(from, to));

        } catch (IllegalArgumentException iae) {
            // to < from
            badMsg("range beginning > range end", msg);
        }
    }
    //vector now contains all ranges
    if (vector.size() == 0) {
        badMsg("empty range list", msg);
    }
}

From source file:gtu.zcognos.SimpleUI.java

private void initGUI() {
    try {/*w ww . j  a va2s  .  c o m*/

        final SwingActionUtil swingUtil = (SwingActionUtil) SwingActionUtil.newInstance(this);
        {
            GroupLayout thisLayout = new GroupLayout((JComponent) getContentPane());
            getContentPane().setLayout(thisLayout);
            this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            {
                projectId = new JTextField();
            }
            {
                packageId = new JTextField();
            }
            {
                jLabel1 = new JLabel();
                jLabel1.setText("PROJECT_ID");
            }
            {
                jLabel2 = new JLabel();
                jLabel2.setText("PACKAGE_ID");
            }
            {
                jLabel3 = new JLabel();
                jLabel3.setText("DATATABLE");
            }
            {
                jScrollPane1 = new JScrollPane();
                {
                    dataTable = new JTextArea();
                    jScrollPane1.setViewportView(dataTable);
                }
            }
            {
                create = new JButton();
                create.setText("create");
                create.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        swingUtil.invokeAction("create.actionPerformed", evt);
                    }
                });
            }
            thisLayout.setVerticalGroup(thisLayout.createSequentialGroup().addContainerGap(16, 16)
                    .addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(projectId, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(thisLayout.createParallelGroup().addGroup(GroupLayout.Alignment.LEADING,
                            thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                    .addComponent(packageId, GroupLayout.Alignment.BASELINE,
                                            GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE,
                                            GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel2, GroupLayout.Alignment.BASELINE,
                                            GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE,
                                            GroupLayout.PREFERRED_SIZE))
                            .addGroup(GroupLayout.Alignment.LEADING,
                                    thisLayout.createSequentialGroup()
                                            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 0,
                                                    Short.MAX_VALUE)
                                            .addComponent(create, GroupLayout.PREFERRED_SIZE, 22,
                                                    GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jLabel3, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 217, GroupLayout.PREFERRED_SIZE)
                    .addContainerGap());
            thisLayout.setHorizontalGroup(thisLayout.createSequentialGroup().addContainerGap(31, 31).addGroup(
                    thisLayout.createParallelGroup().addGroup(GroupLayout.Alignment.LEADING, thisLayout
                            .createSequentialGroup()
                            .addGroup(thisLayout.createParallelGroup()
                                    .addComponent(jLabel2, GroupLayout.Alignment.LEADING,
                                            GroupLayout.PREFERRED_SIZE, 103, GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel1, GroupLayout.Alignment.LEADING,
                                            GroupLayout.PREFERRED_SIZE, 103, GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel3, GroupLayout.Alignment.LEADING,
                                            GroupLayout.PREFERRED_SIZE, 103, GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(thisLayout.createParallelGroup()
                                    .addComponent(packageId, GroupLayout.Alignment.LEADING,
                                            GroupLayout.PREFERRED_SIZE, 204, GroupLayout.PREFERRED_SIZE)
                                    .addComponent(projectId, GroupLayout.Alignment.LEADING,
                                            GroupLayout.PREFERRED_SIZE, 204, GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(create, GroupLayout.PREFERRED_SIZE, 88, GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 0, Short.MAX_VALUE))
                            .addGroup(thisLayout.createSequentialGroup()
                                    .addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 417,
                                            GroupLayout.PREFERRED_SIZE)
                                    .addGap(0, 0, Short.MAX_VALUE)))
                    .addContainerGap(17, 17));
        }
        this.setSize(473, 356);

        swingUtil.addAction("create.actionPerformed", new Action() {
            public void action(EventObject evt) throws Exception {
                String project = projectId.getText();
                String dataTab = dataTable.getText();
                Validate.notEmpty(project);
                Validate.notEmpty(dataTab);
                String pkgId = StringUtils.defaultIfEmpty(packageId.getText(), project);

                List<String> dataTableList = new ArrayList<String>();
                StringTokenizer tok = new StringTokenizer(dataTab);
                for (int ii = 0; tok.hasMoreElements(); ii++) {
                    String column = (String) tok.nextElement();
                    System.out.format("%d -- %s\n", ii, column);
                    if (StringUtils.isBlank(column)) {
                        continue;
                    }
                    dataTableList.add(column.trim());
                }

                File destDir = new File(CREATE_DEST + "\\" + project);
                destDir.mkdirs();

                Map<String, Object> map = new HashMap<String, Object>();
                map.put("PROJECT_ID", project);
                map.put("PACKAGE_ID", pkgId);
                map.put("DATATABLE", dataTableList);

                ConfigCopy.getInstance().applyBaseDir(new File(CREATE_DEST)).applyProjectId(project).execute();

                Simple.getInstance()//
                        .applyDestDir(destDir.getAbsolutePath())//
                        .applyParameter(map)//
                        .execute();

                JOptionPaneUtil.newInstance().iconInformationMessage()
                        .showMessageDialog(pkgId + " create completed!!\r\n dir : " //
                                + destDir.getAbsolutePath(), pkgId);

                Desktop.getDesktop().open(destDir);
            }
        });

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

From source file:org.openmrs.module.addresshierarchyrwanda.htmlformentry.element.AddressHierarchySubmissionElement.java

public AddressHierarchySubmissionElement(FormEntryContext context, HttpServletRequest request,
        Map<String, String> parameters) {
    Patient existingPatient = context.getExistingPatient();
    addressWidgetList = new ArrayList<Widget>();
    errorWidget = new ErrorWidget();

    // check parameter types (optional)
    String types = parameters.get(FIELD_TYPES);
    if (types != null && types.length() > 1) {
        StringTokenizer tokenizer = new StringTokenizer(types, ",");
        while (tokenizer.hasMoreElements()) {
            String element = ((String) tokenizer.nextElement()).trim();
            if (element.equalsIgnoreCase(AddressHierarchyWidget.TYPE_COUNTRY)
                    || element.equalsIgnoreCase(AddressHierarchyWidget.TYPE_PROVINCE)
                    || element.equalsIgnoreCase(AddressHierarchyWidget.TYPE_DISTRICT)
                    || element.equalsIgnoreCase(AddressHierarchyWidget.TYPE_SECTOR)
                    || element.equalsIgnoreCase(AddressHierarchyWidget.TYPE_CELL)
                    || element.equalsIgnoreCase(AddressHierarchyWidget.TYPE_UMUDUGUDU)) {
                addressWidgetList.add(new AddressHierarchyWidget(element, existingPatient.getPersonAddress()));
            } else {
                throw new IllegalArgumentException(
                        "You must provide a valid type for example country in " + parameters);
            }//from  w ww . jav  a  2s .  com
        }
    } else {
        addressWidgetList.add(new AddressHierarchyWidget(AddressHierarchyWidget.TYPE_COUNTRY,
                existingPatient.getPersonAddress()));
        addressWidgetList.add(new AddressHierarchyWidget(AddressHierarchyWidget.TYPE_PROVINCE,
                existingPatient.getPersonAddress()));
        addressWidgetList.add(new AddressHierarchyWidget(AddressHierarchyWidget.TYPE_DISTRICT,
                existingPatient.getPersonAddress()));
        addressWidgetList.add(new AddressHierarchyWidget(AddressHierarchyWidget.TYPE_SECTOR,
                existingPatient.getPersonAddress()));
        addressWidgetList.add(new AddressHierarchyWidget(AddressHierarchyWidget.TYPE_CELL,
                existingPatient.getPersonAddress()));
        addressWidgetList.add(new AddressHierarchyWidget(AddressHierarchyWidget.TYPE_UMUDUGUDU,
                existingPatient.getPersonAddress()));
    }

    // Register widgets
    registerWidgetList(addressWidgetList, context);
    context.registerWidget(errorWidget);
}

From source file:therian.operator.convert.EnumerationToListTest.java

private Enumeration<String> tokenize(String s) {
    final StringTokenizer tok = new StringTokenizer(s);
    return new Enumeration<String>() {

        @Override//from   www. j  a  v a 2s.c  o  m
        public String nextElement() {
            return tok.nextToken();
        }

        @Override
        public boolean hasMoreElements() {
            return tok.hasMoreElements();
        }
    };
}

From source file:com.properned.application.preferences.Preferences.java

/**
 * File are stored as File1:Date1|File2:Date2
 * //from   ww  w  . j av a  2s  .  c  o  m
 * @return the file as map
 */
private RecentFileSet getRecentFileSet() {
    if (this.recentFileSet == null) {
        String recentFileListString = this.properties.getProperty(Preferences.KEY_RECENT_FILE_LIST, "");
        this.logger
                .info("Initial value for '" + Preferences.KEY_RECENT_FILE_LIST + "' : " + recentFileListString);
        this.recentFileSet = new RecentFileSet(this.recentFileListSize);

        StringTokenizer recentFileStringTokenizer = new StringTokenizer(recentFileListString, "|");
        while (recentFileStringTokenizer.hasMoreElements()) {
            String recentFileString = recentFileStringTokenizer.nextToken();
            String[] recentFileTab = recentFileString.split("\\*");
            if (recentFileTab.length != 2) {
                continue;
            }
            File file = new File(recentFileTab[0]);
            Date lastAccessDate = new Date(Long.valueOf(recentFileTab[1]).longValue());
            this.recentFileSet.addRecentFile(new RecentFile(file, lastAccessDate));
        }
    }
    return this.recentFileSet;
}

From source file:org.wso2.carbon.identity.sso.saml.builders.assertion.DefaultSAMLAssertionBuilder.java

private AttributeStatement buildAttributeStatement(Map<String, String> claims) {

    String claimSeparator = claims.get(IdentityCoreConstants.MULTI_ATTRIBUTE_SEPARATOR);
    if (StringUtils.isNotBlank(claimSeparator)) {
        userAttributeSeparator = claimSeparator;
    }//from w w  w.  ja v  a 2 s  .  c om
    claims.remove(IdentityCoreConstants.MULTI_ATTRIBUTE_SEPARATOR);

    AttributeStatement attStmt = new AttributeStatementBuilder().buildObject();
    Iterator<Map.Entry<String, String>> iterator = claims.entrySet().iterator();
    boolean atLeastOneNotEmpty = false;
    for (int i = 0; i < claims.size(); i++) {
        Map.Entry<String, String> claimEntry = iterator.next();
        String claimUri = claimEntry.getKey();
        String claimValue = claimEntry.getValue();
        if (claimUri != null && !claimUri.trim().isEmpty() && claimValue != null
                && !claimValue.trim().isEmpty()) {
            atLeastOneNotEmpty = true;
            Attribute attribute = new AttributeBuilder().buildObject();
            attribute.setName(claimUri);
            //setting NAMEFORMAT attribute value to basic attribute profile
            attribute.setNameFormat(SAMLSSOConstants.NAME_FORMAT_BASIC);
            // look
            // https://wiki.shibboleth.net/confluence/display/OpenSAML/OSTwoUsrManJavaAnyTypes
            XSStringBuilder stringBuilder = (XSStringBuilder) Configuration.getBuilderFactory()
                    .getBuilder(XSString.TYPE_NAME);
            XSString stringValue;

            //Need to check if the claim has multiple values
            if (userAttributeSeparator != null && claimValue.contains(userAttributeSeparator)) {
                StringTokenizer st = new StringTokenizer(claimValue, userAttributeSeparator);
                while (st.hasMoreElements()) {
                    String attValue = st.nextElement().toString();
                    if (attValue != null && attValue.trim().length() > 0) {
                        stringValue = stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME,
                                XSString.TYPE_NAME);
                        stringValue.setValue(attValue);
                        attribute.getAttributeValues().add(stringValue);
                    }
                }
            } else {
                stringValue = stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME,
                        XSString.TYPE_NAME);
                stringValue.setValue(claimValue);
                attribute.getAttributeValues().add(stringValue);
            }

            attStmt.getAttributes().add(attribute);
        }
    }
    if (atLeastOneNotEmpty) {
        return attStmt;
    } else {
        return null;
    }
}

From source file:org.jasig.ssp.service.impl.StudentDocumentServiceImpl.java

private void initVolumes() {

    if (StringUtils.isEmpty(studentDocumentsVolumes)) {
        volumes.add("");
    } else {/*from  ww  w .  ja v  a 2s .c  o m*/
        StringTokenizer tokenizer = new StringTokenizer(studentDocumentsVolumes, ",");
        while (tokenizer.hasMoreElements()) {
            volumes.add((String) tokenizer.nextElement());
        }
    }
}

From source file:org.wso2.carbon.identity.saml.inbound.builders.assertion.DefaultSAMLAssertionBuilder.java

private AttributeStatement buildAttributeStatement(Map<String, String> claims) {

    String claimSeparator = claims.get(MULTI_ATTRIBUTE_SEPARATOR);
    if (StringUtils.isNotBlank(claimSeparator)) {
        userAttributeSeparator = claimSeparator;
    }//from  w w w . j  a  va2  s . c om
    claims.remove(MULTI_ATTRIBUTE_SEPARATOR);

    AttributeStatement attStmt = new AttributeStatementBuilder().buildObject();
    Iterator<Map.Entry<String, String>> iterator = claims.entrySet().iterator();
    boolean atLeastOneNotEmpty = false;
    for (int i = 0; i < claims.size(); i++) {
        Map.Entry<String, String> claimEntry = iterator.next();
        String claimUri = claimEntry.getKey();
        String claimValue = claimEntry.getValue();
        if (claimUri != null && !claimUri.trim().isEmpty() && claimValue != null
                && !claimValue.trim().isEmpty()) {
            atLeastOneNotEmpty = true;
            Attribute attribute = new AttributeBuilder().buildObject();
            attribute.setName(claimUri);
            //setting NAMEFORMAT attribute value to basic attribute profile
            attribute.setNameFormat(SAMLSSOConstants.NAME_FORMAT_BASIC);
            // look
            // https://wiki.shibboleth.net/confluence/display/OpenSAML/OSTwoUsrManJavaAnyTypes
            XSStringBuilder stringBuilder = (XSStringBuilder) Configuration.getBuilderFactory()
                    .getBuilder(XSString.TYPE_NAME);
            XSString stringValue;

            //Need to check if the claim has multiple values
            if (userAttributeSeparator != null && claimValue.contains(userAttributeSeparator)) {
                StringTokenizer st = new StringTokenizer(claimValue, userAttributeSeparator);
                while (st.hasMoreElements()) {
                    String attValue = st.nextElement().toString();
                    if (attValue != null && attValue.trim().length() > 0) {
                        stringValue = stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME,
                                XSString.TYPE_NAME);
                        stringValue.setValue(attValue);
                        attribute.getAttributeValues().add(stringValue);
                    }
                }
            } else {
                stringValue = stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME,
                        XSString.TYPE_NAME);
                stringValue.setValue(claimValue);
                attribute.getAttributeValues().add(stringValue);
            }

            attStmt.getAttributes().add(attribute);
        }
    }
    if (atLeastOneNotEmpty) {
        return attStmt;
    } else {
        return null;
    }
}

From source file:com.jkoolcloud.tnt4j.streams.inputs.JMXZabbixDataPuller.java

/**
 * {@inheritDoc}/*from w  w w.j  ava 2 s. com*/
 * <p>
 * Starts scheduler and schedules Cron expression defined job to invoke Zabbix queries.
 */
@Override
protected void initialize() throws Exception {
    super.initialize();

    if (StringUtils.isEmpty(jmxQueryString)) {
        throw new IllegalStateException(
                StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
                        "TNTInputStream.property.undefined", ZorkaConstants.PROP_JXM_QUERY));
    }

    this.scheduler = StdSchedulerFactory.getDefaultScheduler();
    this.scheduler.start();

    JobDataMap jobAttrs = new JobDataMap();
    jobAttrs.put(JOB_PROP_STREAM_KEY, this);
    jobAttrs.put(JOB_PROP_HOST_KEY, host);
    jobAttrs.put(JOB_PROP_PORT_KEY, socketPort);
    StringTokenizer tokenizer = new StringTokenizer(jmxQueryString, JMX_QUERIES_DELIMITER);
    while (tokenizer.hasMoreElements()) {
        jmxQueries.add(tokenizer.nextToken().trim());
    }
    jobAttrs.put(JOB_PROP_JMX_QUERIES_KEY, jmxQueries);

    CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(jmxSchedulerExpression);

    JobDetail job = JobBuilder.newJob(ZabbixCallJob.class).usingJobData(jobAttrs).build();
    trigger = TriggerBuilder.newTrigger().withIdentity(job.getKey() + "Trigger").startNow() // NON-NLS
            .withSchedule(scheduleBuilder).build();
    scheduler.scheduleJob(job, trigger);
}