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.adobe.cq.wcm.core.components.internal.servlets.WorkflowModelDataSourceServlet.java

@Override
protected void doGet(@Nonnull SlingHttpServletRequest request, @Nonnull SlingHttpServletResponse response)
        throws ServletException, IOException {
    try {//from   ww w. ja  v a2  s  . c o  m
        WorkflowSession workflowSession = request.getResourceResolver().adaptTo(WorkflowSession.class);
        ArrayList<Resource> resources = new ArrayList<>();
        if (workflowSession != null) {
            WorkflowModel[] models = workflowSession.getModels();
            for (WorkflowModel model : models) {
                resources.add(new WorkflowModelResource(model, request.getResourceResolver()));
            }
        }
        SimpleDataSource dataSource = new SimpleDataSource(resources.iterator());
        request.setAttribute(DataSource.class.getName(), dataSource);
    } catch (WorkflowException e) {
        throw new ServletException(e);
    }
}

From source file:dom.rootlocus.utils.Utils.java

public void addtoLineChartSeries(ArrayList<List<Complex>> series, List<LineChartSeries> plotSeries,
        LineChartModel model, boolean marker) {
    Iterator it = series.iterator();
    int i = 0;//counter for plotSeries
    while (it.hasNext()) {
        List<Complex> serie = (List<Complex>) it.next();
        LineChartSeries chartSeries = plotSeries.get(i);
        if (marker) {
            chartSeries.setShowMarker(marker);
        } else {//from w  w w  .  j av  a 2  s. c om
            chartSeries.setShowMarker(false);
        }
        for (Complex c : serie) {
            chartSeries.set(c.getReal(), c.getImaginary());
        }
        model.addSeries(chartSeries);
        i++;
    }

}

From source file:jp.or.openid.eiwg.scim.servlet.Schemas.java

/**
 * GET?//from   w ww  .ja v  a  2 s  .com
 *
 * @param request 
 * @param response ?
 * @throws ServletException
 * @throws IOException
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // ?
    ServletContext context = getServletContext();

    // ??
    Operation op = new Operation();
    boolean result = op.Authentication(context, request);

    if (!result) {
        // 
        errorResponse(response, op.getErrorCode(), op.getErrorType(), op.getErrorMessage());
    } else {
        // location?URL?
        String location = request.getScheme() + "://" + request.getServerName();
        int serverPort = request.getServerPort();
        if (serverPort != 80 && serverPort != 443) {
            location += ":" + Integer.toString(serverPort);
        }
        location += request.getContextPath();

        // ?
        @SuppressWarnings("unchecked")
        ArrayList<LinkedHashMap<String, Object>> schemas = (ArrayList<LinkedHashMap<String, Object>>) context
                .getAttribute("Schemas");

        // location?
        Iterator<LinkedHashMap<String, Object>> schemasIt = schemas.iterator();
        while (schemasIt.hasNext()) {
            LinkedHashMap<String, Object> schemaInfo = schemasIt.next();
            // meta?
            Object metaObject = SCIMUtil.getAttribute(schemaInfo, "meta");
            if (metaObject != null && metaObject instanceof LinkedHashMap) {
                @SuppressWarnings("unchecked")
                LinkedHashMap<String, Object> metaInfo = (LinkedHashMap<String, Object>) metaObject;
                Object locationInfo = SCIMUtil.getAttribute(metaInfo, "location");
                if (locationInfo != null && locationInfo instanceof String) {
                    String locationValue = String.format(locationInfo.toString(), location);
                    metaInfo.put("location", locationValue);
                    schemaInfo.put("meta", metaInfo);
                }
            }
        }

        try {
            // javaJSON??
            ObjectMapper mapper = new ObjectMapper();
            StringWriter writer = new StringWriter();
            mapper.writeValue(writer, schemas);

            // ??
            String listResponse = "{\"schemas\":[\"urn:ietf:params:scim:api:messages:2.0:ListResponse\"],";
            listResponse += "\"totalResults\":" + schemas.size();
            if (schemas.size() > 0) {
                listResponse += ",\"Resources\":";
                listResponse += writer.toString();
            }
            listResponse += "}";

            response.setContentType("application/scim+json;charset=UTF-8");
            PrintWriter out = response.getWriter();
            out.println(listResponse);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}

From source file:com.example.SpeechRecognizer.java

private void ReturnSpeechResults(int requestCode, ArrayList<String> matches) {
    boolean firstValue = true;
    StringBuilder sb = new StringBuilder();
    sb.append("{\"speechMatches\": {");
    sb.append("\"requestCode\": ");
    sb.append(Integer.toString(requestCode));
    sb.append(", \"speechMatch\": [");

    Iterator<String> iterator = matches.iterator();
    while (iterator.hasNext()) {
        String match = iterator.next();

        if (firstValue == false)
            sb.append(", ");
        firstValue = false;/*  w w w .  ja  va2s  . com*/
        sb.append(JSONObject.quote(match));
    }
    sb.append("]}}");

    PluginResult result = new PluginResult(PluginResult.Status.OK, sb.toString());
    result.setKeepCallback(false);
    this.success(result, this.speechRecognizerCallbackId);
    this.speechRecognizerCallbackId = "";
}

