Improve and cleanup code in runelite-client (#3859)

* Remove redundant escape char
* Remove double negation
* Replace while loop with forEach
* Replace collections.sort with list.sort as its faster
* Replace if/elseif chain with switch
* Remove redundant call to format()
* Use bulk operation instead of iteration
* Remove unnecessary contains check
* Remove redundant type casts
This commit is contained in:
Harry
2018-06-18 10:05:33 +01:00
committed by Tomas Slusny
parent 3472d7e5e8
commit 3b17c3e892
13 changed files with 27 additions and 36 deletions

View File

@@ -195,7 +195,7 @@ public class ConfigManager
Map<String, String> copy = (Map) ImmutableMap.copyOf(properties);
copy.forEach((groupAndKey, value) ->
{
final String[] split = ((String) groupAndKey).split("\\.", 2);
final String[] split = groupAndKey.split("\\.", 2);
if (split.length != 2)
{
log.debug("Properties key malformed!: {}", groupAndKey);
@@ -209,7 +209,7 @@ public class ConfigManager
configChanged.setGroup(groupName);
configChanged.setKey(key);
configChanged.setOldValue(null);
configChanged.setNewValue((String) value);
configChanged.setNewValue(value);
eventBus.post(configChanged);
});
}

View File

@@ -231,7 +231,7 @@ public class ItemManager
itemPriceCache.put(itemPrice.getItem().getId(), itemPrice);
}
// Append these to the already cached items
Arrays.stream(itemPrices).forEach(existing::add);
existing.addAll(Arrays.asList(itemPrices));
}
future.complete(existing.toArray(new ItemPrice[existing.size()]));
}

View File

@@ -25,6 +25,7 @@
package net.runelite.client.plugins.cannon;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import lombok.Getter;
import net.runelite.api.coords.WorldPoint;
@@ -59,10 +60,7 @@ public enum CannonSpots
{
for (CannonSpots cannonSpot : values())
{
for (WorldPoint spot : cannonSpot.spots)
{
cannonSpots.add(spot);
}
cannonSpots.addAll(Arrays.asList(cannonSpot.spots));
}
}

View File

@@ -28,7 +28,6 @@ package net.runelite.client.plugins.cerberus;
import com.google.common.collect.ComparisonChain;
import com.google.common.eventbus.Subscribe;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;
@@ -99,7 +98,7 @@ public class CerberusPlugin extends Plugin
return;
}
Collections.sort(ghosts, (a, b) -> ComparisonChain.start()
ghosts.sort((a, b) -> ComparisonChain.start()
// First, sort by the southernmost ghost (e.g with lowest y)
.compare(a.getLocalLocation().getY(), b.getLocalLocation().getY())
// Then, sort by the westernmost ghost (e.g with lowest x)

View File

@@ -85,17 +85,17 @@ public class DailyTasksPlugin extends Plugin
{
if (event.getGroup().equals("dailytaskindicators"))
{
if (event.getKey().equals("showHerbBoxes"))
switch (event.getKey())
{
hasSentHerbMsg = false;
}
else if (event.getKey().equals("showStaves"))
{
hasSentStavesMsg = false;
}
else if (event.getKey().equals("showEssence"))
{
hasSentEssenceMsg = false;
case "showHerbBoxes":
hasSentHerbMsg = false;
break;
case "showStaves":
hasSentStavesMsg = false;
break;
case "showEssence":
hasSentEssenceMsg = false;
break;
}
}
}

View File

@@ -27,7 +27,6 @@ package net.runelite.client.plugins.hunter;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.util.Iterator;
import java.util.Map;
import javax.inject.Inject;
import net.runelite.api.Client;
@@ -99,10 +98,8 @@ public class TrapOverlay extends Overlay
*/
private void drawTraps(Graphics2D graphics)
{
Iterator<Map.Entry<WorldPoint, HunterTrap>> it = plugin.getTraps().entrySet().iterator();
while (it.hasNext())
for (Map.Entry<WorldPoint, HunterTrap> entry : plugin.getTraps().entrySet())
{
Map.Entry<WorldPoint, HunterTrap> entry = it.next();
HunterTrap trap = entry.getValue();
switch (trap.getState())

View File

@@ -60,7 +60,7 @@ public class JRichTextPane extends JEditorPane
public void enableAutoLinkHandler(boolean enable)
{
if (enable != (linkHandler != null))
if (enable == (linkHandler == null))
{
if (enable)
{

View File

@@ -200,8 +200,8 @@ class InstanceMapOverlay extends Overlay
int tileX = playerLoc.getRegionX();
int tileY = (tiles[0].length - 1) - playerLoc.getRegionY(); // flip the y value
int x = (int) (tileX * TILE_SIZE);
int y = (int) (tileY * TILE_SIZE);
int x = tileX * TILE_SIZE;
int y = tileY * TILE_SIZE;
graphics.setColor(dotColor);
graphics.fillRect(x, y, PLAYER_MARKER_SIZE, PLAYER_MARKER_SIZE);//draw the players point on the map
graphics.setColor(outlineColor);

View File

@@ -47,7 +47,7 @@ public class KingdomCounter extends Counter
@Override
public String getTooltip()
{
return String.format("Favor: " + plugin.getFavor() + "/127" + "</br>"
+ "Coffer: " + StackFormatter.quantityToRSStackSize(plugin.getCoffer()));
return "Favor: " + plugin.getFavor() + "/127" + "</br>"
+ "Coffer: " + StackFormatter.quantityToRSStackSize(plugin.getCoffer());
}
}

View File

@@ -82,7 +82,7 @@ public class RaidsPlugin extends Plugin
private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("###.##");
static final DecimalFormat POINTS_FORMAT = new DecimalFormat("#,###");
private static final String SPLIT_REGEX = "\\s*,\\s*";
private static final Pattern ROTATION_REGEX = Pattern.compile("\\[(.*?)\\]");
private static final Pattern ROTATION_REGEX = Pattern.compile("\\[(.*?)]");
private BufferedImage raidsIcon;
private RaidsTimer timer;

View File

@@ -129,11 +129,8 @@ public class XpGlobesPlugin extends Plugin
public void addXpGlobe(XpGlobe xpGlobe, int maxLength)
{
if (xpGlobes.contains(xpGlobe))
{
//remove the old globe, allowing it to be readded as the most recent (right) side when drawn
xpGlobes.remove(xpGlobe);
}
//remove the old globe, allowing it to be readded as the most recent (right) side when drawn
xpGlobes.remove(xpGlobe);
if (getXpGlobesSize() >= maxLength)
{
xpGlobes.remove(0);

View File

@@ -57,7 +57,7 @@ public final class ComboBoxListRenderer extends JLabel implements ListCellRender
setBorder(new EmptyBorder(5, 5, 5, 0));
String text = (String) o.toString();
String text = o.toString();
setText(text);
return this;

View File

@@ -155,7 +155,7 @@ public class InfoBoxManager
private void refreshInfoBoxes()
{
Collections.sort(infoBoxes, (b1, b2) -> ComparisonChain
infoBoxes.sort((b1, b2) -> ComparisonChain
.start()
.compare(b1.getPriority(), b2.getPriority())
.compare(b1.getPlugin().getClass().getAnnotation(PluginDescriptor.class).name(), b2.getPlugin().getClass().getAnnotation(PluginDescriptor.class).name())