Parse varying sized arrays in data structure - Java -


as novice java programmer, i've run rather high hurdle while trying analyze data personal project of mine. have text file ~33.5k data points in following format:

pointnumber:        33530   lat:                8.99167773897820e-001   lon:                6.20173660875318e+000   alt:                0.00000000000000e+000   numberofaccesses:   4   0    4.80784667215499e+003   4.80872732950073e+003   0    1.05264215520092e+004   1.05273043378212e+004   1    1.65167780853593e+004   1.65185840063538e+004   1    6.52228387069902e+004   6.52246514228552e+004   

the final rows, i.e. ones beginning 0 or 1, correspond integer in number of accesses row. parse through file , print lat, lon, , 2 values following each access instance of pointnumbers having more 1 number of accesses.

i'm not sure whether start scanner or tokenizer or compile pattern. technique makes storing valid pointnumbers easier? intuition tells me parse through file, placing relevant values object:

pointnumber num1 = new pointnumber(lat, lon, accesses[]); 

then loop through objects , print object's values if accesses array length > 1. on other hand, better disregard information not meet requirements. done checking numberofaccesses value while parsing jump ahead next string.startswith("pointnumber:") if value <= 1?

i have feeling overwhelming majority of community try steering me towards xml or yaml, prefer trying tackle in java. advice, direction, or applicable examples appreciated.

you can loop through while have input parse

// assuming have scanner object named s , pointed file:  // pointnumber: 33530 int pointnumber = 0; while(!s.next().equals("pointnumber:")) {     pointnumber = s.nextint(); }  // lat: 8.99167773897820e-001 double lat = 0.0; while(!s.next().equals("lat:")) {     lat = s.nextdouble(); }  // lon: 6.20173660875318e+000 double lon = 0.0; while(!s.next().equals("lon:")) {     lon = s.nextdouble(); }  // alt: 0.00000000000000e+000 double alt = 0.0; while(!s.next().equals("alt:")) {     alt = s.nextdouble(); }  // numberofaccesses: 4 int numberofaccesses = 0; while(!s.next().equals("numberofaccesses:")) {     numberofaccesses = s.nextint(); }  // 0 4.80784667215499e+003 4.80872732950073e+003 // 0 1.05264215520092e+004 1.05273043378212e+004 // 1 1.65167780853593e+004 1.65185840063538e+004 // 1 6.52228387069902e+004 6.52246514228552e+004  // assuming have defined access class linkedlist<access> accesses = new linkedlist<access>(); for(int = 0; < numberofaccesses; i++) {     // assuming constructor access class     accesses.add(new access(s.nextint(), s.nextdouble(), s.nextdouble())); } 

then can add data want list of "pointnumber" , print or whatever it.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -