Example usage for java.util List iterator

List of usage examples for java.util List iterator

Introduction

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

Prototype

Iterator<E> iterator();

Source Link

Document

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

Usage

From source file:com.etime.ETimeUtils.java

/**
 * Get the total hours logged today from a list pf punches. This method does not account for lunch rounding.
 *
 * @param punches A list of punches from a given user for today.
 * @return A double of the total hours logged today.
 *//*from   ww  w.  j  av a  2 s . c  o m*/
protected static double todaysTotalHrsLogged(List<Punch> punches) {
    long runningMilliSecTotal = 0;
    Punch curInPunch;
    Punch curOutPunch;
    Iterator<Punch> iterPunches = punches.iterator();

    while (true) {
        //get next clock in
        if (!iterPunches.hasNext())
            break;

        curInPunch = iterPunches.next();

        //get next clock out
        if (!iterPunches.hasNext()) {
            curOutPunch = new Punch();
            curOutPunch.setCalendar(Calendar.getInstance());
            curOutPunch.setClockIn(false);
            break;
        } else {
            curOutPunch = iterPunches.next();
        }

        runningMilliSecTotal += curOutPunch.getCalendar().getTimeInMillis()
                - curInPunch.getCalendar().getTimeInMillis();
    }

    int hrs = (int) (((runningMilliSecTotal / 1000) / 60) / 60) % 24;
    int minutes = (int) (Math.round((((runningMilliSecTotal / 1000) / 60) % 60) / 15.0) * 15);
    double mins = (minutes) / 60.0;

    return ((double) hrs) + mins;
}

From source file:org.apache.ofbiz.solr.SolrUtil.java

public static SolrInputDocument generateSolrDocument(Map<String, Object> context)
        throws GenericEntityException {
    SolrInputDocument doc1 = new SolrInputDocument();

    // add defined attributes
    for (int i = 0; i < solrProdAttribute.length; i++) {
        if (context.get(solrProdAttribute[i]) != null) {
            doc1.addField(solrProdAttribute[i], context.get(solrProdAttribute[i]).toString());
        }//  w  w  w.  j  a  v a 2  s.  co  m
    }

    // add catalog
    if (context.get("catalog") != null) {
        List<String> catalog = UtilGenerics.<String>checkList(context.get("catalog"));
        for (String c : catalog) {
            doc1.addField("catalog", c);
        }
    }

    // add categories
    if (context.get("category") != null) {
        List<String> category = UtilGenerics.<String>checkList(context.get("category"));
        Iterator<String> catIter = category.iterator();
        while (catIter.hasNext()) {
            String cat = (String) catIter.next();
            doc1.addField("cat", cat);
        }
    }

    // add features
    if (context.get("features") != null) {
        Set<String> features = UtilGenerics.<String>checkSet(context.get("features"));
        Iterator<String> featIter = features.iterator();
        while (featIter.hasNext()) {
            String feat = featIter.next();
            doc1.addField("features", feat);
        }
    }

    // add attributes
    if (context.get("attributes") != null) {
        List<String> attributes = UtilGenerics.<String>checkList(context.get("attributes"));
        Iterator<String> attrIter = attributes.iterator();
        while (attrIter.hasNext()) {
            String attr = attrIter.next();
            doc1.addField("attributes", attr);
        }
    }

    // add title
    if (context.get("title") != null) {
        Map<String, String> title = UtilGenerics.<String, String>checkMap(context.get("title"));
        for (Map.Entry<String, String> entry : title.entrySet()) {
            doc1.addField("title_i18n_" + entry.getKey(), entry.getValue());
        }
    }

    // add short_description
    if (context.get("description") != null) {
        Map<String, String> description = UtilGenerics.<String, String>checkMap(context.get("description"));
        for (Map.Entry<String, String> entry : description.entrySet()) {
            doc1.addField("description_i18n_" + entry.getKey(), entry.getValue());
        }
    }

    // add short_description
    if (context.get("longDescription") != null) {
        Map<String, String> longDescription = UtilGenerics
                .<String, String>checkMap(context.get("longDescription"));
        for (Map.Entry<String, String> entry : longDescription.entrySet()) {
            doc1.addField("longdescription_i18n_" + entry.getKey(), entry.getValue());
        }
    }

    return doc1;
}

From source file:com.qualogy.qafe.business.integration.adapter.Adapter.java

/**
 * Method to adapt an integration service result to one ore more business domain objects. If service result
 * is a list, the list will be recursively adapted. 
 * /*from w ww .ja  v a 2  s  .c  o m*/
 * This 'controlling' method for adapting the output controls in 2 steps:
 *  1. map according to specified service attribute name (regarding the dot notation within the reference key)
 *  2. map according to mapping or type    
 * 
 * The order in which the mapping upon the outcome will be tried is:
 *  1. MappingAdapter when mapping not null,
 *  2. PredefinedMapper when type is a known (for this business project) type
 *  3. BestEffortAdapter will try to adapt Type(business domain) rules to the given object
 *  
 *  Notes:
 *  - Empty mapping leaves a null object
 *  - A null paramname on an outputmapping doesn't leave an entry 
 *   
 * @param id
 * @param serviceOutcome - the object from a service to adapt
 * @param outputMapping - the mapping the object needs to be adapted to
 */
