更新Java PriorityQueue时,其元素更改优先级(Updating Java PriorityQueue when its elements change priority)
我试图使用
PriorityQueue
来使用Comparator
来对对象进行排序。这可以很容易地实现,但是对象类变量(比较器计算优先级)可以在初始插入之后改变。 大多数人建议删除对象,更新值并重新插入该对象的简单解决方案,因为优先级队列的比较器将被执行。
除了在PriorityQueue周围创建一个包装类来做这个吗?
I'm trying to use a
PriorityQueue
to order objects using aComparator
.This can be achieved easily, but the objects class variables (with which the comparator calculates priority) may change after the initial insertion. Most people have suggested the simple solution of removing the object, updating the values and reinserting it again, as this is when the priority queue's comparator is put into action.
Is there a better way other than just creating a wrapper class around the PriorityQueue to do this?
原文:https://stackoverflow.com/questions/1871253
最满意答案
确保列表不在可滚动容器中。
将它放在BordarLayout容器的中心。
Make sure the list is not in a scrollable container.
Place it at the center of a BordarLayout container.
相关问答
更多-
为什么Codename中的List没有显示所有条目?(Why is the List in Codename one not showing all entries if there are many?)[2023-07-19]
确保列表不在可滚动容器中。 将它放在BordarLayout容器的中心。 Make sure the list is not in a scrollable container. Place it at the center of a BordarLayout container. -
我可以强制Codename One的InfiniteScrollAdapter不循环(Can I force Codename One's InfiniteScrollAdapter not to loop)[2024-02-20]
我的方法是跟踪lastId和返回的记录数。 我们假设我有一个包含105条记录的数据库,我想一次取10条记录: 我将确保查询以升序或降序拉取记录。 假设它按升序排列,我的初始lastId将为0,一旦返回记录, lastId将更改为最后一个记录ID(在本例中为10)。 然后我将其作为参数传递给下一个记录,其中id大于lastId (10),即11向上。 编码理念: InfiniteScrollAdapter.createInfiniteScroll(scroller, new Runnable() { ... -
代号包含列表的一个列表(Codename One List Containing Lists)[2024-01-06]
没有。 这没有任何意义。 Codename一个列表渲染器是“橡皮图章”,这意味着它们没有状态,因此您将无法改变元素的大小或访问其中的各个组件。 您需要做的是使用Component-> Container层次结构来实现您正在寻找的功能。 No. This wouldn't make any sense. Codename One list renderer's are "rubber stamps" which means they have no state and so you will not be a ... -
渲染器是无国籍的。 我建议阅读开发者指南或关注我如何? 视频。 您需要编辑模型,使其包含与标签名称匹配的字段以及所需的正确字符串。 Renderer's are stateless. I suggest reading the developer guide or following the How Do I? videos. You need to edit your model so that it includes a field matching the name of the label with ...
-
我可以免费在iOS设备上测试我的Codename One应用吗?(Can I test my Codename One app on my iOS device for free?)[2022-11-12]
您需要Apple提供的证书才能在不使用xcode的情况下在设备上进行测试,而我们无法真实地提供解决方案。 从Apple获得免费证书是另一回事。 教育机构通常可以访问一个教育性的苹果开发者帐户,允许您免费执行此操作,因此,如果您是学生或了解学生,您可以访问其中一个并使用它在您的设备上免费测试您的应用程序。 You need a certificate from Apple to test on a device without using xcode and we can't realistically pr ... -
如何使用VSTO在Excel中获取Worksheet的CodeName(How to get the CodeName for Worksheet in Excel using VSTO)[2023-11-15]
在您的情况下,您可以使用Worksheet.CustomProperties作为替代来保存工作表的唯一属性。 Worksheet ws = **current_sheet** as Worksheet; ws.CustomProperties.Add("SheetID", **some_value**); 所以,稍后您可以访问它们 foreach (Excel.CustomProperty prop in ws.CustomProperties) { if (prop.Name == "Sheet ... -
表示没有条目的列表(represent list with no entries)[2021-10-14]
空列表只是[] 例如,定义一个包含空列表的变量可以通过以下方式完成: emptyList :: [a] emptyList = [] An empty list is simply [] For example, defining a variable that holds an empty list can be done by: emptyList :: [a] emptyList = [] -
EmailShare类要求图像文件的路径不是任意文件作为其第二个参数,因此加载失败。 Message类更适合它。 您还可以使用不会启动本机电子邮件应用程序的云发送选项。 例如, Log类直接通过Log.sendLog API包含该功能。 The EmailShare class expects a path to an image file not an arbitrary file as its second argument so loading that fails. The Message clas ...
-
代号解析一个(Codename one parsing)[2021-03-29]
也许你错过了这一行? connectionRequest.setPost(false); 我不确定,但我认为它默认设置为true。 Maybe you are missing this line? connectionRequest.setPost(false); I'm not sure, but I think it's set to true by default. -
在Codename One中的游戏(Game in Codename One)[2020-11-07]
Codename One可能不适合您。 7.5的Windows Phone端口基于XNA,但由于MS有效地解决了这个问题,我们不得不放弃这种方法,MS没有提供任何替代方案(没有小部件的Direct X不是替代方案)。 因此,Windows Phone上的图形目前以相对低效的方式绘制,这可能适用于纸牌游戏,但如果您需要更快的性能则不行。 Android / iOS性能应该不错,但在MS解决此用例之前,Windows Phone可能会执行。 Codename One最初并不是作为游戏平台设计的,所以它没有精灵和 ...