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:net.commerce.zocalo.freechart.ChartGenerator.java

static public TimePeriodValuesCollection getHistoricalVolumes(String claimName, List trades) {
    TimePeriodValues values = new TimePeriodValues(claimName);
    for (Iterator iterator = trades.iterator(); iterator.hasNext();) {
        Trade trade = (Trade) iterator.next();
        TimePeriodValue volume = trade.timeAndVolume();
        if (volume != null) {
            values.add(volume);/*  w  w w . ja va2s.  co  m*/
        }
    }
    return new TimePeriodValuesCollection(values);
}

From source file:com.streamsets.pipeline.kafka.impl.KafkaValidationUtil08.java

private static TopicMetadata getTopicMetadata(List<HostAndPort> kafkaBrokers, String topic, int maxRetries,
        long backOffms) throws IOException {
    TopicMetadata topicMetadata = null;// w  ww .  j  a  v a 2  s . co m
    boolean connectionError = true;
    boolean retry = true;
    int retryCount = 0;
    while (retry && retryCount <= maxRetries) {
        for (HostAndPort broker : kafkaBrokers) {
            SimpleConsumer simpleConsumer = null;
            try {
                simpleConsumer = new SimpleConsumer(broker.getHostText(), broker.getPort(),
                        METADATA_READER_TIME_OUT, BUFFER_SIZE, METADATA_READER_CLIENT);

                List<String> topics = Collections.singletonList(topic);
                TopicMetadataRequest req = new TopicMetadataRequest(topics);
                kafka.javaapi.TopicMetadataResponse resp = simpleConsumer.send(req);

                // No exception => no connection error
                connectionError = false;

                List<TopicMetadata> topicMetadataList = resp.topicsMetadata();
                if (topicMetadataList == null || topicMetadataList.isEmpty()) {
                    //This broker did not have any metadata. May not be in sync?
                    continue;
                }
                topicMetadata = topicMetadataList.iterator().next();
                if (topicMetadata != null && topicMetadata.errorCode() == 0) {
                    retry = false;
                }
            } catch (Exception e) {
                //could not connect to this broker, try others
            } finally {
                if (simpleConsumer != null) {
                    simpleConsumer.close();
                }
            }
        }
        if (retry) {
            LOG.warn(
                    "Unable to connect or cannot fetch topic metadata. Waiting for '{}' seconds before retrying",
                    backOffms / 1000);
            retryCount++;
            if (!ThreadUtil.sleep(backOffms)) {
                break;
            }
        }
    }
    if (connectionError) {
        //could not connect any broker even after retries. Fail with exception
        throw new IOException(Utils.format(KafkaErrors.KAFKA_67.getMessage(), getKafkaBrokers(kafkaBrokers)));
    }
    return topicMetadata;
}

From source file:net.sf.jsignpdf.Signer.java

/**
 * Writes info about security providers to the {@link Logger} instance. The
 * log-level for messages is TRACE./*from  w w  w.j  a v  a2 s  .  c o m*/
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
private static void traceInfo() {
    if (LOGGER.isTraceEnabled()) {
        try {
            Provider[] aProvider = Security.getProviders();
            for (int i = 0; i < aProvider.length; i++) {
                Provider provider = aProvider[i];
                LOGGER.trace(
                        "Provider " + (i + 1) + " : " + provider.getName() + " " + provider.getInfo() + " :");
                List keyList = new ArrayList(provider.keySet());
                try {
                    Collections.sort(keyList);
                } catch (Exception e) {
                    LOGGER.trace("Provider's properties keys can't be sorted", e);
                }
                Iterator keyIterator = keyList.iterator();
                while (keyIterator.hasNext()) {
                    String key = (String) keyIterator.next();
                    LOGGER.trace(key + ": " + provider.getProperty(key));
                }
                LOGGER.trace("------------------------------------------------");
            }
        } catch (Exception e) {
            LOGGER.trace("Listing security providers failed", e);
        }
    }
}

From source file:com.glaf.core.util.QuartzUtils.java

/**
 * ??Quartz/*from   ww  w. j av a 2  s.  c  o  m*/
 */
