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:jp.or.openid.eiwg.scim.util.SCIMUtil.java

/**
 * ??????/*from  w  w  w .  j  a  va 2s .c  om*/
 *
 * @param context
 * @param attributeName
 * @param isCore
 * @return ?
 */
public static LinkedHashMap<String, Object> getUserAttributeInfo(ServletContext context, String attributeName,
        boolean isCore) {
    LinkedHashMap<String, Object> result = null;

    Set<String> schemaIdSet = new HashSet<>();

    // ?
    @SuppressWarnings("unchecked")
    ArrayList<LinkedHashMap<String, Object>> resourceTypes = (ArrayList<LinkedHashMap<String, Object>>) context
            .getAttribute("ResourceTypes");
    Iterator<LinkedHashMap<String, Object>> resourceTypesIt = resourceTypes.iterator();
    while (resourceTypesIt.hasNext()) {
        LinkedHashMap<String, Object> resourceTypeInfo = resourceTypesIt.next();
        Object endpoint = SCIMUtil.getAttribute(resourceTypeInfo, "endpoint");
        if (endpoint != null && endpoint.toString().equalsIgnoreCase("/Users")) {
            Object schema = SCIMUtil.getAttribute(resourceTypeInfo, "schema");
            if (schema != null) {
                schemaIdSet.add(schema.toString());
            }

            Object schemaExtensions = SCIMUtil.getAttribute(resourceTypeInfo, "schemaExtensions");
            if (schemaExtensions != null && schemaExtensions instanceof ArrayList) {
                @SuppressWarnings("unchecked")
                ArrayList<LinkedHashMap<String, Object>> schemaExtensionList = (ArrayList<LinkedHashMap<String, Object>>) schemaExtensions;
                Iterator<LinkedHashMap<String, Object>> schemaExtensionListIt = schemaExtensionList.iterator();
                while (schemaExtensionListIt.hasNext()) {
                    LinkedHashMap<String, Object> schemaExtensionInfo = schemaExtensionListIt.next();
                    schema = SCIMUtil.getAttribute(schemaExtensionInfo, "schema");
                    if (schema != null) {
                        schemaIdSet.add(schema.toString());
                    }
                }
            }

            break;
        }
    }

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

    Iterator<LinkedHashMap<String, Object>> schemasIt = schemas.iterator();
    while (schemasIt.hasNext()) {
        LinkedHashMap<String, Object> schemaInfo = schemasIt.next();
        // id?
        Object id = SCIMUtil.getAttribute(schemaInfo, "id");
        if (id != null && id instanceof String) {
            // ??
            boolean isUserSchema = false;
            if (!schemaIdSet.isEmpty()) {
                Iterator<String> schemaIdSetIt = schemaIdSet.iterator();
                while (schemaIdSetIt.hasNext()) {
                    if (id.toString().equalsIgnoreCase(schemaIdSetIt.next())) {
                        isUserSchema = true;
                    }
                }
            }

            if (isUserSchema) {
                Object attributes = schemaInfo.get("attributes");
                if (attributes != null && attributes instanceof ArrayList) {
                    @SuppressWarnings("unchecked")
                    ArrayList<LinkedHashMap<String, Object>> attributeList = (ArrayList<LinkedHashMap<String, Object>>) attributes;
                    Iterator<LinkedHashMap<String, Object>> attributeListIt = attributeList.iterator();
                    while (attributeListIt.hasNext()) {
                        LinkedHashMap<String, Object> attributeInfo = attributeListIt.next();
                        Object name = attributeInfo.get("name");
                        // ??
                        if (attributeName.equalsIgnoreCase(name.toString())) {
                            result = attributeInfo;
                            break;
                        }
                    }
                }
            }
        }
    }

    if (result == null && isCore) {
        if (attributeName.equalsIgnoreCase("schemas")) {
            result = new LinkedHashMap<String, Object>();
            result.put("name", "schemas");
            result.put("type", "string");
            result.put("multiValued", true);
            result.put("mutability", "readWrite");
        } else if (attributeName.equalsIgnoreCase("id")) {
            result = new LinkedHashMap<String, Object>();
            result.put("name", "id");
            result.put("type", "string");
            result.put("multiValued", false);
            result.put("mutability", "readOnly");
        } else if (attributeName.equalsIgnoreCase("meta")) {
            result = new LinkedHashMap<String, Object>();
            result.put("name", "meta");
            result.put("type", "complex");
            result.put("multiValued", false);
            result.put("mutability", "readOnly");
        }
    }

    return result;
}

