实施排序的“观察列表” java中的类:使用什么工具?

发布于 2024-12-27 15:43:46 字数 374 浏览 1 评论 0原文

我需要实现 WatchList 类作为 Java 客户端-服务器应用程序的一部分。 WL 本质上是一个 Items 数组,每个 Items 都有一个时间戳。我负责应用程序的客户端。 WL 可以在客户端手动更新,即可以向其添加新元素。还可以通过服务器定期更新来修改它。同样,定期上传也会将手动添加的术语发送到服务器。

由于我对 Java 相当陌生,我需要关于应该使用哪些内置工具(类)来实现此 WL 类的建议。它显然是某种带有自定义比较器的排序结构,会比较日期。我可能还想以最新项目优先的顺序维护它,以便我可以快速检索最新项目以发送到服务器。在这种情况下,从服务器下载期间接收的项目将被添加到列表的开头而不是末尾。或者将其保持为最新项目最后的顺序也同样有效?

非常感谢!

I need to implement a WatchList class as a part of a Java client-server app. WL is essentially an array of Items, each of which has a timestamp. I am responsible for for the client side of the app. The WL might be updated on the client side manually, i.e. new elements can be added to it. It can also be modified with a regularly schedule update from the server. Similarly, regular uploads are also performed with the terms that had been added manually being sent to the server.

Since I am fairly new to Java, I need advice on what built-in instruments (classes) I should use to implement this WL class. It will obviously be some type of sorted structure with a custom comparator that would compare dates. I will probably also want to maintain it in a newest-items-first order so that I could quickly retrieve the newest items to send to the server. In which case the item that will be received during a download from the server will be added to the beginning of the list rather than at the end. Or keeping it in the newest-items-last order is just as efficient?

Thanks much!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心安伴我暖 2025-01-03 15:43:46

最新的在前或最新的在后,这纯粹是功能性的选择。一个比较器只是另一个比较器的逆。

您需要了解集合框架的类。

我不会在客户端保留未保存的时间表。如果客户端崩溃,您将丢失所有未保存的项目。为什么不在客户端每次创建项目时简单地调用服务器呢?

Newest first or newest last, it's a purely functional choice. The comparator of one is just the inverse of the comparator of the other.

You'll need to understand the classes of the collections framework.

I wouldn't keep unsaved schedules at client side. If the client crashes, you lose all the unsaved items. Why don't you simply call the server each time an item is created at client-side?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文