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:de.suse.swamp.core.filter.DatabaseFilter.java

public String buildSQLString(ArrayList columns, ArrayList tables, ArrayList conditions) {
    StringBuffer sqlString = new StringBuffer("SELECT DISTINCT ");
    for (Iterator it = columns.iterator(); it.hasNext();) {
        sqlString.append(StringEscapeUtils.escapeSql((String) it.next())).append(", ");
    }/*from w  ww  .j  a v a 2 s.c o  m*/
    sqlString.delete(sqlString.length() - 2, sqlString.length());

    sqlString.append(" FROM ");
    for (Iterator it = tables.iterator(); it.hasNext();) {
        sqlString.append(StringEscapeUtils.escapeSql((String) it.next())).append(", ");
    }
    sqlString.delete(sqlString.length() - 2, sqlString.length());

    if (conditions != null && conditions.size() >= 1) {
        sqlString.append(" WHERE ");
        for (Iterator it = conditions.iterator(); it.hasNext();) {
            sqlString.append((String) it.next()).append(" AND ");
        }
        sqlString.delete(sqlString.length() - 5, sqlString.length());
    }

    // does this filter set an ordering?
    if (descending != null && orderColumn != null) {
        sqlString.append(" ORDER BY " + orderColumn);
        if (descending.equals(Boolean.TRUE))
            sqlString.append(" DESC");
        else
            sqlString.append(" ASC");
        sqlString.append(", dbWorkflows.wfid ASC");

    }
    if (limit > 0) {
        sqlString.append(" LIMIT " + limit);
    }

    sqlString.append(";");
    return sqlString.toString();
}

From source file:com.gunjan.businessLayer.dictServlet.java

protected String getJSONObjectForWord(String word) throws IOException {
    DBConnection conn = DBConnection.getConnection();
    ArrayList defs = conn.getDefinition(word);
    if (defs == null) {
        defs = new ArrayList();
    }//from  w w w  .  j  a  v a  2  s  .  c om
    Iterator<Definition> it = defs.iterator();
    JSONArray defList = new JSONArray();
    while (it.hasNext()) {
        Definition d = (Definition) it.next();
        JSONObject obj = new JSONObject();
        obj.put("type", d.getType());
        obj.put("definition", d.getDefinition());
        defList.add(obj);
    }
    JSONObject mainObj = new JSONObject();
    mainObj.put("word", word);
    mainObj.put("definitions", defList);

    StringWriter out = new StringWriter();
    mainObj.writeJSONString(out);

    String jsonText = out.toString();
    return jsonText;
}

From source file:gr.ntua.ivml.awareness.search.SearchServiceAccess.java

public BasicDBObject searchEuropeanaRecord(String recid) throws Exception {
    URI uri = constructURIRecord(recid);
    httpGet = new HttpGet(uri);

    httpRes = httpClient.execute(httpGet);
    httpEntity = httpRes.getEntity();//from w  w  w.ja  va2  s.com
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    httpEntity.writeTo(out);
    String resprec = new String(out.toByteArray(), "UTF-8");
    BasicDBObject objrecord = (BasicDBObject) JSON.parse(resprec);

    BasicDBObject record = (BasicDBObject) objrecord.get("object");
    BasicDBObject re = new BasicDBObject();

    ArrayList<Object> items = (ArrayList<Object>) record.get("aggregations");
    Iterator<Object> it = items.iterator();
    while (it.hasNext()) {
        BasicDBObject tmp = (BasicDBObject) it.next();
        Object edmObject = tmp.get("edmObject");
        if (edmObject != null)
            re.put("europeana_image", edmObject.toString());

    }

    return re;

}

From source file:com.arainfor.thermostat.daemon.HvacMonitor.java

/**
 * This handles the callback for Thermometer changes.
 * @param thermometerChanged//  w w w .  j  a v  a  2 s.  c  o  m
 * @param value
 */