From source file:net.sf.excelutils.ExcelParser.java

/**
 * get Iterator from the object//from ww  w.ja  v  a 2s  .c  o m
 * 
 * @param collection
 * @return Iterator of the object
 */
public static Iterator getIterator(Object collection) {
    Iterator iterator = null;
    if (collection.getClass().isArray()) {
        try {
            // If we're lucky, it is an array of objects
            // that we can iterate over with no copying
            iterator = Arrays.asList((Object[]) collection).iterator();
        } catch (ClassCastException e) {
            // Rats -- it is an array of primitives
            int length = Array.getLength(collection);
            ArrayList c = new ArrayList(length);
            for (int i = 0; i < length; i++) {
                c.add(Array.get(collection, i));
            }
            iterator = c.iterator();
        }
    } else if (collection instanceof Collection) {
        iterator = ((Collection) collection).iterator();
    } else if (collection instanceof Iterator) {
        iterator = (Iterator) collection;
    } else if (collection instanceof Map) {
        iterator = ((Map) collection).entrySet().iterator();
    }
    return iterator;
}

From source file:com.oinux.lanmitm.util.RequestParser.java

public static ArrayList<BasicClientCookie> getCookiesFromHeaders(ArrayList<String> headers) {
    ArrayList<String> values = getHeaderValues("Cookie", headers);

    if (values != null && values.size() > 0) {
        ArrayList<BasicClientCookie> cookies = new ArrayList<BasicClientCookie>();
        for (String value : values) {
            ArrayList<BasicClientCookie> lineCookies = parseRawCookie(value);
            if (lineCookies != null && lineCookies.size() > 0) {
                cookies.addAll(lineCookies);
            }/*  w  w  w  . j av  a 2s  .c om*/
        }
        Iterator<BasicClientCookie> it = cookies.iterator();
        while (it.hasNext()) {
            BasicClientCookie cookie = (BasicClientCookie) it.next();
            if (cookie.getName().startsWith("__utm") || cookie.getName().equals("__cfduid"))
                it.remove();
        }
        return cookies.size() > 0 ? cookies : new ArrayList<BasicClientCookie>();
    }
    return new ArrayList<BasicClientCookie>();
}

From source file:cn.InstFS.wkr.NetworkMining.UIs.TimeSeriesChart1.java

public static XYDataset createLineDataset(DataItems dataitems1, DataItems dataitems2,
        Map<String, ArrayList<LinePos>> mapAB, XYPlot xyplot) {
    // ????//  w w  w. j a  v  a2s .  c  o  m
    int modelcount = mapAB.keySet().size();
    long off1 = dataitems1.getElementAt(0).getTime().getTime();
    long off2 = dataitems2.getElementAt(0).getTime().getTime();
    long unit = 0;
    if (dataitems1.getLength() > 0) {
        unit = dataitems1.getElementAt(1).getTime().getTime() - off1;
    } else {
        unit = 3600000;
    }

    XYSeriesCollection xyseriescollection = new XYSeriesCollection();
    // ??

    int colorindex = 0;
    int renderercount = 2;
    for (Object se : mapAB.keySet()) {
        ArrayList<LinePos> s = mapAB.get(se);
        int oneModelCount = s.size();

        ArrayList<DataItems> dslist = new ArrayList<DataItems>();
        Iterator it = s.iterator();

        System.out.println("**************");
        System.out.println("?=" + se + ":=" + oneModelCount);

        XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer();
        // ???
        xylineandshaperenderer.setBaseShapesVisible(false);
        // ??
        xylineandshaperenderer.setSeriesLinesVisible(0, true);
        // xylineandshaperenderer.setSeriesShape(0, double1); //?
        // 
        xylineandshaperenderer.setSeriesPaint(0, getcolor(colorindex % 9));
        xylineandshaperenderer.setSeriesFillPaint(0, getcolor(colorindex % 9));
        xylineandshaperenderer.setSeriesOutlinePaint(0, getcolor(colorindex % 9));
        colorindex++;
        xylineandshaperenderer.setUseFillPaint(true);
        xylineandshaperenderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());

        xylineandshaperenderer.setBaseShapesVisible(false);
        xylineandshaperenderer.setSeriesStroke(0,
                new BasicStroke(1.0F, 1, 1, 1.0F, new float[] { 15F, 12F }, 0.0F)); // 
        xylineandshaperenderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
        xylineandshaperenderer.setBaseItemLabelsVisible(false);

        while (it.hasNext()) {
            LinePos temp = (LinePos) it.next();

            DataItem d1 = new DataItem();
            d1 = dataitems1.getElementAt(temp.A_start);
            DataItem d2 = new DataItem();
            d2 = dataitems2.getElementAt(temp.B_start);
            DataItems ds1 = new DataItems();
            ds1.add1Data(d1);
            ds1.add1Data(d2);
            // dslist.add(ds1);
            XYDataset xydataset1 = createmodeDataset(ds1, off1, se.toString() + ":" + 1, unit);

            DataItem d3 = new DataItem();
            d3 = dataitems1.getElementAt(temp.A_end);
            DataItem d4 = new DataItem();
            d4 = dataitems2.getElementAt(temp.B_end);
            DataItems ds2 = new DataItems();
            ds2.add1Data(d3);
            ds2.add1Data(d4);
            // dslist.add(ds2);
            XYDataset xydataset2 = createmodeDataset(ds2, off1, se.toString() + ":" + 2, unit);

            int datasetCount = xyplot.getDatasetCount();
            XYTextAnnotation localXYTextAnnotation = null;
            int modelx = (temp.A_start + temp.B_end) / 2;
            double modely = (Double.parseDouble(dataitems2.getElementAt(temp.A_start).getData())
                    + Double.parseDouble(dataitems1.getElementAt(temp.B_end).getData())) / 2;
            /*System.out.println("se=" + se + "::" + "x=" + modelx + "y="
                  + modely);*/
            localXYTextAnnotation = new XYTextAnnotation("" + se + ":" + oneModelCount, modelx, modely);
            xyplot.addAnnotation(localXYTextAnnotation);
            /*System.out.println("datasetCount=" + datasetCount);*/

            xyplot.setDataset(datasetCount, xydataset1);
            xyplot.setRenderer(datasetCount, xylineandshaperenderer);
            xyplot.setDataset(datasetCount + 1, xydataset2);
            xyplot.setRenderer(datasetCount + 1, xylineandshaperenderer);

        }

    }
    return xyseriescollection;
}

