Example usage for java.util ArrayList iterator

List of usage examples for java.util ArrayList iterator

Introduction

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

Prototype

public Iterator<E> iterator() 

Source Link

Document

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

Usage

From source file:com.concursive.connect.web.portal.PortalUtils.java

public static void populateObject(Object bean, ActionRequest request) {
    String nestedAttribute = "_";

    Enumeration en = request.getParameterNames();
    String paramName = null;/*from  w w  w .  ja  v a  2  s  . c o  m*/
    while (en.hasMoreElements()) {
        paramName = (String) en.nextElement();

        // a form has been submitted and requested to be auto-populated,
        // so we do that here..going through every element and trying
        // to call a setXXX() method on the bean object passed in for the value
        // of the request parameter currently being checked.
        String[] paramValues = request.getParameterValues(paramName);
        if (paramValues.length > 1) {
            ObjectUtils.setParam(bean, paramName, paramValues, nestedAttribute);
        } else {
            ObjectUtils.setParam(bean, paramName, paramValues[0], nestedAttribute);
        }
    }

    // TODO: currently for ticket and ticket history
    //ObjectUtils.invokeMethod(bean, "setRequestItems", new HttpRequestContext(request));
    // Check for valid user
    User thisUser = (User) request.getAttribute(Constants.REQUEST_USER);
    if (thisUser != null) {
        // Populate date/time fields using the user's timezone and locale
        if (thisUser.getTimeZone() != null) {
            ArrayList timeParams = (ArrayList) ObjectUtils.getObject(bean, "TimeZoneParams");
            if (timeParams != null) {
                Calendar cal = Calendar.getInstance();
                Iterator i = timeParams.iterator();
                while (i.hasNext()) {
                    // The property that can be set
                    String name = (String) i.next();
                    // See if it is in the request
                    String value = request.getParameter(name);
                    if (value != null) {
                        // See if time is in request too
                        String hourValue = request.getParameter(name + "Hour");
                        if (hourValue == null) {
                            // Date fields: 1-1 mapping between HTML field and Java property
                            ObjectUtils.setParam(bean, name,
                                    DateUtils.getUserToServerDateTimeString(
                                            TimeZone.getTimeZone(thisUser.getTimeZone()), DateFormat.SHORT,
                                            DateFormat.LONG, value, thisUser.getLocale()));
                        } else {
                            // Date & Time fields: 4-1 mapping between HTML fields and Java property
                            try {
                                Timestamp timestamp = DatabaseUtils.parseDateToTimestamp(value,
                                        thisUser.getLocale());
                                cal.setTimeInMillis(timestamp.getTime());
                                int hour = Integer.parseInt(hourValue);
                                int minute = Integer.parseInt(request.getParameter(name + "Minute"));
                                String ampmString = request.getParameter(name + "AMPM");
                                if (ampmString != null) {
                                    int ampm = Integer.parseInt(ampmString);
                                    if (ampm == Calendar.AM) {
                                        if (hour == 12) {
                                            hour = 0;
                                        }
                                    } else {
                                        if (hour < 12) {
                                            hour += 12;
                                        }
                                    }
                                }
                                cal.set(Calendar.HOUR_OF_DAY, hour);
                                cal.set(Calendar.MINUTE, minute);
                                cal.setTimeZone(TimeZone.getTimeZone(thisUser.getTimeZone()));
                                ObjectUtils.setParam(bean, name, new Timestamp(cal.getTimeInMillis()));
                            } catch (Exception dateE) {
                            }
                        }
                    }
                }
            }
        }

        // Populate number fields using the user's locale
        if (thisUser.getLocale() != null) {
            ArrayList numberParams = (ArrayList) ObjectUtils.getObject(bean, "NumberParams");
            if (numberParams != null) {
                NumberFormat nf = NumberFormat.getInstance(thisUser.getLocale());
                Iterator i = numberParams.iterator();
                while (i.hasNext()) {
                    // The property that can be set
                    String name = (String) i.next();
                    // See if it is in the request
                    String value = (String) request.getParameter(name);
                    if (value != null && !"".equals(value)) {
                        try {
                            // Parse the value
                            ObjectUtils.setParam(bean, name, nf.parse(value).doubleValue());
                        } catch (Exception e) {
                            //e.printStackTrace(System.out);
                        }
                    }
                }
            }
        }
    }
}

