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):
<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:
public List<Measurement> readMeasurements(String xmlFile) {
List<Measurement> measurements = new ArrayList<Measurement>();
Measurement measurement = null;
Here is piece of code from Stax Parser class:
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.