From source file:es.caib.zkib.jxpath.util.ValueUtils.java

/**
 * Returns an iterator for the supplied collection. If the argument
 * is null, returns an empty iterator. If the argument is not
 * a collection, returns an iterator that produces just that one object.
 * @param collection to iterate//from   ww w  .  j a  va2 s . c  o  m
 * @return Iterator
 */
public static Iterator iterate(Object collection) {
    if (collection == null) {
        return Collections.EMPTY_LIST.iterator();
    }
    if (collection.getClass().isArray()) {
        int length = Array.getLength(collection);
        if (length == 0) {
            return Collections.EMPTY_LIST.iterator();
        }
        ArrayList list = new ArrayList();
        for (int i = 0; i < length; i++) {
            list.add(Array.get(collection, i));
        }
        return list.iterator();
    }
    if (collection instanceof Collection) {
        return ((Collection) collection).iterator();
    }
    return Collections.singletonList(collection).iterator();
}

From source file:AlternateDeadlockDetectingLock.java

private static Iterator getAllLocksOwned(Thread t) {
    AlternateDeadlockDetectingLock current;
    ArrayList results = new ArrayList();

    Iterator itr = deadlockLocksRegistry.iterator();
    while (itr.hasNext()) {
        current = (AlternateDeadlockDetectingLock) itr.next();
        if (current.getOwner() == t)
            results.add(current);//from  w w  w.  jav a  2s  .com
    }
    return results.iterator();
}

From source file:it.evilsocket.dsploit.net.http.RequestParser.java

public static ArrayList<BasicClientCookie> getCookiesFromHeaders(ArrayList<String> headers) {
    ArrayList<String> values = getHeaderValues("Cookie", headers);

    if (values != null && values.size() > 0) {
        ArrayList<BasicClientCookie> cookies = new ArrayList<BasicClientCookie>();
        for (String value : values) {
            ArrayList<BasicClientCookie> lineCookies = parseRawCookie(value);
            if (lineCookies != null && lineCookies.size() > 0) {
                cookies.addAll(lineCookies);
            }//from www . j  av  a2 s.c o  m
        }

        // remove google and cloudflare cookies
        Iterator<BasicClientCookie> it = cookies.iterator();
        while (it.hasNext()) {
            BasicClientCookie cookie = (BasicClientCookie) it.next();
            if (cookie.getName().startsWith("__utm") || cookie.getName().equals("__cfduid"))
                it.remove();
        }

        return cookies.size() > 0 ? cookies : null;
    }

    return null;
}

