ArrayList trouble
in
Programming Questions
•
2 years ago
My program reads distances and altitudes from all Garmin files (xml) present in the sketch folder. At the end of
setup()
i have two global ArrayLists. One is called altArrays and one is called distArrays. The are both structured the same, i.e. they are two-dimensional. So, for example, altArrays[0] contains an ArrayList of all of the altitudes for the first xml file in the sketch folder. altArrays[1] contains an ArrayList of all the altitudes for the second xml file, and so on. Here's the code that gets me there:
My question is, now what? :)
My assumption is that if i'm going to use distance for the x-axis and altitude for the y-axis, I'm going to need all of these values to be integers (or double). What is the best way to get them there? My first thought was to simply index through the ArrayLists and somehow convert (perhaps via casting) the values to primitives. I can't seem to get that to work. Second approach was to just try some sort of conversion like:
but it appears the two-dimensions are making this difficult. So I'm now out of ideas.
Thanks for the help.
Lee C
- XMLElement xml;
- float mapX1, mapX2, mapY1, mapY2;
- float w_start, w_end, h_start, h_end;
- int pad = 100; // sizes the window padding around the edgemost points
- ArrayList altArrays = new ArrayList();
- ArrayList distArrays = new ArrayList();
- void setup() {
- size(100, 100);
- File dir = new File("/Users/leecarmichael/Documents/Processing/bikeViz_alt/data");
- String[] files = dir.list();
- println(files.length + " files present.");
- for(int i=0; i<files.length; i++){
- xml = new XMLElement(this, files[i]);
- GarminXML data = new GarminXML(xml);
- altArrays.add(data.getAltitudes());
- }
- for(int i=0; i<files.length; i++){
- xml = new XMLElement(this,files[i]);
- GarminXML data = new GarminXML(xml);
- distArrays.add(data.getDistances());
- }
- }
- void draw(){
My question is, now what? :)
My assumption is that if i'm going to use distance for the x-axis and altitude for the y-axis, I'm going to need all of these values to be integers (or double). What is the best way to get them there? My first thought was to simply index through the ArrayLists and somehow convert (perhaps via casting) the values to primitives. I can't seem to get that to work. Second approach was to just try some sort of conversion like:
- String[] distances = new String[distArray.size()];
- distArray.toArray(distances);
but it appears the two-dimensions are making this difficult. So I'm now out of ideas.
Thanks for the help.
Lee C
1