From source file:glluch.com.ontotaxoseeker.TestsGen.java

public void testTermsResults() throws IOException, FileNotFoundException, ClassNotFoundException {
    Terms ts = (Terms) TestsGen.load("resources/test/Terms.ser");
    ArrayList<Term> terms = ts.terms();
    Iterator iter = terms.iterator();
    ArrayList<String> lemas = new ArrayList<>();
    while (iter.hasNext()) {
        Term next = (Term) iter.next();/*from  ww w  .  j av a 2s.  co  m*/
        lemas.add(next.getLema());
    }
    File target = new File("resources/test/testTermsResults.bin");
    byte[] vs = SerializationUtils.serialize(lemas);
    FileUtils.writeByteArrayToFile(target, vs);
}

From source file:ch.epfl.bbp.uima.annotationviewer.BlueAnnotationViewGenerator.java

/**
 * Automatically generates a style map for the given text analysis engine.
 * The style map will be returned as an XML string.
 * // w w  w. j  av a  2s  . c o m
 * @param aTaeMetaData
 *            Metadata of the Text Analysis Engine whose outputs will be
 *            viewed using the generated style map.
 * 
 * @return a String containing the XML style map
 */
public static String autoGenerateStyleMap(AnalysisEngineMetaData aTaeMetaData) {
    // styles used in automatically generated style maps

    final String[] STYLES = { "color:black; background:lightblue;", "color:black; background:lightgreen;",
            "color:black; background:orange;", "color:black; background:yellow;",
            "color:black; background:pink;", "color:black; background:salmon;", "color:black; background:cyan;",
            "color:black; background:violet;", "color:black; background:tan;", "color:white; background:brown;",
            "color:white; background:blue;", "color:white; background:green;", "color:white; background:red;",
            "color:white; background:mediumpurple;" };

    // get list of output types from TAE
    ArrayList outputTypes = new ArrayList();
    Capability[] capabilities = aTaeMetaData.getCapabilities();

    for (int i = 0; i < capabilities.length; i++) {
        TypeOrFeature[] outputs = capabilities[i].getOutputs();

        for (int j = 0; j < outputs.length; j++) {
            if (outputs[j].isType() && !outputTypes.contains(outputs[j].getName())) {
                outputTypes.add(outputs[j].getName());
            }
        }
    }

    // generate style map by mapping each type to a background color
    StringBuffer buf = new StringBuffer();

    buf.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n");
    buf.append("<styleMap>\n");

    int i = 0;
    Iterator it = outputTypes.iterator();

    while (it.hasNext()) {
        String outputType = (String) it.next();
        String label = outputType;
        int lastDot = outputType.lastIndexOf('.');
        if (lastDot > -1) {
            label = outputType.substring(lastDot + 1);
        }

        buf.append("<rule>\n");
        buf.append("<pattern>");
        buf.append(outputType);
        buf.append("</pattern>\n");
        buf.append("<label>");
        buf.append(label);
        buf.append("</label>\n");
        buf.append("<style>");
        buf.append(STYLES[i % STYLES.length]);
        buf.append("</style>\n");
        buf.append("</rule>\n");
        i++;
    }

    buf.append("</styleMap>\n");

    return buf.toString();
}

From source file:org.toobsframework.email.SmtpMailSender.java

private String[] processRecipients(ArrayList recipients) {

    List retRecipients = new ArrayList();
    Iterator it = recipients.iterator();
    while (it.hasNext()) {
        StringTokenizer st = new StringTokenizer((String) it.next(), ",");
        while (st.hasMoreTokens()) {
            retRecipients.add(st.nextToken());
        }/*  ww w.j a  v a 2s.  c o  m*/
    }

    String[] ary = new String[retRecipients.size()];
    return (String[]) retRecipients.toArray(ary);
}

From source file:cloudlens.engine.CLIterator.java

public CLIterator(BlockEngine engine, ArrayList<BlockObject> array, boolean withHistory) {
    this.it = array.iterator();
    this.history = new ArrayList<>(array);
    this.mem = new ArrayList<>();
    this.withHistory = withHistory;
}

From source file:glluch.com.ontotaxoseeker.TermsTest.java

