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:Utils.java

/**
 * Create a typesafe copy of a raw list.
 * @param rawList an unchecked list/*  w  ww . j a v a 2  s  . co  m*/
 * @param type the desired supertype of the entries
 * @param strict true to throw a <code>ClassCastException</code> if the raw list has an invalid entry,
 *               false to skip over such entries (warnings may be logged)
 * @return a typed list guaranteed to contain only entries assignable
 *         to the named type (or they may be null)
 * @throws ClassCastException if some entry in the raw list was not well-typed, and only if <code>strict</code> was true
 */
public static <E> List<E> checkedListByCopy(List rawList, Class<E> type, boolean strict)
        throws ClassCastException {
    List<E> l = (rawList instanceof RandomAccess) ? new ArrayList<E>(rawList.size()) : new LinkedList<E>();
    Iterator it = rawList.iterator();
    while (it.hasNext()) {
        Object e = it.next();
        try {
            l.add(type.cast(e));
        } catch (ClassCastException x) {
            if (strict) {
                throw x;
            } else {
                System.out.println("not assignable ");
            }
        }
    }
    return l;
}

From source file:com.aurel.track.persist.TBLOBPeer.java

public static List<TBLOBBean> convertTorqueListToBeanList(List<TBLOB> torqueList) {
    List<TBLOBBean> beanList = new LinkedList<TBLOBBean>();
    TBLOB tblob;/*from  www.ja  va  2 s.  co m*/
    if (torqueList != null) {
        Iterator<TBLOB> itrTorqueList = torqueList.iterator();
        while (itrTorqueList.hasNext()) {
            tblob = itrTorqueList.next();
            beanList.add(tblob.getBean());
        }
    }
    return beanList;
}

From source file:edu.kit.cockpit.valuationserver.rest.clients.DeliberationPlatformClient.java

/**
 * First make sure that the poll is deployed, then replace it with an update
 * /*  w  w  w.j  av a 2 s  .c  om*/
 * @param isVisible
 *            determines visibility of the new poll on the DP
 * @param newEval
 *            evaluation entity containing the update
 * @return success status
 * @throws DPInteractionException
 */
public static void updateEvaluationPoll(boolean isVisible, EvaluationE newEval) throws DPInteractionException {
    // GET poll list for associated service from DP
    // return false if that fails
    ArrayOfPoll polls = getPolls(newEval.getServiceId());
    if (polls == null)
        throw new DPInteractionException("Reading poll list from DP failed");
    // retrieve specific poll
    // return false if not found
    PollType currentPoll = null;
    List<PollType> pollTypeList = polls.getPoll();
    for (Iterator<PollType> iterator = pollTypeList.iterator(); iterator.hasNext();) {
        PollType pollType = (PollType) iterator.next();
        if (pollType.getPollId().equals(newEval.getPollId()))
            currentPoll = pollType;
    }
    if (currentPoll == null)
        throw new DPInteractionException("Inconsistent state detected: aborted poll not deployed on DP");
    // create new poll
    // return false if erroneous
    PollType updatedPoll;
    try {
        updatedPoll = PollGenerator.createPoll(newEval, isVisible);
        if (updatedPoll == null)
            throw new DPInteractionException("Problem during poll generation");
    } catch (DatatypeConfigurationException e) {
        throw new DPInteractionException("Problem during poll generation", e);
    }
    // try to PUT updated poll to DP
    putPoll(updatedPoll);
    // if we made it up to here all is fine
}

From source file:com.amalto.workbench.utils.MDMServerHelper.java

private static Element getServerElement(Element rootElement, String matchingName) {
    List<?> properties = rootElement.elements(MDMServerHelper.PROPERTIES);
    for (Iterator<?> iterator = properties.iterator(); iterator.hasNext();) {
        Element serverElement = (Element) iterator.next();
        Element nameElement = serverElement.element(MDMServerHelper.NAME);
        if (nameElement != null) {
            String name = nameElement.getText();
            if (matchingName.equals(name)) {
                return serverElement;
            }//  w w w . j a v  a2  s  .c  o  m
        }
    }
    return null;
}

From source file:nl.frankkie.bronylivewallpaper.CLog.java

/**
 * Print all parameter of List<NameValuePair>
 * @param pairs the pairs to be printed/*from ww w. j  av  a 2  s.  c o  m*/
 */
public static void printNameValuePairs(List<NameValuePair> pairs) {
    if (!shouldLog) {
        return;
    }
    Iterator i = pairs.iterator();
    while (i.hasNext()) {
        NameValuePair p = (NameValuePair) i.next();
        v(p.getName() + ":" + p.getValue());
    }
}

From source file:de.upb.timok.ProgressEstimator.java

public static long average(final List<Long> jobDurations2) {
    long sum = 0;
    int size = 0;
    synchronized (jobDurations2) {
        size = jobDurations2.size();/*  w w  w  .j a  v  a2 s  .  co  m*/
        final Iterator<Long> i = jobDurations2.iterator();
        while (i.hasNext()) {
            sum += i.next();
        }
    }
    if (size == 0) {
        return Long.MIN_VALUE;
    }
    return sum / size;
}

From source file:it.geosolutions.geoserver.jms.impl.utils.BeanUtils.java