From source file:logdruid.util.DataMiner.java

private static Map<Recording, String> getRegexp(Repository repo, Source source) {
    Map<Recording, String> recMatch = new HashMap<Recording, String>();
    Map<Recording, Boolean> activeRecordingOnSourceCache = new HashMap<Recording, Boolean>();
    ArrayList<Recording> recordings;
    recordings = repo.getRecordings(StatRecording.class);
    recordings.addAll(repo.getRecordings(EventRecording.class));
    StringBuffer sb = new StringBuffer(100);

    Iterator<Recording> recordingIterator = recordings.iterator();
    while (recordingIterator.hasNext()) {
        Recording rec = recordingIterator.next();
        if (!activeRecordingOnSourceCache.containsKey(rec)) {
            activeRecordingOnSourceCache.put(rec, source.isActiveRecordingOnSource(rec));
        }//from   w w  w. j a  v  a 2 s  .  c o m
        if (activeRecordingOnSourceCache.get(rec)) {
            if (rec.getIsActive() == true) {
                ArrayList<RecordingItem> recordingItem = ((Recording) rec).getRecordingItem();
                Iterator<RecordingItem> recItemIte = recordingItem.iterator();
                if (logger.isDebugEnabled()) {
                    logger.debug("Record: " + rec.getName());
                }
                sb.setLength(0);
                int cnt = 0;
                while (recItemIte.hasNext()) {
                    RecordingItem recItem = recItemIte.next();
                    String stBefore = (String) recItem.getBefore();
                    String stType = (String) recItem.getType();
                    String stAfter = (String) recItem.getAfter();
                    if (stType.equals("date")) {
                        sb.append(stBefore);
                        sb.append("(");
                        sb.append(repo.getDateFormat(rec.getDateFormatID()).getPattern());
                        sb.append(")");
                        sb.append(stAfter);
                    } else {
                        sb.append(stBefore);
                        sb.append("(");
                        sb.append(getTypeString(stType));
                        sb.append(")");
                        sb.append(stAfter);
                    }
                }
                recMatch.put(rec, sb.toString());

                // logger.info("2**** regexp: "
                // +rec.getRegexp());
                if (logger.isDebugEnabled()) {
                    logger.debug("Pattern: " + sb.toString());
                }
            }
        }
    }
    return recMatch;
}

From source file:logdruid.util.DataMiner.java