public static void stopAll() {
    List<Scheduler> list = getSysSchedulerService().getAllSchedulers();
    Iterator<Scheduler> iterator = list.iterator();
    while (iterator.hasNext()) {
        Scheduler model = iterator.next();
        try {
            stop(model.getId());
        } catch (Exception ex) {
            ex.printStackTrace();
            logger.error(ex);
        }
    }
}

From source file:net.majorkernelpanic.streaming.misc.UriParser.java

/**
 * Configures a Session according to the given URI.
 * Here are some examples of URIs that can be used to configure a Session:
 * <ul><li>rtsp://xxx.xxx.xxx.xxx:8086?h264&flash=on</li>
 * <li>rtsp://xxx.xxx.xxx.xxx:8086?h263&camera=front&flash=on</li>
 * <li>rtsp://xxx.xxx.xxx.xxx:8086?h264=200-20-320-240</li>
 * <li>rtsp://xxx.xxx.xxx.xxx:8086?aac</li></ul>
 * @param uri The URI//from w  ww.j  ava  2  s .  c om
 * @param session The Session that will be configured
 * @throws IllegalStateException
 * @throws IOException
 */
public static void parse(String uri, Session session) throws IllegalStateException, IOException {
    boolean flash = false;
    int camera = CameraInfo.CAMERA_FACING_BACK;

    List<NameValuePair> params = URLEncodedUtils.parse(URI.create(uri), "UTF-8");
    if (params.size() > 0) {

        // Those parameters must be parsed first or else they won't necessarily be taken into account
        for (Iterator<NameValuePair> it = params.iterator(); it.hasNext();) {
            NameValuePair param = it.next();

            // FLASH ON/OFF
            if (param.getName().equals("flash")) {
                if (param.getValue().equals("on"))
                    flash = true;
                else
                    flash = false;
            }

            // CAMERA -> the client can choose between the front facing camera and the back facing camera
            else if (param.getName().equals("camera")) {
                if (param.getValue().equals("back"))
                    camera = CameraInfo.CAMERA_FACING_BACK;
                else if (param.getValue().equals("front"))
                    camera = CameraInfo.CAMERA_FACING_FRONT;
            }

            // MULTICAST -> the stream will be sent to a multicast group
            // The default mutlicast address is 228.5.6.7, but the client can specify one 
            else if (param.getName().equals("multicast")) {
                session.setRoutingScheme(Session.MULTICAST);
                if (param.getValue() != null) {
                    try {
                        InetAddress addr = InetAddress.getByName(param.getValue());
                        if (!addr.isMulticastAddress()) {
                            throw new IllegalStateException("Invalid multicast address !");
                        }
                        session.setDestination(addr);
                    } catch (UnknownHostException e) {
                        throw new IllegalStateException("Invalid multicast address !");
                    }
                } else {
                    // Default multicast address
                    session.setDestination(InetAddress.getByName("228.5.6.7"));
                }
            }

            // UNICAST -> the client can use this so specify where he wants the stream to be sent
            else if (param.getName().equals("unicast")) {
                if (param.getValue() != null) {
                    try {
                        InetAddress addr = InetAddress.getByName(param.getValue());
                        session.setDestination(addr);
                    } catch (UnknownHostException e) {
                        throw new IllegalStateException("Invalid destination address !");
                    }
                }
            }

            // TTL -> the client can modify the time to live of packets
            // By default ttl=64
            else if (param.getName().equals("ttl")) {
                if (param.getValue() != null) {
                    try {
                        int ttl = Integer.parseInt(param.getValue());
                        if (ttl < 0)
                            throw new IllegalStateException("The TTL must be a positive integer !");
                        session.setTimeToLive(ttl);
                    } catch (Exception e) {
                        throw new IllegalStateException("The TTL must be a positive integer !");
                    }
                }
            }

            // No tracks will be added to the session
            else if (param.getName().equals("stop")) {
                return;
            }

        }

        for (Iterator<NameValuePair> it = params.iterator(); it.hasNext();) {
            NameValuePair param = it.next();

            // H264
            if (param.getName().equals("h264")) {
                VideoQuality quality = VideoQuality.parseQuality(param.getValue());
                session.addVideoTrack(Session.VIDEO_H264, camera, quality, flash);
            }

            // H263
            else if (param.getName().equals("h263")) {
                VideoQuality quality = VideoQuality.parseQuality(param.getValue());
                session.addVideoTrack(Session.VIDEO_H263, camera, quality, flash);
            }

            // AMRNB
            else if (param.getName().equals("amrnb") || param.getName().equals("amr")) {
                session.addAudioTrack(Session.AUDIO_AMRNB);
            }

            // AAC
            else if (param.getName().equals("aac")) {
                session.addAudioTrack(Session.AUDIO_AAC);
            }

            // Generic Audio Stream -> make use of api level 12
            // TODO: Doesn't work :/
            else if (param.getName().equals("testnewapi")) {
                session.addAudioTrack(Session.AUDIO_ANDROID_AMR);
            }

        }

        // The default behavior is to only add one video track
        if (session.getTrackCount() == 0) {
            session.addVideoTrack();
            session.addAudioTrack();
        }

    }
    // Uri has no parameters: the default behavior is to only add one video track
    else {
        session.addVideoTrack();
        session.addAudioTrack();
    }
}