/**
 * This is a 'smart' (perform checks for some special cases) update function which should be used to copy of the properties for objects
 * of the catalog and configuration./*www. j a  v  a 2  s  .c o  m*/
 * 
 * @param <T> the type of the bean to update
 * @param info the bean instance to update
 * @param properties the list of string of properties to update
 * @param values the list of new values to update
 * 
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 * @throws NoSuchMethodException
 */
public static <T> void smartUpdate(final T info, final List<String> properties, final List<Object> values)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    final Iterator<String> itPropertyName = properties.iterator();
    final Iterator<Object> itValue = values.iterator();
    while (itPropertyName.hasNext() && itValue.hasNext()) {
        String propertyName = itPropertyName.next();
        final Object value = itValue.next();

        PropertyDescriptor pd = PropertyUtils.getPropertyDescriptor(info, propertyName);
        // return null if there is no such descriptor
        if (pd == null) {
            // this is a special case used by the NamespaceInfoImpl setURI
            // the propertyName coming from the ModificationProxy is set to 'uRI'
            // lets set it to uri
            propertyName = propertyName.toUpperCase();
            pd = PropertyUtils.getPropertyDescriptor(info, propertyName);
            if (pd == null) {
                return;
            }
        }
        if (pd.getWriteMethod() != null) {
            PropertyUtils.setProperty(info, propertyName, value);
        } else {
            // T interface do not declare setter method for this property
            // lets use getter methods to get the property reference
            final Object property = PropertyUtils.getProperty(info, propertyName);

            // check type of property to apply new value
            if (Collection.class.isAssignableFrom(pd.getPropertyType())) {
                final Collection<?> liveCollection = (Collection<?>) property;
                liveCollection.clear();
                liveCollection.addAll((Collection) value);
            } else if (Map.class.isAssignableFrom(pd.getPropertyType())) {
                final Map<?, ?> liveMap = (Map<?, ?>) property;
                liveMap.clear();
                liveMap.putAll((Map) value);
            } else {
                if (CatalogUtils.LOGGER.isLoggable(java.util.logging.Level.SEVERE))
                    CatalogUtils.LOGGER.severe("Skipping unwritable property " + propertyName
                            + " with property type " + pd.getPropertyType());
            }
        }
    }
}

From source file:Main.java

/**
 * Converts two {@link List} to a map. The order is important here because
 * each key will map to one value./*from   w w  w  .j a v  a2s. c om*/
 */
public static <T, K> Map<T, K> newMapFromLists(List<T> keys, List<K> values) {
    // throw if there's invalid input..
    if (keys.size() != values.size()) {
        throw new IllegalArgumentException();
    }
    Map<T, K> map = new HashMap<>(keys.size());
    Iterator<T> keyIter = keys.iterator();
    Iterator<K> valueIter = values.iterator();
    while (keyIter.hasNext() && valueIter.hasNext()) {
        T key = keyIter.next();
        K value = valueIter.next();
        map.put(key, value);
    }
    return map;
}

From source file:com.impetus.kvapps.runner.ExecutorService.java

/**
 *  On print tweets event.//from ww  w  . j  ava 2s . c o  m
 *  
 * @param tweets
 */
private static void onPrintTweets(final List<Tweets> tweets) {
    for (Iterator<Tweets> iterator = tweets.iterator(); iterator.hasNext();) {

        int counter = 1;
        while (iterator.hasNext()) {
            logger.info("\n");
            logger.info("\t\t Tweet No:#" + counter++);
            Tweets rec = (Tweets) iterator.next();
            logger.info("\t\t tweet is ->" + rec.getBody());
            logger.info("\t\t Tweeted at ->" + rec.getTweetDate());

            if (rec.getVideos() != null) {
                logger.info("\t\t Tweeted Contains Video ->" + rec.getVideos().size());

                for (Iterator<Video> iteratorVideo = rec.getVideos().iterator(); iteratorVideo.hasNext();) {
                    Video video = (Video) iteratorVideo.next();
                    logger.info(video);
                }
            }

        }
    }

}

From source file:de.tudarmstadt.ukp.experiments.argumentation.sequence.evaluation.helpers.FinalTableExtractor.java

public static void extractCVResults(String inFile, String outFile) throws IOException {
    File file = new File(inFile);

    Table<String, String, String> table = TreeBasedTable.create();

    List<String> lines = IOUtils.readLines(new FileInputStream(file));
    Iterator<String> iterator = lines.iterator();
    while (iterator.hasNext()) {
        String featureSet = iterator.next();

        featureSet = featureSet.replaceAll("^\\./", "");

        System.out.println(featureSet);
        // shorten fs name
        featureSet = featureSet.replaceAll("/.*", "");

        String[] fsSettings = featureSet.split("_", 6);
        String clusters = fsSettings[4];

        if (includeRow(clusters)) {
            table.put(featureSet, "FS", fsSettings[1]);
            table.put(featureSet, "Clusters", clusters);
        }//ww  w. j a  va  2s  .c o  m

        // 12 lines with results
        for (int i = 0; i < 12; i++) {
            String line = iterator.next();
            String[] split = line.split("\\s+");
            String measure = split[0];
            Double value = Double.valueOf(split[1]);

            if (includeRow(clusters)) {
                table.put(featureSet, "Clusters", clusters);
                if (includeColumn(measure)) {
                    table.put(featureSet, measure, String.format(Locale.ENGLISH, "%.3f", value));
                }
            }
        }
    }

    //        tableToCsv(table, new FileWriter(outFile));
}