@Override
public synchronized void subjectChanged(Thermometer thermometerChanged, double value) {

    ArrayList<Temperature> temperatureList = TemperaturesList.getInstance().list();
    Iterator<Temperature> it = temperatureList.iterator();

    while (it.hasNext()) {
        Temperature temperature = it.next();
        if (temperature.getIndex() == thermometerChanged.getIndex()) {
            temperature.setValue(value);
            temperatureList.set(temperature.getIndex(), temperature);
            temperatureLogger.logMessage(temperatureList.toString());
            break;
        }
    }
}

From source file:TestStringsProvider.java

public void stringifyTestItems(ArrayList<String[]> itemsList) {
    setDataStrings(new String[itemsList.size()][8]);
    int i = 0;//w w  w.  j a va  2 s .com
    Iterator itr = itemsList.iterator();
    while (itr.hasNext()) {
        getDataStrings()[i] = (String[]) itr.next();
        i++;
    }
}

From source file:com.owly.srv.BasicDataMetricInJson.java

/**
 * This method is used to create the data in this object based in the array of Basic Stats captured from database previously. 
 * The data has two components : the label will be used to showe in the flot plugin, and the array of data with value,time.   
 * @param ListBasicStats is the list of captured metris from database
 * @param offset is the offset obtained with timezone in the customer browser
 *///from www.j  av a  2 s.  c  o  m
public void insertDataMetrics(ArrayList<BasicStat> ListBasicStats, Integer offset) {

    //Clean the data till now inserted.
    this.jsonDataArray.clear();

    Iterator it = ListBasicStats.iterator();

    //Process all values from the list of metrics to save in a format valid for flot.
    while (it.hasNext()) {
        Date d2 = new Date();
        BasicStat s = (BasicStat) it.next();
        Date d = s.getDate();
        //Change offset to milisseconds
        long msecOffset = ((long) offset) * 60 * 1000;
        Float v = Float.parseFloat(s.getValue());
        d2.setTime(d.getTime() - msecOffset);
        //logger.debug("date = " + d + ";date_offset = "+d2+";value = "+v );
        this.addJsonDataArray(d2, v);

    }

}

From source file:it.crs4.most.ehrlib.parser.AdlParser.java

/**
 * Gets the paths array./*from   www . ja v  a  2s . c o  m*/
 *
 * @param path the path
 * @return the paths array
 */
private String[] getPathsArray(String path) {
    ArrayList<String> pathsA = new ArrayList<String>(Arrays.asList(path.split("[\\[\\]/]")));

    Iterator<String> iter = pathsA.iterator();
    while (iter.hasNext()) {
        if (iter.next().equalsIgnoreCase(""))
            iter.remove();
    }
    return pathsA.toArray(new String[0]);
}

From source file:com.infovity.iep.loader.util.SupplierLoaderUtil.java

