Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Ignavis

Pages: [1]
1
General discussion / Re: Forum portal
« on: May 22, 2014, 02:05:47 pm »
I am really enjoy it! Using everyday.

2
Java / Stax Parser / arraylist
« on: January 13, 2014, 08:46:49 pm »
I used arraylist and Stax parser to extract data from XML file.
This is how each row looks in my XML file (each row contains different data):

Code: [Select]
    <row>
      <millis>1000</millis>
      <stamp> 1273010254</stamp>
      <datetime> 2010/5/4 21:57:34</datetime>
      <light> 333</light>
      <temp> 78.32</temp>
      <vcc> 3.54</vcc>
    </row>

Here is a ArrayList I am using:

Code: [Select]
    public List<Measurement> readMeasurements(String xmlFile) {
           
            List<Measurement> measurements = new ArrayList<Measurement>();
            Measurement measurement = null;

Here is piece of code from Stax Parser class:

Code: [Select]
    if (xmlEvent.isStartElement()){
                        StartElement startElement = xmlEvent.asStartElement();
                        if(startElement.getName().getLocalPart().equals("row")){
                            measurement = new Measurement();
                        }
                        else if(startElement.getName().getLocalPart().equals("millis")){
                            xmlEvent = xmlEventReader.nextEvent();
                            measurement.setMillis(xmlEvent.asCharacters().getData());

and so on...

Still new in programming so my question is: How to calculate (find mean/average) of "light" or "millis" elements from mine arraylist and display it in a textbox. Don't need to be displayed at textbox but will be easier for me, because I will presenting data from textbox using Jfreechart.
I did some research and I read that IndexOf may be helpful since I am using equal in my code, but I am not sure how to manipulate specific element of my arraylist.

Pages: [1]