解析数据结构中不同大小的数组 - Java
作为一名新手 Java 程序员,我在尝试分析个人项目的数据时遇到了相当高的障碍。我有一条文字 该文件包含大约 33.5k 数据点,格式如下:
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
最后几行(即以 0 或 1 开头的行)对应于“访问次数”行中的整数。我想通过解析 文件并打印纬度、经度以及仅具有超过 1 次访问的 PointNumbers 的每个访问实例之后的两个值。
我不确定是从扫描仪或分词器开始还是编译模式。哪种技术可以更轻松地仅存储有效的 PointNumber? 直觉告诉我解析文件,将相关值放入对象中:
PointNumber num1 = new PointNumber(lat, lon, accesses[]);
然后循环遍历对象并在访问数组长度>时打印对象的值。 1. 另一方面,对于不符合要求的信息,最好忽略。是否可以通过在解析时检查 NumberOfAccesses 值然后如果该值 <= 1 则跳转到下一个 string.startsWith("PointNumber:") 来完成?
我有一种感觉,这个社区的绝大多数人都会尝试引导我转向 XML 或 YAML,但我真的更喜欢尝试 在 Java 中解决这个问题。任何建议、方向或适用的例子总是非常感激。
As a novice Java programmer, I've run into a rather high hurdle while trying to analyze data for a personal project of mine. I have a text
file with ~33.5k data points in the 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 with 0 or 1, correspond to the integer in the Number of Accesses row. I would like to parse through the
file and print the Lat, Lon, and two values following each access instance of only PointNumbers having more than 1 number of accesses.
I'm not sure whether to start with a scanner or tokenizer or to compile a pattern. Which technique makes storing only valid PointNumbers easier?
Intuition tells me to parse through the file, placing relevant values into an object:
PointNumber num1 = new PointNumber(lat, lon, accesses[]);
Then loop through the objects and print the object's values if the accesses array length is > 1. On the other hand, it would be better to disregard the information that does not meet the requirements. Could this be done by checking the NumberOfAccesses value while parsing then jump ahead to the next string.startsWith("PointNumber:") if the value is <= 1?
I have a feeling the overwhelming majority of this community will try steering me towards XML or YAML, but I really prefer trying to
tackle this in Java. Any advice, direction, or applicable examples is always greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您有要解析的输入时,您可以循环执行此操作
然后您可以将您实际想要的所有数据添加到“PointNumber”列表中,然后打印或从中执行任何操作。
You can loop through this while you have input to parse
Then you can add all the data you actually want into a list of "PointNumber" and then print or do whatever from it.