From source file:it.tizianofagni.sparkboost.DataUtils.java

public static <R> void saveHadoopClassificationResults(String outputPath,
        JavaRDD<DocClassificationResults> results) {

    JavaRDD<ClassificationPartialResults> classifications = results.mapPartitionsWithIndex((id, docs) -> {

        int tp = 0, tn = 0, fp = 0, fn = 0;
        StringBuilder sb = new StringBuilder();
        while (docs.hasNext()) {
            DocClassificationResults doc = docs.next();
            int docID = doc.getDocID();
            int[] labels = doc.getLabels();
            int[] goldLabels = doc.getGoldLabels();
            sb.append("DocID: " + docID + ", Labels assigned: " + Arrays.toString(labels) + ", Labels scores: "
                    + Arrays.toString(doc.getScores()) + ", Gold labels: " + Arrays.toString(goldLabels)
                    + "\n");
            tp += doc.getCt().tp();//from   ww w .ja va2s  .  co m
            tn += doc.getCt().tn();
            fp += doc.getCt().fp();
            fn += doc.getCt().fn();
        }
        ContingencyTable ctRes = new ContingencyTable(tp, tn, fp, fn);
        sb.append("**** Effectiveness\n");
        sb.append(ctRes.toString() + "\n");

        ArrayList<ClassificationPartialResults> tables = new ArrayList<ClassificationPartialResults>();
        tables.add(new ClassificationPartialResults(id, sb.toString(), ctRes));
        return tables.iterator();

    }, true).persist(StorageLevel.MEMORY_AND_DISK());

    classifications.saveAsTextFile(outputPath);

    ContingencyTable ctRes = classifications.map(res -> {
        return res.ct;
    }).reduce((ct1, ct2) -> {

        ContingencyTable ct = new ContingencyTable(ct1.tp() + ct2.tp(), ct1.tn() + ct2.tn(),
                ct1.fp() + ct2.fp(), ct1.fn() + ct2.fn());
        return ct;
    });

    DataUtils.saveHadoopTextFile(outputPath + "/global_contingency_table", ctRes.toString());
}

From source file:br.bireme.tb.URLS.java

/**
 * Given a table, generates all of its cells and save each one into a file
 * @param table table used to generate cells
 * @param elem //from  www .ja v a  2s  .  c  om
 * @param root root directory where the files will be created
 * @param urls
 * @param tableNum table number used to create the file name
 */
private static void genCellsFromTable(final Table table, final UrlElem elem, final File root,
        final Set<String> urls, final int tableNum) {
    assert table != null;
    assert elem != null;
    assert root != null;
    assert urls != null;
    assert tableNum >= 0;

    final ArrayList<ArrayList<String>> elems = table.getLines();
    final Iterator<ArrayList<String>> yit = elems.iterator();
    int idx = 1;

    for (String row : table.getRow()) {
        final Iterator<String> xit = yit.next().iterator();
        for (List<String> hdr : table.getHeader()) {
            if (xit.hasNext()) {
                final Cell cell = new Cell();
                cell.setIdx(idx++);
                cell.setElem(elem);
                cell.setHeader(hdr);
                cell.setNotes(table.getNotes());
                cell.setRow(row);
                cell.setScope(table.getScope());
                cell.setSources(table.getSources());
                cell.setSubtitle(table.getSubtitle());
                cell.setTitle(table.getTitle());
                cell.setValue(xit.next());
                cell.setLabels(adjustLabel(cell.getValue(), table.getLabels()));
                final Matcher mat = REFUSE_PAT.matcher(cell.getValue());
                if (!mat.matches()) {
                    try {
                        urls.add(saveToFile(cell, root, tableNum));
                    } catch (IOException ioe) {
                        Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, "Can not save file.",
                                ioe);
                    }
                }
            }
        }
    }
}

From source file:com.draagon.meta.manager.ObjectManager.java

/**
 * Clips the specified objects by the provided range
 *//*from   w  w w .  j  a v a  2 s. c om*/
public static Collection<Object> distinctObjects(Collection<?> objs) throws MetaException {
    // TODO:  Check this, as I don't think it works!

    ArrayList<Object> a = new ArrayList<Object>(objs);
    for (Iterator<Object> i = a.iterator(); i.hasNext();) {
        Object o = i.next();

        // Find the first index of the object
        int fi = a.indexOf(o);

        // Remove all objects of the same value
        int li = 0;
        while ((li = a.lastIndexOf(o)) != fi)
            a.remove(li);
    }

    return a;
}