如何在黑莓应用程序中对持久存储记录进行排序?

发布于 2024-08-18 10:47:37 字数 56 浏览 1 评论 0原文

您能帮我在 Blackberry 应用程序中对持久存储记录进行排序吗? 我想按升序和降序排序...

Can you please help me in sorting persistent store records in Blackberry application?
I want to sort it in ascending and descending order...

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

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

发布评论

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

评论(2

雨落星ぅ辰 2024-08-25 10:47:37

要在黑莓中排序,您可以使用 SimpleSortingVector
但坏消息是,SimpleSortingVector 是不持久的。
因此,要在持久存储中排序,您必须编写
你自己的排序方法。

Vector info = (Vector) store.getContents();

现在使用任何排序算法对向量的内容进行排序。

For sorting in blackberry you can use SimpleSortingVector
but bad news is, SimpleSortingVector is not persistable.
So for sorting in persistent store you have to write
your own sorting method.

Vector info = (Vector) store.getContents();

now sort contents of vectors with any sorting algo.

扎心 2024-08-25 10:47:37

我假设您指的是存储在 PersistableStore 中的排序记录,而不仅仅是实现 Persistable 接口的对象。

为了将数据提交到 PersistentStore:

SimpleSortingVector ssv = new SimpleSortingVector();
// Construct your records and add them to the vector

PersistentObject po = PersistentStore.getPersistentObject(persistentStoreKey);
po.setContents(new ControlledAccess(ssv, codeSigningKey));
po.commit();

为了检索向量:

Object contents = po.getContents();
if (contents instanceof SimpleSortingVector)
{
    // Cast to a SimpleSortingVector and load your data
}

我相信将 SimpleSortingVector 放入 PersistentStore 应该不会有任何问题。但是,它确实混合了数据存储与其行为之间的界限(因为您不仅存储数据记录,还存储比较器和排序信息)。将记录作为 Vector 存储在 PersistentStore 中可能是一个更简洁的解决方案,当您将其从 PersistentStore 中加载时,将其复制到 SimpleSortingVector 中,以便在应用程序的整个运行时使用。如果您采用这种方法,则可以以指定的格式将有关 Comparator 的信息和排序信息存储在 Vector 本身中,并在构造 SimpleSortingVector 时将其提取出来。

I'm assuming you are referring to sorting records which are stored in the PersistentStore, not just objects which implement the Persistable interface.

In order to commit your data to the PersistentStore:

SimpleSortingVector ssv = new SimpleSortingVector();
// Construct your records and add them to the vector

PersistentObject po = PersistentStore.getPersistentObject(persistentStoreKey);
po.setContents(new ControlledAccess(ssv, codeSigningKey));
po.commit();

In order to retrieve the vector:

Object contents = po.getContents();
if (contents instanceof SimpleSortingVector)
{
    // Cast to a SimpleSortingVector and load your data
}

I believe there shouldn't be any issue with putting a SimpleSortingVector in the PersistentStore. However, it does blend the line between the storage of your data and it's behavior (since you are not only storing your data records, but also a Comparator and sorting information). It may be a cleaner solution to store your records in the PersistentStore as just a Vector, and when you load it out of the PersistentStore, copy it into a SimpleSortingVector which you use throughout the runtime of your app. If you went with that approach, you could store information about the Comparator and sorting information in the Vector itself in a specified format, and extract that out when you construct the SimpleSortingVector.

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