From source file:net.commerce.zocalo.freechart.ChartGenerator.java

static public TimePeriodValuesCollection getHistoricalPrices(String claimName, List trades) {
    TimePeriodValues values = new TimePeriodValues(claimName);
    for (Iterator iterator = trades.iterator(); iterator.hasNext();) {
        Trade trade = (Trade) iterator.next();
        if (!trade.getQuantity().isZero()) {
            if (trade.getPos().isInvertedPosition()) {
                values.add(trade.timeAndPriceInverted());
            } else {
                values.add(trade.timeAndPrice());
            }//from w w w . j  a  v  a  2 s  . com
        }
    }
    return new TimePeriodValuesCollection(values);
}

From source file:gov.nist.healthcare.ttt.parsing.Parsing.java

public static boolean isRegistryResponseSuccessFullHeaders(String mtom) throws IOException {
    String soapEnv = Parsing.findSoapOfRegistryResponse(mtom);
    Envelope env = (Envelope) JAXB.unmarshal(new StringReader(soapEnv), Envelope.class);

    List<Object> body = env.getBody().getAny();
    Iterator it = body.iterator();
    if (it.hasNext()) {
        Element next = (Element) it.next();
        String regRep = MiscUtil.xmlToString(next);
        return Parsing.isRegistryResponseSuccess(regRep);
    } else {/*from ww w . ja  v  a 2 s  . c om*/
        return false;
    }

}

From source file:KMeansNDimension.java

/**
 * Initialize the centroids with the first k points of the datasets
 * @param points Dataset/*from   w w w  . jav  a2s .  c o  m*/
 * @param k number of clusters to generate
 * @param env ExecutionEnvironment
 * @return DataSet<Centroid> centroids
 */
private static DataSet<Centroid> getCentroidDataSet(DataSet<DenseVector> points, int k,
        ExecutionEnvironment env) {
    DataSet<Centroid> dtDataSet = null;

    List<Centroid> centroids = new ArrayList<Centroid>();

    try {
        List<DenseVector> gro = points.first(k).collect();
        Iterator<DenseVector> iter = gro.iterator();

        int c = 1;

        while (iter.hasNext()) {
            centroids.add(new Centroid(c, iter.next()));
            c++;
        }
        dtDataSet = env.fromCollection(centroids);

    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return dtDataSet;
}

From source file:bridge.toolkit.commands.PreProcess.java

/**
 * Adds ICN references from referenced data modules to the list of files
 * to be used as dependencies in the resources section.  
 * //from ww  w .j  a v a 2  s  .  co m
 * @param dependencies - List of Strings that will be used as "Dependency" elements for "SCO" resources.
 * @param dmDoc - Document object that represents the data module file being used. 
 * @throws JDOMException
 */
private static List<String> addICNDependencies(List<String> dependencies, Document dmDoc) throws JDOMException {
    // reach into the dm docs and find ICN references
    List<String> icnRefs = searchForICN(dmDoc);

    Iterator<String> icn_iter = icnRefs.iterator();
    while (icn_iter.hasNext()) {
        String the_icn = icn_iter.next();
        if (!dependencies.contains(the_icn)) {
            dependencies.add(the_icn);
        }
    }

    return dependencies;
}