Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Sorting tie-breakers in stream

Featured Replies

I have a question about sorting in a stream. When sorting using a single comparator, o is an RS2Object and the reference to realDistance is found.

objects.getAll().stream.sorted(Comparator.comparingInt(map::realDistance)).findFirst();

When I try to use a second comparator to tie-break, o is an object and the reference to realDistance and bar are not found.

objects.getAll().stream.sorted(Comparator.comparingInt(map::realDistance).thenComparingInt(foo::bar).findFirst();

I am also unable to reverse the result of the sort.

objects.getAll().stream.sorted(Comparator.comparingInt(map::realDistance).reversed()).findFirst();

What is the correct way to tie-break a sort in a stream?

2 hours ago, Solzhenitsyn said:

 

When I try to use a second comparator to tie-break, o is an object and the reference to realDistance and bar are not found.


objects.getAll().stream.sorted(Comparator.comparingInt(map::realDistance).thenComparingInt(foo::bar).findFirst();

 

your parentheses are messed up lol. You're welcome

  • Author
11 hours ago, dogetrix said:

your parentheses are messed up lol. You're welcome

I typed an MCVE by hand, parentheses are not the problem. 

Edited by Solzhenitsyn

On 7/30/2018 at 5:03 AM, Solzhenitsyn said:

I have a question about sorting in a stream. When sorting using a single comparator, o is an RS2Object and the reference to realDistance is found.


objects.getAll().stream.sorted(Comparator.comparingInt(map::realDistance)).findFirst();

When I try to use a second comparator to tie-break, o is an object and the reference to realDistance and bar are not found.


objects.getAll().stream.sorted(Comparator.comparingInt(map::realDistance).thenComparingInt(foo::bar).findFirst();

I am also unable to reverse the result of the sort.


objects.getAll().stream.sorted(Comparator.comparingInt(map::realDistance).reversed()).findFirst();

What is the correct way to tie-break a sort in a stream?

Let's see your implementation of bar in foo?

Make sure you specify the type as RS2Object for the first functional interface input (should carry to the chained thenComparing)

Comparator.<RS2Object>comparingInt(map::realDistance)

Also be aware that sorting all objects by realDistance is very computationally expensive.

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.