简体   繁体   English

如何在一个文件中写入多个LinkList并将LinkedList读入LinkedList的ArrayList中?

[英]How to write multiple LinkLists in a file and read the LinkedLists into a ArrayList of LinkedList?

I am doing a project in Processing which is based on Java. 我正在处理基于Java的项目。 My project is on Visualizing the retweets for tweets on a give topics (# tags). 我的项目是在可视化给定主题(#标签)上的推文的转发。 I am using twitter4j to interact with Twitter API. 我正在使用twitter4j与Twitter API进行交互。 I always end up exceeding the Twitter API Rate limit (15 queries an hour) which limits my visualization data set. 我总是总是超过Twitter API速率限制(每小时15个查询),该限制限制了我的可视化数据集。

Now I am trying to write a script which runs overnight with some periodic interval to collect the data from twitter. 现在,我正在尝试编写一个脚本,该脚本以一定的周期性间隔运行一整夜,以从Twitter收集数据。 In this way I think I will not cross the rate limit of Twitter API. 这样,我认为我不会越过Twitter API的速率限制。

Something like this . 这样的东西。

My project goes on twitter to search for tweets according to query parameters and for every tweets it finds it collects its retweets and then extract the user location of the tweet and retweet, pass it to Google Maps Geocoding API and gets the latitude and longitude of the tweet's user location and location of all the retweets for this tweet. 我的项目在Twitter上进行搜索,以根据查询参数搜索推文,并发现每条推文都会收集其推文,然后提取该推文和转发的用户位置,并将其传递给Google Maps Geocoding API,并获取该经纬度tweet的用户位置以及此tweet的所有转发的位置。 Basically, the first node of the linked list stores the latitude and longitude of the tweet and following nodes stores the same of retweets. 基本上,链表的第一个节点存储推文的纬度和经度,随后的节点存储推文的纬度和经度。

Tweet -> Retweet 1 -> Retweet2
[22.4655, 34.5678]->[23.2344, 23.4545]->.....

and I have n number of linked list of this kind which I store in an ArrayList . 并且我有n个这样的linked list存储在ArrayList In short I have an ArrayList of LinkedList and the LinkedList 's node is a PVector containing latitude and longitude of a location. 简而言之,我有一个LinkedListArrayList ,而LinkedList的节点是一个包含位置的纬度和经度的PVector

Now to handle the rate limit I want to write a script which does the same thing but writes the data to file which my visualization program can read and visualize on WorldMap. 现在要处理速率限制,我想编写一个脚本,该脚本执行相同的操作,但是将数据写入文件,我的可视化程序可以在WorldMap上读取和可视化该文件。 For this I want to prepare a LinkedList for a tweet with all its retweet's location and then write that linked list to a file then the same for the second tweet in the second line of the file. 为此,我想为一条带有其所有转发位置的推文准备一个LinkedList ,然后将该链接列表写入文件,然后在文件第二行中将其与第二条推文相同。

In my visualization program I want to read the data line by line in linkedlists and store them collectively in an arraylist. 在我的可视化程序中,我想逐行读取链表中的数据并将它们集中存储在arraylist中。 I want keep this kind of structure because my visualization program is based on this. 我想保留这种结构,因为我的可视化程序基于此。

I think this is more than sufficient information on what I am trying to do but with my limited exposure to Processing and Java I am confused about how to do it. 我认为这是关于我要做什么的足够的信息,但是由于我对处理和Java的了解有限,所以我对如何做感到困惑。

To summarize I want to write multiple linkedlist on a file so that one line contains one linked list and then read them line by line in n number of linkedlist and store them collectively in an arraylist. 总而言之,我想在一个文件上写入多个链表,以便一行包含一个链表,然后在n个链表中逐行读取它们,并将它们集中存储在数组列表中。

You can do a simple trick to build a set of Strings to write on a file. 您可以做一个简单的技巧来构建一组要写入文件的字符串。 That is too much straight forward but the solution you are expecting. 这太简单了,但是您所期望的解决方案。 (As you want to read a file line-by-line) (因为要逐行读取文件)
But it will be a too much messy code to read lines and split them. 但是,读取行并拆分它们将是太多的混乱代码。 If you try Serialization (as @pm-77-1 said), you don't have to bother about those stuff. 如果您尝试序列化(如@ pm-77-1所述),则不必担心这些问题。 You can store the whole block at once, read the whole block at once. 您可以一次存储整个块,一次读取整个块。
1st, write a code to serialize your ArrayList using the input file you already have. 1,编写代码以使用已有的输入文件序列化ArrayList Then write a code to de-serialize it and replace your file-reading segment with that. 然后编写代码以对其进行反序列化,并以此替换您的文件读取段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM