Welcome to Dream.In.Code
Become a Java Expert!

Join 150,369 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,842 people online right now. Registration is fast and FREE... Join Now!




for loop confusion

 
Reply to this topicStart new topic

for loop confusion, How does a : operator perform in a for loop

razi
8 Feb, 2008 - 02:24 AM
Post #1

New D.I.C Head
*

Joined: 8 Feb, 2008
Posts: 5


My Contributions
Hi all,

I am trying to figure out wat this bit of code is doing??
CODE

public void run() {

        PollDataList pdl;
        PollDeviceConfig pdc = null;

        if (mdl instanceof PollDataList) {
            pdl = (PollDataList) mdl;
            pdc = pdl.getPollDeviceConfig();
        }
        MonitorDataList mdl_last = pdc.getLastPollData();
        dpp = pdc.getDevicePollProperties();
        double max = 0;
        double min = 0;
        double totalresponse = 0;
        int totalttl = 0;
        double packetlosspercent = 0;
        double avg = 0;
         int count = 0;
        int successcount = 0;
        for (MonitorData md : mdl) {
            PollData pd = (PollData) md;
            if (Resources.getServer().getOS().equalsIgnoreCase("linux")) {
                try {
                     PingData response = (PingData) pd.get("ping");
                    if (response.getMin() != null) {
                        min = getInteger(response.getMin());
                    }
                    if (response.getMax() != null) {
                        max = getInteger(response.getMax());
                    }
                    if (response.getAvg() != null) {
                        avg = getInteger(response.getAvg());
                    }
                    if (response.getPacketloss() != null) {
                        packetlosspercent = getInteger(response.getPacketloss());
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }


I cant understand wat the statement for (MonitorData md : mdl) do actually?

User is offlineProfile CardPM
+Quote Post

chuck87
RE: For Loop Confusion
8 Feb, 2008 - 04:06 AM
Post #2

D.I.C Head
**

Joined: 7 Sep, 2007
Posts: 65


My Contributions
check this I believe it will help

This post has been edited by chuck87: 8 Feb, 2008 - 04:06 AM
User is offlineProfile CardPM
+Quote Post

razi
RE: For Loop Confusion
8 Feb, 2008 - 05:15 AM
Post #3

New D.I.C Head
*

Joined: 8 Feb, 2008
Posts: 5


My Contributions
QUOTE(chuck87 @ 8 Feb, 2008 - 05:06 AM) *

check this I believe it will help


thanx 4 the quick reply but i still cant understand completely

wat i understand is dat mdl is and instance of MonitorDataList class. Its not an array rite?

this is my code 4 the MonitorDataList class

CODE

package com.infrascape.mdae.data;

import com.infrascape.mdae.datamodel.DataModel;
import com.infrascape.mdae.datamodel.MonitorDefinition;
import com.infrascape.mdae.datamodel.MonitorTable;
import com.infrascape.mdae.datamodel.PollDefinition;
import com.infrascape.mdae.datamodel.PollDeviceConfig;
import java.util.Calendar;
import java.util.LinkedList;
/**
*
* @author Raziuddin Ahmed
*/
public class MonitorDataList extends LinkedList<MonitorData> {
  
  /**
   * Creates a new instance of MonitorDataList
   */
  
  public MonitorDataList(){
    
  }
  public MonitorDataList(int device_id){
    
    
    this.device_id = device_id;
    timestamp = Calendar.getInstance();
    timestamp.setTimeInMillis(System.currentTimeMillis());
    //System.out.println("Monitor_Id: "+monitor_id+" Device Id: "+device_id+" Timestamp: "+timestamp.getTime());
    dm = DataModel.getInstance();
  }


User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 02:19PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month