public static void adaptOut(DataIdentifier id, Object serviceOutcome, List outputMapping) {

    if (serviceOutcome instanceof Object[]) {
        serviceOutcome = Arrays.asList((Object[]) serviceOutcome);
    }

    if (outputMapping != null) {
        for (Iterator iter1 = outputMapping.iterator(); iter1.hasNext();) {
            Parameter param = (Parameter) iter1.next();
            if (param.getName() == null)
                continue;
            Object dsResult = null;

            if (serviceOutcome instanceof List) {
                dsResult = prepareList((List) serviceOutcome, param);
            } else {
                dsResult = prepare(serviceOutcome, param);
            }

            if (DataStore.findValue(id, DataStore.KEY_WORD_COUNT) != null) {
                dsResult = ((Map) ((ArrayList) dsResult).get(0)).get("count(*)");
            }

            DataStore.store(id, param.getName(), dsResult);
        }
    }

    retrieveQafeBuiltInList(id, serviceOutcome);

}

From source file:com.silverpeas.jcrutil.BasicDaoFactory.java

/**
 * Remove a reference from an array of javax.jcr.Value. If the reference is not found no change is
 * done to the array./* ww w . j a v a  2 s .  co m*/
 *
 * @param values the array of references
 * @param uuid the reference to be removed
 * @return the updated arry of references.
 * @throws ValueFormatException
 * @throws IllegalStateException
 * @throws RepositoryException
 */
public static Value[] removeReference(Value[] values, String uuid)
        throws ValueFormatException, IllegalStateException, RepositoryException {
    List<Value> references = new ArrayList<Value>(Arrays.asList(values));
    Iterator<Value> iter = references.iterator();
    while (iter.hasNext()) {
        Value value = iter.next();
        if (uuid.equals(value.getString())) {
            iter.remove();
            return references.toArray(new Value[values.length - 1]);
        }
    }
    return values;
}

From source file:edu.northwestern.bioinformatics.studycalendar.osgi.OsgiLayerIntegratedTestHelper.java

public static Bundle findBundle(String bundleName) throws IOException {
    for (Bundle candidate : getBundleContext().getBundles()) {
        if (candidate.getSymbolicName() == null) {
            throw new NullPointerException(
                    String.format("Bundle %s (%s) has no symbolic name", candidate, candidate.getBundleId()));
        }/*w ww.ja  v  a  2s  .c om*/
        if (candidate.getSymbolicName().equals(bundleName)) {
            return candidate;
        }
    }

    List<String> bundles = new ArrayList<String>();
    for (Bundle bundle : getBundleContext().getBundles()) {
        bundles.add(bundle.getSymbolicName());
    }

    throw new StudyCalendarSystemException("No bundle %s in the testing context:\n- %s", bundleName,
            StringUtils.join(bundles.iterator(), ("\n- ")));
}

From source file:com.music.MusicXmlRenderer.java

