首页 \ 问答 \ 更新Java PriorityQueue时,其元素更改优先级(Updating Java PriorityQueue when its elements change priority)

更新Java PriorityQueue时,其元素更改优先级(Updating Java PriorityQueue when its elements change priority)

我试图使用PriorityQueue来使用Comparator来对对象进行排序。

这可以很容易地实现,但是对象类变量(比较器计算优先级)可以在初始插入之后改变。 大多数人建议删除对象,更新值并重新插入该对象的简单解决方案,因为优先级队列的比较器将被执行。

除了在PriorityQueue周围创建一个包装类来做这个吗?


I'm trying to use a PriorityQueue to order objects using a Comparator.

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
更新时间:2024-04-19 06:04

最满意答案

确保列表不在可滚动容器中。

将它放在BordarLayout容器的中心。


Make sure the list is not in a scrollable container.

Place it at the center of a BordarLayout container.

相关问答

更多
  • 确保列表不在可滚动容器中。 将它放在BordarLayout容器的中心。 Make sure the list is not in a scrollable container. Place it at the center of a BordarLayout container.
  • 我的方法是跟踪lastId和返回的记录数。 我们假设我有一个包含105条记录的数据库,我想一次取10条记录: 我将确保查询以升序或降序拉取记录。 假设它按升序排列,我的初始lastId将为0,一旦返回记录, lastId将更改为最后一个记录ID(在本例中为10)。 然后我将其作为参数传递给下一个记录,其中id大于lastId (10),即11向上。 编码理念: InfiniteScrollAdapter.createInfiniteScroll(scroller, new Runnable() { ...
  • 没有。 这没有任何意义。 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 ...
  • 您需要Apple提供的证书才能在不使用xcode的情况下在设备上进行测试,而我们无法真实地提供解决方案。 从Apple获得免费证书是另一回事。 教育机构通常可以访问一个教育性的苹果开发者帐户,允许您免费执行此操作,因此,如果您是学生或了解学生,您可以访问其中一个并使用它在您的设备上免费测试您的应用程序。 You need a certificate from Apple to test on a device without using xcode and we can't realistically pr ...
  • 在您的情况下,您可以使用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 ...
  • 空列表只是[] 例如,定义一个包含空列表的变量可以通过以下方式完成: 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 ...
  • 也许你错过了这一行? 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可能不适合您。 7.5的Windows Phone端口基于XNA,但由于MS有效地解决了这个问题,我们不得不放弃这种方法,MS没有提供任何替代方案(没有小部件的Direct X不是替代方案)。 因此,Windows Phone上的图形目前以相对低效的方式绘制,这可能适用于纸牌游戏,但如果您需要更快的性能则不行。 Android / iOS性能应该不错,但在MS解决此用例之前,Windows Phone可能会执行。 Codename One最初并不是作为游戏平台设计的,所以它没有精灵和 ...

相关文章

更多

最新问答

更多
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • 电脑高中毕业学习去哪里培训
  • 电脑系统专业就业状况如何啊?
  • IEnumerable linq表达式(IEnumerable linq expressions)
  • 如何在Spring测试中连接依赖关系(How to wire dependencies in Spring tests)
  • Solr可以在没有Lucene的情况下运行吗?(Can Solr run without Lucene?)
  • 如何保证Task在当前线程上同步运行?(How to guarantee that a Task runs synchronously on the current thread?)
  • 在保持每列的类的同时向数据框添加行(Adding row to data frame while maintaining the class of each column)
  • 的?(The ? marks in emacs/haskell and ghc mode)
  • 一个线程可以调用SuspendThread传递自己的线程ID吗?(Can a thread call SuspendThread passing its own thread ID?)
  • 延迟socket.io响应,并“警告 - websocket连接无效”(Delayed socket.io response, and “warn - websocket connection invalid”)
  • 悬停时的图像转换(Image transition on hover)
  • IIS 7.5仅显示homecontroller(IIS 7.5 only shows homecontroller)
  • 没有JavaScript的复选框“关闭”值(Checkbox 'off' value without JavaScript)
  • java分布式框架有哪些
  • Python:填写表单并点击按钮确认[关闭](Python: fill out a form and confirm with a button click [closed])
  • PHP将文件链接到根文件目录(PHP Linking Files to Root File Directory)
  • 我如何删除ListView中的项目?(How I can remove a item in my ListView?)
  • 您是否必须为TFS(云)中的每个BUG创建一个TASK以跟踪时间?(Do you have to create a TASK for every BUG in TFS (Cloud) to track time?)
  • typoscript TMENU ATagParams小写(typoscript TMENU ATagParams lowercase)
  • 武陟会计培训类的学校哪个好点?
  • 从链接中删除文本修饰(Remove text decoration from links)