avoid boxing Comparator.comparings
This commit is contained in:
@@ -210,7 +210,7 @@ public class FlatStorage implements Storage
|
|||||||
@Override
|
@Override
|
||||||
public void save(Store store) throws IOException
|
public void save(Store store) throws IOException
|
||||||
{
|
{
|
||||||
store.getIndexes().sort(Comparator.comparing(Index::getId));
|
store.getIndexes().sort(Comparator.comparingInt(Index::getId));
|
||||||
for (Index idx : store.getIndexes())
|
for (Index idx : store.getIndexes())
|
||||||
{
|
{
|
||||||
String file = idx.getId() + EXTENSION;
|
String file = idx.getId() + EXTENSION;
|
||||||
@@ -222,7 +222,7 @@ public class FlatStorage implements Storage
|
|||||||
br.printf("crc=%d\n", idx.getCrc());
|
br.printf("crc=%d\n", idx.getCrc());
|
||||||
br.printf("named=%b\n", idx.isNamed());
|
br.printf("named=%b\n", idx.isNamed());
|
||||||
|
|
||||||
idx.getArchives().sort(Comparator.comparing(Archive::getArchiveId));
|
idx.getArchives().sort(Comparator.comparingInt(Archive::getArchiveId));
|
||||||
for (Archive archive : idx.getArchives())
|
for (Archive archive : idx.getArchives())
|
||||||
{
|
{
|
||||||
br.printf("id=%d\n", archive.getArchiveId());
|
br.printf("id=%d\n", archive.getArchiveId());
|
||||||
|
|||||||
@@ -65,13 +65,13 @@ public class RectangleUnion
|
|||||||
boolean trace = log.isTraceEnabled();
|
boolean trace = log.isTraceEnabled();
|
||||||
|
|
||||||
// Sort all of the rectangles so they are ordered by their left edge
|
// Sort all of the rectangles so they are ordered by their left edge
|
||||||
lefts.sort(Comparator.comparing(Rectangle::getX1));
|
lefts.sort(Comparator.comparingInt(Rectangle::getX1));
|
||||||
|
|
||||||
// Again, but for the right edge
|
// Again, but for the right edge
|
||||||
// this should be relatively fast if the rectangles are similar sizes because timsort deals with partially
|
// this should be relatively fast if the rectangles are similar sizes because timsort deals with partially
|
||||||
// presorted data well
|
// presorted data well
|
||||||
List<Rectangle> rights = new ArrayList<>(lefts);
|
List<Rectangle> rights = new ArrayList<>(lefts);
|
||||||
rights.sort(Comparator.comparing(Rectangle::getX2));
|
rights.sort(Comparator.comparingInt(Rectangle::getX2));
|
||||||
|
|
||||||
// ranges of our scan line with how many rectangles it is occluding
|
// ranges of our scan line with how many rectangles it is occluding
|
||||||
Segments segments = new Segments();
|
Segments segments = new Segments();
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ public class EventBus
|
|||||||
{
|
{
|
||||||
final ImmutableMultimap.Builder<Class<?>, Subscriber> builder = ImmutableMultimap.builder();
|
final ImmutableMultimap.Builder<Class<?>, Subscriber> builder = ImmutableMultimap.builder();
|
||||||
builder.putAll(subscribers);
|
builder.putAll(subscribers);
|
||||||
builder.orderValuesBy(Comparator.comparing(Subscriber::getPriority).reversed()
|
builder.orderValuesBy(Comparator.comparingDouble(Subscriber::getPriority).reversed()
|
||||||
.thenComparing(s -> s.object.getClass().getName()));
|
.thenComparing(s -> s.object.getClass().getName()));
|
||||||
|
|
||||||
for (Class<?> clazz = object.getClass(); clazz != null; clazz = clazz.getSuperclass())
|
for (Class<?> clazz = object.getClass(); clazz != null; clazz = clazz.getSuperclass())
|
||||||
@@ -171,7 +171,7 @@ public class EventBus
|
|||||||
{
|
{
|
||||||
final ImmutableMultimap.Builder<Class<?>, Subscriber> builder = ImmutableMultimap.builder();
|
final ImmutableMultimap.Builder<Class<?>, Subscriber> builder = ImmutableMultimap.builder();
|
||||||
builder.putAll(subscribers);
|
builder.putAll(subscribers);
|
||||||
builder.orderValuesBy(Comparator.comparing(Subscriber::getPriority).reversed()
|
builder.orderValuesBy(Comparator.comparingDouble(Subscriber::getPriority).reversed()
|
||||||
.thenComparing(s -> s.object.getClass().getName()));
|
.thenComparing(s -> s.object.getClass().getName()));
|
||||||
|
|
||||||
Subscriber sub = new Subscriber(subFn, null, priority, (Consumer<Object>) subFn);
|
Subscriber sub = new Subscriber(subFn, null, priority, (Consumer<Object>) subFn);
|
||||||
|
|||||||
@@ -546,8 +546,8 @@ public class BankTagsPlugin extends Plugin implements MouseWheelListener
|
|||||||
Widget[] containerChildren = itemContainer.getDynamicChildren();
|
Widget[] containerChildren = itemContainer.getDynamicChildren();
|
||||||
|
|
||||||
// sort the child array as the items are not in the displayed order
|
// sort the child array as the items are not in the displayed order
|
||||||
Arrays.sort(containerChildren, Comparator.comparing(Widget::getOriginalY)
|
Arrays.sort(containerChildren, Comparator.comparingInt(Widget::getOriginalY)
|
||||||
.thenComparing(Widget::getOriginalX));
|
.thenComparingInt(Widget::getOriginalX));
|
||||||
|
|
||||||
for (Widget child : containerChildren)
|
for (Widget child : containerChildren)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -436,9 +436,9 @@ class WidgetInspector extends DevToolsFrame
|
|||||||
|
|
||||||
parent = Stream.of(roots)
|
parent = Stream.of(roots)
|
||||||
.filter(w -> w.getType() == WidgetType.LAYER && w.getContentType() == 0 && !w.isSelfHidden())
|
.filter(w -> w.getType() == WidgetType.LAYER && w.getContentType() == 0 && !w.isSelfHidden())
|
||||||
.sorted(Comparator.comparing((Widget w) -> w.getRelativeX() + w.getRelativeY())
|
.sorted(Comparator.comparingInt((Widget w) -> w.getRelativeX() + w.getRelativeY())
|
||||||
.reversed()
|
.reversed()
|
||||||
.thenComparing(Widget::getId)
|
.thenComparingInt(Widget::getId)
|
||||||
.reversed())
|
.reversed())
|
||||||
.findFirst().get();
|
.findFirst().get();
|
||||||
x = 4;
|
x = 4;
|
||||||
|
|||||||
@@ -462,14 +462,14 @@ public class FishingPlugin extends Plugin
|
|||||||
|
|
||||||
final LocalPoint cameraPoint = new LocalPoint(client.getCameraX(), client.getCameraY());
|
final LocalPoint cameraPoint = new LocalPoint(client.getCameraX(), client.getCameraY());
|
||||||
fishingSpots.sort(
|
fishingSpots.sort(
|
||||||
Comparator.comparing(
|
Comparator.comparingInt(
|
||||||
// Negate to have the furthest first
|
// Negate to have the furthest first
|
||||||
(NPC npc) -> -npc.getLocalLocation().distanceTo(cameraPoint))
|
(NPC npc) -> -npc.getLocalLocation().distanceTo(cameraPoint))
|
||||||
// Order by position
|
// Order by position
|
||||||
.thenComparing(NPC::getLocalLocation, Comparator.comparing(LocalPoint::getX)
|
.thenComparing(NPC::getLocalLocation, Comparator.comparingInt(LocalPoint::getX)
|
||||||
.thenComparing(LocalPoint::getY))
|
.thenComparingInt(LocalPoint::getY))
|
||||||
// And then by id
|
// And then by id
|
||||||
.thenComparing(NPC::getId)
|
.thenComparingInt(NPC::getId)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ public class SaradominBrew implements Effect
|
|||||||
).toArray(StatChange[]::new));
|
).toArray(StatChange[]::new));
|
||||||
changes.setPositivity(Stream.of(changes.getStatChanges())
|
changes.setPositivity(Stream.of(changes.getStatChanges())
|
||||||
.map(sc -> sc.getPositivity())
|
.map(sc -> sc.getPositivity())
|
||||||
.max(Comparator.comparing(Enum::ordinal)).get());
|
.max(Comparator.naturalOrder()).get());
|
||||||
return changes;
|
return changes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -68,7 +68,9 @@ public class SuperRestore implements Effect
|
|||||||
return calc.effect(client);
|
return calc.effect(client);
|
||||||
})
|
})
|
||||||
).toArray(StatChange[]::new));
|
).toArray(StatChange[]::new));
|
||||||
changes.setPositivity(Stream.of(changes.getStatChanges()).map(sc -> sc.getPositivity()).max(Comparator.comparing(Enum::ordinal)).get());
|
changes.setPositivity(Stream.of(changes.getStatChanges())
|
||||||
|
.map(sc -> sc.getPositivity())
|
||||||
|
.max(Comparator.naturalOrder()).get());
|
||||||
return changes;
|
return changes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public class CastleWarsBandage implements Effect
|
|||||||
changes.setStatChanges(new StatChange[]{hitPoints, runEnergy});
|
changes.setStatChanges(new StatChange[]{hitPoints, runEnergy});
|
||||||
changes.setPositivity(Stream.of(changes.getStatChanges())
|
changes.setPositivity(Stream.of(changes.getStatChanges())
|
||||||
.map(StatChange::getPositivity)
|
.map(StatChange::getPositivity)
|
||||||
.max(Comparator.comparing(Enum::ordinal)).get());
|
.max(Comparator.naturalOrder()).get());
|
||||||
|
|
||||||
return changes;
|
return changes;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -418,7 +418,7 @@ public class MusicPlugin extends Plugin
|
|||||||
if (tracks == null)
|
if (tracks == null)
|
||||||
{
|
{
|
||||||
tracks = Arrays.stream(musicList.getDynamicChildren())
|
tracks = Arrays.stream(musicList.getDynamicChildren())
|
||||||
.sorted(Comparator.comparing(Widget::getRelativeY))
|
.sorted(Comparator.comparingInt(Widget::getRelativeY))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -336,7 +336,7 @@ public class QuestListPlugin extends Plugin
|
|||||||
{
|
{
|
||||||
// Find all of the widgets that we care about, sorting by their Y value
|
// Find all of the widgets that we care about, sorting by their Y value
|
||||||
quests = Arrays.stream(list.getDynamicChildren())
|
quests = Arrays.stream(list.getDynamicChildren())
|
||||||
.sorted(Comparator.comparing(Widget::getRelativeY))
|
.sorted(Comparator.comparingInt(Widget::getRelativeY))
|
||||||
.filter(w -> !QUEST_HEADERS.contains(w.getText()))
|
.filter(w -> !QUEST_HEADERS.contains(w.getText()))
|
||||||
.map(w -> new QuestWidget(w, Text.removeTags(w.getText()).toLowerCase()))
|
.map(w -> new QuestWidget(w, Text.removeTags(w.getText()).toLowerCase()))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|||||||
@@ -271,7 +271,7 @@ public class ContainableFrame extends JFrame
|
|||||||
{
|
{
|
||||||
return Arrays.stream(GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices())
|
return Arrays.stream(GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices())
|
||||||
.map(GraphicsDevice::getDefaultConfiguration)
|
.map(GraphicsDevice::getDefaultConfiguration)
|
||||||
.max(Comparator.comparing(config ->
|
.max(Comparator.comparingInt(config ->
|
||||||
{
|
{
|
||||||
Rectangle intersection = config.getBounds().intersection(getBounds());
|
Rectangle intersection = config.getBounds().intersection(getBounds());
|
||||||
return intersection.width * intersection.height;
|
return intersection.width * intersection.height;
|
||||||
|
|||||||
Reference in New Issue
Block a user