public static Map<String, ArrayList<FileRecord>> getSourceFileGroup(Map<Integer, FileRecord> sourceFiles,
        Source src, Repository repo) {
    PatternCache patternCache = new PatternCache();
    String patternString = "";
    Map<String, ArrayList<FileRecord>> sourceFileGroup = new HashMap<String, ArrayList<FileRecord>>();
    ArrayList<FileRecord> groupedFiles = new ArrayList<FileRecord>();
    // ArrayList<SourceItem> sourceItemArrayList = src.getSourceItem();
    ArrayList<Recording> recordings = (ArrayList<Recording>) repo.getRecordings(MetadataRecording.class);
    Matcher matcher = null;//from www . j ava 2  s.c om
    if (recordings != null) {
        Iterator<Recording> it = recordings.iterator();
        // logger.info("recordings not null ");
        while (it.hasNext()) {
            Recording rec = it.next();
            if (src.isActiveRecordingOnSource(rec)) {
                ArrayList<RecordingItem> rIV = ((MetadataRecording) rec).getRecordingItem();
                Iterator<RecordingItem> itV = rIV.iterator();
                int nbRec = 0;
                while (itV.hasNext()) {
                    RecordingItem rI = itV.next();
                    String type = rI.getType();
                    if (type == "date") {
                        patternString += rI.getBefore() + "(" + repo.getDateFormat(rec.getDateFormatID()) + ")"
                                + rI.getAfter();
                    } else {
                        patternString += rI.getBefore() + "(" + DataMiner.getTypeString(type) + ")"
                                + rI.getAfter();
                    }
                    // logger.info("patternString: " + patternString
                    // + " getType: " +
                    // DataMiner.getTypeString(rI.getType()));
                    nbRec++;
                }
                Iterator<FileRecord> sourceFileIterator = sourceFiles.values().iterator();
                String key = "";
                // tempV = new ArrayList<String>();
                while (sourceFileIterator.hasNext()) {
                    groupedFiles.clear();

                    FileRecord fileName = sourceFileIterator.next();
                    // logger.info("file: "+fileName);
                    try {

                        if (logger.isDebugEnabled())
                            logger.debug("patternString: " + patternString);
                        if (logger.isDebugEnabled())
                            logger.debug("filename: " + fileName);
                        // Pattern pattern = Pattern.compile(patternString +
                        // ".*");
                        // Matcher matcher = pattern.matcher(fileName);
                        matcher = patternCache.getPattern(patternString + ".*")
                                .matcher(new File(repo.getBaseSourcePath()).toURI()
                                        .relativize(new File(fileName.getFile().getCanonicalPath()).toURI())
                                        .getPath());
                        //***
                        if (matcher.find()) {
                            if (logger.isDebugEnabled())
                                logger.debug("found filename " + fileName + " with group");

                            key = "";
                            int i = 1;
                            for (i = 1; i <= matcher.groupCount(); i++) {
                                if (recordings.get(i).getIsActive()) {
                                    if (logger.isDebugEnabled())
                                        logger.debug("one : " + matcher.group(i));
                                    key += matcher.group(i) + " ";
                                }
                            }
                            if (logger.isDebugEnabled())
                                logger.debug("i : " + i + " nbRec: " + nbRec);
                            if (i - 1 == nbRec) {
                                if (logger.isDebugEnabled())
                                    logger.debug(" passed!");
                                if (!sourceFileGroup.containsKey(key)) {
                                    ArrayList<FileRecord> v = new ArrayList<FileRecord>();
                                    v.add(fileName);
                                    sourceFileGroup.put(key, v);
                                    if (logger.isDebugEnabled())
                                        logger.debug(" to key: " + key + " added : " + fileName);
                                } else {
                                    sourceFileGroup.get(key).add(fileName);
                                    if (logger.isDebugEnabled())
                                        logger.debug(" to key: " + key + " added : " + fileName);

                                }

                            }
                            /*
                             * if (tempV != null) { sourceFileGroup.put(key,
                             * tempV); logger.info("Added file " + fileName
                             * + " to group " + key.toString());
                             * logger.info("files " + tempV);
                             * 
                             * }
                             */
                        }

                    } catch (Exception e1) {
                        e1.printStackTrace();
                        // System.exit(1);
                    }

                    // logger.info("found group " + key + "with " +
                    // groupedFiles.size() + " files in source " +
                    // src.getSourceName());

                }
            }
        }
    }
    // TODO Auto-generated method stub
    return sourceFileGroup;
}

From source file:com.tacitknowledge.util.migration.jdbc.loader.DelimitedFileLoader.java

/**
 * Parses the table name from the file name, and the column names
 * from the header (first row) of the delimited file.  Creates an
 * insert query to insert a single row./*w w w. j  a  va2  s .  com*/
 *
 * @return query in the format: INSERT INTO tablename (colname, colname)...
 */
protected String getStatmentSql() {
    try {
        String columnHeader = getHeader(getResourceAsStream());
        String delimiter = getDelimiter();
        StringTokenizer st = new StringTokenizer(columnHeader, delimiter);
        ArrayList columnNames = new ArrayList();
        while (st.hasMoreTokens()) {
            columnNames.add((st.nextToken().trim()));
        }
        StringBuffer query = new StringBuffer("INSERT INTO ");
        query.append(getTableFromName());
        query.append(" (");
        Iterator it = columnNames.iterator();
        boolean firstTime = true;
        while (it.hasNext()) {
            if (!firstTime) {
                query.append(", ");
            } else {
                firstTime = false;
            }
            query.append((String) it.next());
        }
        query.append(") VALUES (");
        for (int i = 0; i < columnNames.size(); i++) {
            if (i > 0) {
                query.append(", ");
            }
            query.append("?");
        }
        query.append(")");
        return query.toString();
    } catch (IOException e) {
        log.error("No header was found for file: " + getName(), e);
    }
    return null;
}

From source file:info.magnolia.freemarker.models.BinaryNodeDataModel.java

@Override
public TemplateCollectionModel values() throws TemplateModelException {
    ArrayList<String> result = new ArrayList<String>();
    try {/*  w ww  .  j  a v  a2  s. c om*/
        Iterator<String> iter = binaryNodeData.getAttributeNames().iterator();
        while (iter.hasNext()) {
            result.add(iter.next());
        }
    } catch (RepositoryException e) {
        // don't care
    }
    return (TemplateCollectionModel) wrapper.wrap(result.iterator());
}