@SuppressWarnings("unchecked")
public static void render(Score score, OutputStream out) {

    double normalizedMeasureSize = 1d * score.getNumerator() * 4 / score.getDenominator();

    ScorePartwise root = new ScorePartwise();
    root.setMovementTitle(score.getTitle());
    int idx = 1;//from w  w w. j av a 2 s  . com
    for (Part part : score.getPartArray()) {
        ScorePartDefinition def = new ScorePartDefinition();
        def.setPartName(instrumentNames.get(part.getInstrument()));
        def.setId("P" + idx);
        root.getPartDefinitionList().add(def);

        ScorePart xmlPart = new ScorePart();
        xmlPart.setId(def.getId());
        double currentMeasureSize = 0;
        List<Note> partNotes = new ArrayList<Note>();
        for (Phrase phrase : part.getPhraseArray()) {
            partNotes.addAll(phrase.getNoteList());
        }
        Iterator<Note> noteIterator = partNotes.iterator();
        int measureNumber = 1;
        Measure currentMeasure = createMeasure(score, measureNumber++);
        while (noteIterator.hasNext()) {
            Note note = noteIterator.next();
            NoteElement xmlNote = new NoteElement();
            int length = (int) (getClosestLength(note.getRhythmValue()) * 10000);
            switch (length) {
            case (int) (THIRTYSECOND_NOTE * 10000):
                xmlNote.setType("32nd");
                break;
            case (int) (SIXTEENTH_NOTE * 10000):
                xmlNote.setType("16th");
                break;
            case (int) (EIGHTH_NOTE * 10000):
                xmlNote.setType("eighth");
                break;
            case (int) (QUARTER_NOTE * 10000):
                xmlNote.setType("quarter");
                break;
            case (int) (DOTTED_QUARTER_NOTE * 10000):
                xmlNote.setType("quarter");
                xmlNote.setDot("");
                break;
            case (int) (HALF_NOTE * 10000):
                xmlNote.setType("half");
                break;
            case (int) (WHOLE_NOTE * 10000):
                xmlNote.setType("whole");
                break;
            default:
                xmlNote.setType("/" + (length / 10000d));
            }
            xmlNote.setDuration((int) (note.getRhythmValue() * 2));
            xmlNote.setVoice(idx);
            if (!note.isRest()) {
                xmlNote.setPitch(new Pitch());
                int pitch = note.getPitch() % 12;
                String sPitch = NOTES[pitch];
                int octave = note.getPitch() / 12 - 1;
                xmlNote.getPitch().setOctave(octave);
                if (sPitch.length() > 1) {
                    xmlNote.getPitch().setAlter((byte) (sPitch.contains("#") ? 1 : -1));
                    sPitch = sPitch.substring(0, 1);
                }
                xmlNote.getPitch().setStep(sPitch);
            } else {
                xmlNote.setRest(new RestElement());
            }

            currentMeasure.getNotes().add(xmlNote);
            currentMeasureSize += note.getRhythmValue();
            if (currentMeasureSize >= normalizedMeasureSize) {
                currentMeasureSize = 0;
                xmlPart.getMeasures().add(currentMeasure);
                currentMeasure = createMeasure(score, measureNumber++);
            }
        }
        root.getPartList().add(xmlPart);
        idx++;
    }

    try {
        //XMLStreamWriter xmlStreamWriter = xmlOutputFactory.createXMLStreamWriter(out, (String) marshaller.getProperty(Marshaller.JAXB_ENCODING));
        //xmlStreamWriter.writeStartDocument((String) marshaller.getProperty(Marshaller.JAXB_ENCODING), "1.0");
        marshaller.marshal(root, out);
        //xmlStreamWriter.writeEndDocument();
        //xmlStreamWriter.close();
    } catch (Exception ex) {
        throw new IllegalStateException(ex);
    }
}

From source file:bioLockJ.util.MetadataUtil.java

/**
 * Trim all values in row.//from   w  w w  .  j  ava2 s  .c o  m
 * @param row
 * @return
 */
private static List<String> trim(final List<String> row) {
    final List<String> formattedRow = new ArrayList<>();
    final Iterator<String> it = row.iterator();
    while (it.hasNext()) {
        formattedRow.add(it.next().trim());
    }

    return formattedRow;
}

From source file:com.github.rinde.opt.localsearch.Swaps.java

/**
 * Removes all items from list and returns the indices of the removed items.
 * @param list The list to remove items from.
 * @param item The item to remove from the list.
 * @return The indices of the removed items, or an empty list if the item was
 *         not found in list./*from   w ww  .j  a  va  2  s. co  m*/
 */
static <T> IntList removeAll(List<T> list, T item) {
    final Iterator<T> it = list.iterator();
    final IntArrayList indices = new IntArrayList();
    int i = 0;
    while (it.hasNext()) {
        if (it.next().equals(item)) {
            it.remove();
            indices.add(i);
        }
        i++;
    }
    return IntLists.unmodifiable(indices);
}

From source file:es.eucm.eadventure.editor.plugin.vignette.ProxySetup.java

private static Proxy getProxy() {
    List<Proxy> l = null;
    try {/*from   ww w . ja  va2 s . c o m*/
        ProxySelector def = ProxySelector.getDefault();

        l = def.select(new URI("http://foo/bar"));
        ProxySelector.setDefault(null);
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (l != null) {
        for (Iterator<Proxy> iter = l.iterator(); iter.hasNext();) {
            java.net.Proxy proxy = iter.next();
            return proxy;
        }
    }
    return null;
}

From source file:cn.fql.utility.CollectionUtility.java

/**
 * check each element of first list, and compare it to each element of second list.
 * element of list is <code>java.util.Map</code>, get value from map by specified key, if value
 * of element of first list are equals second's, invoke <code>java.util.Map#putAll</code>
 * of element of first list//from   ww  w  . j  a v a  2  s  .c  o  m
 *
 * @param first  first collection
 * @param second second collection
 * @param key    specified key
 * @return first list
 */
public static List joinRecords(List first, List second, String key) {
    if (first != null && second != null) {
        for (int i = 0; i < first.size(); i++) {
            Map record1 = (Map) first.get(i);
            for (Iterator iterator1 = second.iterator(); iterator1.hasNext();) {
                Map record2 = (Map) iterator1.next();
                if (record2.get(key) != null && record2.get(key).equals(record1.get(key))) {
                    record1.putAll(record2);
                    break;
                }
            }
            first.set(i, record1);
        }
    }
    return first;
}