public static ArrayList<String> getSupplierInsertScript(ArrayList<String[]> data) {
    String batchNumber = loginTime + empId;
    String createdBy = userName;//from   w  w  w  .  j a v a2 s .  c  om
    String updatedBy = userName;
    String query = null;
    Set<Integer> set = getUniqueNumbersSet(data.size() * 7);
    int uniqueNumber = getUniqueNumber(set);
    //String[] value = new String[2];
    ArrayList<String> list = new ArrayList<String>();

    String primaryKeyForSupplierImportInterFace = "";
    String primaryKeyForSuppAdd = "";
    String primaryKeyForSuppSite = "";
    String primaryKeyForSuppPayee = "";
    String primaryKeyForSuppBankAccnts = "";
    String primaryKeyForSuppSiteAssign = "";
    String primaryKeyForSuppBankAccntAssgn = "";
    String previousValue = "";
    String previousSuppAdd = "";
    Iterator<String[]> iterator = data.iterator();
    Date date = new Date(System.currentTimeMillis());
    SimpleDateFormat formatter = new SimpleDateFormat("ddMMYYHHmmss");
    String formatted = formatter.format(date);
    while (iterator.hasNext()) {
        String[] val = iterator.next();
        if ((val[3] != null) && !val[3].equals("") && !val[3].equals(previousValue)) {
            query = "INSERT INTO SUPPLIER_IMPORT_INTERFACE VALUES(";
            uniqueNumber = getUniqueNumber(set);
            primaryKeyForSupplierImportInterFace = formatted + uniqueNumber;
            query = query + primaryKeyForSupplierImportInterFace + ",'" + val[0] + "'," + "'" + batchNumber
                    + "','" + createdBy + "',NOW(),'" + updatedBy + "',NOW(),'";
            for (int i = 2; i < 150; i++) {
                query = query + val[i] + "','";
            }
            query = query.substring(0, query.length() - 2) + ")";
            //System.out.println(query);
            list.add(query);
        }
        previousValue = val[3];
        //            if(val[150] == null || val[150].equals("")){
        //                primaryKeyForSuppAdd = null;
        //            }else{
        //                
        //            }
        if ((val[150] != null) && !val[150].equals("")) {// && !val[150].equals(previousSuppAdd)
            query = "INSERT INTO SUPP_ADD VALUES(";
            uniqueNumber = getUniqueNumber(set);
            primaryKeyForSuppAdd = formatted + uniqueNumber;
            query = query + primaryKeyForSuppAdd + "," + primaryKeyForSupplierImportInterFace + ",'" + val[0]
                    + "'," + "'" + batchNumber + "','" + createdBy + "',NOW(),'" + updatedBy + "',NOW(),'";
            //code to insert foriegn key and remaining.
            for (int i = 150; i < 240; i++) {
                query = query + val[i] + "','";
            }
            query = query.substring(0, query.length() - 2) + ")";
            //                System.out.println(query);
            list.add(query);
        }
        previousSuppAdd = val[150];
        String previousSuppSite = val[240];
        if ((previousSuppSite != null) && !previousSuppSite.equals("")) {
            if (previousSuppAdd == null || previousSuppAdd.equals("")) {
                primaryKeyForSuppAdd = null;
            }
            query = "INSERT INTO SUPPLIER_SITE VALUES(";
            uniqueNumber = getUniqueNumber(set);
            primaryKeyForSuppSite = formatted + uniqueNumber;
            query = query + primaryKeyForSuppSite + "," + primaryKeyForSuppAdd + ",'" + val[0] + "'," + "'"
                    + batchNumber + "','" + createdBy + "',NOW(),'" + updatedBy + "',NOW(),'";
            //code to insert foriegn key and remaining.
            for (int i = 240; i < 433; i++) {
                query = query + val[i] + "','";
            }
            query = query.substring(0, query.length() - 2) + ")";
            //                System.out.println(query);
            list.add(query);
        }
        previousSuppSite = val[240];
        query = "INSERT INTO SUPP_SITE_ASSGN VALUES(";
        uniqueNumber = getUniqueNumber(set);
        primaryKeyForSuppSiteAssign = formatted + uniqueNumber;
        query = query + primaryKeyForSuppSiteAssign + "," + primaryKeyForSuppSite + ",'" + val[0] + "'," + "'"
                + batchNumber + "','" + createdBy + "',NOW(),'" + updatedBy + "',NOW(),'";
        //code to insert foriegn key and remaining.
        for (int i = 433; i < 445; i++) {
            query = query + val[i] + "','";
        }
        query = query.substring(0, query.length() - 2) + ")";
        //            System.out.println(query);
        list.add(query);
        String previousPayeeId = val[446];
        if ((previousPayeeId != null) && !previousPayeeId.equals("")) {
            query = "INSERT INTO SUPP_PAYEE VALUES(";
            uniqueNumber = getUniqueNumber(set);
            primaryKeyForSuppPayee = formatted + uniqueNumber;
            query = query + primaryKeyForSuppPayee + "," + primaryKeyForSuppSite + ","
                    + primaryKeyForSupplierImportInterFace + ",'" + previousValue + "','" + val[0] + "'," + "'"
                    + batchNumber + "','" + createdBy + "',NOW(),'" + updatedBy + "',NOW(),'";
            //code to insert foriegn key and remaining.
            for (int i = 445; i < 466; i++) {
                query = query + val[i] + "','";
            }
            query = query.substring(0, query.length() - 2) + ")";
            //                System.out.println(query);
            list.add(query);
        }
        previousPayeeId = val[446];
        String previousPayeeBankAcId = val[468];
        if ((previousPayeeBankAcId != null) && !previousPayeeBankAcId.equals("")
                && !primaryKeyForSuppPayee.equals("")) {
            query = "INSERT INTO SUPP_BANK_ACCNTS VALUES(";
            uniqueNumber = getUniqueNumber(set);
            primaryKeyForSuppBankAccnts = formatted + uniqueNumber;
            query = query + primaryKeyForSuppBankAccnts + "," + primaryKeyForSuppPayee + ",'" + val[0] + "',"
                    + "'" + batchNumber + "','" + createdBy + "',NOW(),'" + updatedBy + "',NOW(),'";
            //code to insert foriegn key and remaining.
            for (int i = 466; i < 505; i++) {
                query = query + val[i] + "','";
            }
            query = query.substring(0, query.length() - 2) + ")";
            //                    System.out.println(query);
            list.add(query);

            query = "INSERT INTO SUPP_BANK_ACCNT_ASSGN VALUES(";
            uniqueNumber = getUniqueNumber(set);
            primaryKeyForSuppBankAccntAssgn = formatted + uniqueNumber;
            // primaryKeyForSuppBankAccnts;
            query = query + primaryKeyForSuppBankAccntAssgn + "," + primaryKeyForSuppBankAccnts + ",'" + val[0]
                    + "'," + "'" + batchNumber + "','" + createdBy + "',NOW(),'" + updatedBy + "',NOW(),'";
            //code to insert foriegn key and remaining.
            for (int i = 505; i < 512; i++) {
                query = query + val[i] + "','";
            }
            query = query.substring(0, query.length() - 2) + ")";
            //                    System.out.println(query);
            list.add(query);
        }
        previousPayeeBankAcId = val[468];
    }
    return list;
}