From source file:jp.or.openid.eiwg.scim.servlet.ResourceTypes.java

/**
 * GET?/* w w w.  j a  v a2  s.com*/
 *
 * @param request 
 * @param response ?
 * @throws ServletException
 * @throws IOException
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // ?
    ServletContext context = getServletContext();

    // ??
    Operation op = new Operation();
    boolean result = op.Authentication(context, request);

    if (!result) {
        // 
        errorResponse(response, op.getErrorCode(), op.getErrorType(), op.getErrorMessage());
    } else {
        // location?URL?
        String location = request.getScheme() + "://" + request.getServerName();
        int serverPort = request.getServerPort();
        if (serverPort != 80 && serverPort != 443) {
            location += ":" + Integer.toString(serverPort);
        }
        location += request.getContextPath();

        // ?
        @SuppressWarnings("unchecked")
        ArrayList<LinkedHashMap<String, Object>> resourceTypes = (ArrayList<LinkedHashMap<String, Object>>) context
                .getAttribute("ResourceTypes");

        // location?
        Iterator<LinkedHashMap<String, Object>> resourceTypesIt = resourceTypes.iterator();
        while (resourceTypesIt.hasNext()) {
            LinkedHashMap<String, Object> resourceTypeInfo = resourceTypesIt.next();
            // meta?
            Object metaObject = SCIMUtil.getAttribute(resourceTypeInfo, "meta");
            if (metaObject != null && metaObject instanceof LinkedHashMap) {
                @SuppressWarnings("unchecked")
                LinkedHashMap<String, Object> metaInfo = (LinkedHashMap<String, Object>) metaObject;
                Object locationInfo = SCIMUtil.getAttribute(metaInfo, "location");
                if (locationInfo != null && locationInfo instanceof String) {
                    String locationValue = String.format(locationInfo.toString(), location);
                    metaInfo.put("location", locationValue);
                    resourceTypeInfo.put("meta", metaInfo);
                }
            }
        }

        try {
            // javaJSON??
            ObjectMapper mapper = new ObjectMapper();
            StringWriter writer = new StringWriter();
            mapper.writeValue(writer, resourceTypes);

            // ??
            String listResponse = "{\"schemas\":[\"urn:ietf:params:scim:api:messages:2.0:ListResponse\"],";
            listResponse += "\"totalResults\":" + resourceTypes.size();
            if (resourceTypes.size() > 0) {
                listResponse += ",\"Resources\":";
                listResponse += writer.toString();
            }
            listResponse += "}";

            response.setContentType("application/scim+json;charset=UTF-8");
            PrintWriter out = response.getWriter();
            out.println(listResponse);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}

From source file:com.rapidminer.operator.preprocessing.discretization.MinimalEntropyDiscretization.java

/**
 * Delivers the maximum range thresholds for all attributes, i.e. the value getRanges()[a][b] is
 * the b-th threshold for the a-th attribute.
 *
 * @throws UserError/*from  w w w  .j  a v  a 2s. com*/
 *             is label is missing
 */
private double[][] getRanges(ExampleSet exampleSet) throws UserError {
    double[][] ranges = new double[exampleSet.getAttributes().size()][];
    Attribute label = exampleSet.getAttributes().getLabel();
    if (label == null) {
        throw new UserError(this, 105);
    }

    int a = 0;
    for (Attribute attribute : exampleSet.getAttributes()) {
        if (attribute.isNumerical()) { // skip nominal and date attributes
            Iterator<Example> reader = exampleSet.iterator();
            LinkedList<double[]> startPartition = new LinkedList<double[]>();
            while (reader.hasNext()) { // Create start partition.
                Example example = reader.next();
                double[] attributeLabelPair = new double[2];
                attributeLabelPair[0] = example.getValue(attribute);
                attributeLabelPair[1] = example.getValue(label);
                startPartition.addLast(attributeLabelPair);
            }
            ArrayList<Double> splitpointsOfAttribute = getSplitpoints(startPartition, label);
            Iterator<Double> it = splitpointsOfAttribute.iterator();
            ranges[a] = new double[splitpointsOfAttribute.size() + 1];
            for (int i = 0; it.hasNext(); i++) {
                ranges[a][i] = it.next();
            }
            ranges[a][ranges[a].length - 1] = exampleSet.getStatistics(attribute, Statistics.MAXIMUM);
            Arrays.sort(ranges[a]);
        }
        a++;
    }
    return ranges;
}