/**
 * Test of terms method, of class Terms.
 * @throws java.io.IOException//from w w w.  j a  va 2s.  c  om
 * @throws java.io.FileNotFoundException
 * @throws java.lang.ClassNotFoundException
 */
@Test
public void testTerms() throws IOException, FileNotFoundException, ClassNotFoundException {
    TermsTest.resetTs();
    System.out.println("Terms.terms");
    Terms instance = TermsTest.ts;
    File file = new File("resources/test/testTermsResults.bin");
    byte[] v = FileUtils.readFileToByteArray(file);
    ArrayList<String> expResult = SerializationUtils.deserialize(v);
    ArrayList<Term> result = instance.terms();
    Iterator iter = result.iterator();
    ArrayList<String> lemas = new ArrayList<>();
    while (iter.hasNext()) {
        Term next = (Term) iter.next();
        lemas.add(next.getLema());
    }
    Object[] lemas1 = lemas.toArray();
    Object[] exp = expResult.toArray();
    java.util.Arrays.sort(lemas1);
    java.util.Arrays.sort(exp);
    //Out.p(lemas1);
    //Out.p(exp);
    Assert.assertArrayEquals(exp, lemas1);

}

From source file:de.kaiserpfalzEdv.commons.jee.paging.SortDO.java

@Override
public Iterator<Order> iterator() {
    ArrayList<Order> result = new ArrayList<>();

    sort.forEach(o -> result.add(new OrderDO(o)));

    return result.iterator();
}

From source file:edu.harvard.mcz.nametools.ICNafpAuthorNameComparator.java

/**
 * Given a botanical authorship string, split it into a list of component 
 * authors on parenthetical authors, ex authors, and sanctioning authors.
 * //from  w w  w  .  ja v  a  2s .  c  om
 * @param authorship to tokenize
 * @return a list of authorship strings representing the components of the 
 * authorship string.
 */
public static List<String> tokenizeAuthorship(String authorship) {
    ArrayList<String> bits = new ArrayList<String>();
    ArrayList<String> subbits = new ArrayList<String>();
    ArrayList<String> result = new ArrayList<String>();

    if (authorship == null || authorship.length() == 0) {
        return result;
    }

    // separate out parenthetical author
    logger.debug(authorship);
    if (authorship.matches("^\\(.*\\).+$")) {
        String[] parBits = authorship.split("\\)");
        logger.debug(parBits.length);
        logger.debug(parBits[0]);
        bits.add(parBits[0].replaceFirst("^\\(", ""));
        bits.add(parBits[1]);
    } else {
        bits.add(authorship);
    }

    // separate out ex author
    Iterator<String> i = bits.iterator();
    while (i.hasNext()) {
        String bit = i.next();
        if (bit.contains(" ex ")) {
            String[] exBits = bit.split(" ex ");
            logger.debug(exBits.length);
            logger.debug(exBits[0]);
            logger.debug(exBits[1]);
            subbits.add(exBits[0]);
            subbits.add(exBits[1]);
        } else {
            logger.debug(bit);
            subbits.add(bit);
        }

    }

    // separate out sanctioning author
    Iterator<String> ir = subbits.iterator();
    while (ir.hasNext()) {
        String bit = ir.next();
        if (bit.contains(":")) {
            String[] exBits = bit.split(":");
            result.add(exBits[0]);
            result.add(exBits[1]);
        } else {
            result.add(bit);
        }

    }
    // strip any leading/trailing spaces
    for (int j = 0; j < result.size(); j++) {
        result.set(j, result.get(j).trim());
    }

    return result;
}

From source file:glluch.com.ontotaxoseeker.Terms.java

public Iterator iterator() {
    ArrayList<Term> keys = this.terms();
    return keys.iterator();
}

From source file:contrail.correct.TestFlashExtension.java

private void assertMapOutput(ArrayList<fastqrecord> actualOutput, HashMap<String, String> expectedHashMap) {
    Iterator<fastqrecord> iterator = actualOutput.iterator();
    while (iterator.hasNext()) {
        fastqrecord flashedRecord = iterator.next();
        String id = flashedRecord.getId().toString();
        String dna = flashedRecord.getRead().toString();
        String qvalue = flashedRecord.getQvalue().toString();
        String receivedValue = dna + " " + qvalue;
        assertEquals(expectedHashMap.get(id), receivedValue);
    }//from   ww  w. j a  v  a  2 s .c om
}