From source file:de.klemp.middleware.controller.Controller.java

/**
 * This method returns the names from the classes of the defined component.
 * This method uses: the class "Servlet"
 * /*ww w.j a  v a 2s . co  m*/
 * @param component
 *            1 or 2
 * @return String of the names. <br>
 *         "," separates the names.
 */
public static String getClassNames(String component) {
    // http://www.java-forum.org/web-tier/136754-string-array-javascript.html
    ArrayList list = getClasses(component);
    String names = new String();
    Iterator iterator = list.iterator();
    while (iterator.hasNext()) {
        Object o = iterator.next();
        String name = o.getClass().getName();
        String[] name1 = name.split("\\.");
        if (iterator.hasNext()) {
            names = names + "" + name1[1] + ",";
        } else {
            names = names + "" + name1[1] + "";
        }
    }
    return names;
}

From source file:de.klemp.middleware.controller.Controller.java

/**
 * This method invokes the methods from the second component. It is used by
 * the method informController(). The variables classes and methodName are
 * used to find the correct method. The variables nameInput,data and topic
 * are used for submit them to the method.
 * //from w  w  w.jav a 2s . co  m
 * @param classes
 *            class from the method
 * @param methodName
 *            name of the method to invoke
 * @param nameInput
 *            name of the input device
 * @param data
 *            name of the data
 * @param topic
 *            topic for the message broker
 */
private static Method getMethod(String classes, String methodName) {
    Method m = null;
    System.out.println(classes + " " + methodName);
    ArrayList<Object> getClasses = getClasses(component2);
    Iterator<Object> iterator = getClasses.iterator();
    // http://stackoverflow.com/questions/160970/how-do-i-invoke-a-java-method-when-given-the-method-name-as-a-string

    while (iterator.hasNext()) {
        Object c = iterator.next();
        System.out.println("Klassen der 2ten Schicht:" + c.getClass().getName());
        String name = c.getClass().getName();
        System.out.println(name);
        String[] classenName = name.split("\\.");
        if (classenName[1].equals(classes)) {
            Method[] methods = c.getClass().getDeclaredMethods();
            for (int i = 0; i < methods.length; i++) {
                System.out.println(
                        methodName + "hallo:methode:" + methods[i].getName() + "methodenName:" + methodName);
                if (methods[i].getName().equals(methodName)) {
                    try {
                        return methods[i];

                    } catch (IllegalArgumentException e) {
                        logger.error("Method of the second component could not be returned", e);
                    }
                }
            }
        }
    }
    return m;
}