Skip to content

Commit

Permalink
Implement the more efficient toLowerCase
Browse files Browse the repository at this point in the history
Yay for efficiency
  • Loading branch information
mcmonkey4eva committed Nov 11, 2014
1 parent 74d0e2c commit 6c4518e
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 18 deletions.
Expand Up @@ -5,6 +5,7 @@
import net.aufdemrand.denizen.objects.*;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizencore.utilities.CoreUtilities;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
Expand Down Expand Up @@ -111,8 +112,9 @@ public void playerMoveEvent(PlayerMoveEvent event) {
// Look for cuboids that contain the block's location
List<dCuboid> cuboids = dCuboid.getNotableCuboidsContaining(event.getTo());
List<dCuboid> match = new ArrayList<dCuboid>();
if (player_cuboids.containsKey(event.getPlayer().getName().toLowerCase()))
match = player_cuboids.get(event.getPlayer().getName().toLowerCase());
String namelow = CoreUtilities.toLowerCase(event.getPlayer().getName());
if (player_cuboids.containsKey(namelow))
match = player_cuboids.get(namelow);

List<dCuboid> exits = new ArrayList<dCuboid>(match);
exits.removeAll(cuboids);
Expand Down Expand Up @@ -152,7 +154,7 @@ public void playerMoveEvent(PlayerMoveEvent event) {
}
}

player_cuboids.put(event.getPlayer().getName().toLowerCase(), cuboids);
player_cuboids.put(namelow, cuboids);
}

/**
Expand Down
20 changes: 11 additions & 9 deletions src/main/java/net/aufdemrand/denizen/objects/aH.java
Expand Up @@ -7,6 +7,7 @@
import net.aufdemrand.denizen.scripts.ScriptRegistry;
import net.aufdemrand.denizen.utilities.debugging.dB;

import net.aufdemrand.denizencore.utilities.CoreUtilities;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.entity.EntityType;
Expand Down Expand Up @@ -92,18 +93,18 @@ public Argument(String string) {

if ((first_space > -1 && first_space < first_colon) || first_colon == -1) {
value = string;
lower_value = string.toLowerCase();
lower_value = CoreUtilities.toLowerCase(string);
}
else {
has_prefix = true;
String[] split = StringUtils.split(string, ":", 2);
prefix = split[0];
lower_prefix = prefix.toLowerCase();
lower_prefix = CoreUtilities.toLowerCase(prefix);
if (split.length == 2)
value = split[1];
else
value = "";
lower_value = value.toLowerCase();
lower_value = CoreUtilities.toLowerCase(value);
}

}
Expand All @@ -115,7 +116,7 @@ public static Argument valueOf(String string) {


public boolean startsWith(String string) {
return lower_value.startsWith(string.toLowerCase());
return lower_value.startsWith(CoreUtilities.toLowerCase(string));
}


Expand All @@ -132,17 +133,18 @@ public Argument getPrefix() {


// TODO: REMOVE IN 1.0
@Deprecated
public boolean matches(String values) {
for (String value : StringUtils.split(values, ',')) {
if (value.trim().toLowerCase().equals(lower_value))
if (CoreUtilities.toLowerCase(value.trim()).equals(lower_value))
return true;
}
return false;
}

public boolean matches(String... values) {
for (String value : values) {
if (value.toLowerCase().equals(lower_value))
if (CoreUtilities.toLowerCase(value).equals(lower_value))
return true;
}
return false;
Expand All @@ -151,7 +153,7 @@ public boolean matches(String... values) {

public void replaceValue(String string) {
value = string;
lower_value = value.toLowerCase();
lower_value = CoreUtilities.toLowerCase(value);
}


Expand Down Expand Up @@ -187,7 +189,7 @@ public boolean matchesEnumList(Enum<?>[] values) {
public boolean matchesPrefix(String values) {
if (!hasPrefix()) return false;
for (String value : StringUtils.split(values, ',')) {
if (value.trim().toLowerCase().equals(lower_prefix))
if (CoreUtilities.toLowerCase(value.trim()).equals(lower_prefix))
return true;
}
return false;
Expand All @@ -196,7 +198,7 @@ public boolean matchesPrefix(String values) {
public boolean matchesPrefix(String... values) {
if (!hasPrefix()) return false;
for (String value : values) {
if (value.toLowerCase().equals(lower_prefix))
if (CoreUtilities.toLowerCase(value).equals(lower_prefix))
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/aufdemrand/denizen/objects/dList.java
Expand Up @@ -79,7 +79,7 @@ public static boolean matches(String arg) {
Matcher m;
m = flag_by_id.matcher(arg);

return m.matches() || arg.contains("|") || arg.contains(internal_escape) || arg.toLowerCase().startsWith("li@");
return m.matches() || arg.contains("|") || arg.contains(internal_escape) || CoreUtilities.toLowerCase(arg).startsWith("li@");
}


Expand Down
Expand Up @@ -6,6 +6,7 @@
import net.aufdemrand.denizen.scripts.ScriptEntrySet;
import net.aufdemrand.denizencore.scripts.ScriptEntryData;
import net.aufdemrand.denizencore.scripts.ScriptHelper;
import net.aufdemrand.denizencore.utilities.CoreUtilities;
import net.aufdemrand.denizencore.utilities.YamlConfiguration;
import net.aufdemrand.denizencore.utilities.debugging.Debuggable;

Expand Down Expand Up @@ -256,6 +257,6 @@ public boolean shouldFilter(String criteria) throws Exception {

@Override
public String toString() {
return "s@" + getName().toLowerCase();
return "s@" + CoreUtilities.toLowerCase(getName());
}
}
7 changes: 4 additions & 3 deletions src/main/java/net/aufdemrand/denizen/tags/Attribute.java
@@ -1,6 +1,7 @@
package net.aufdemrand.denizen.tags;

import net.aufdemrand.denizen.scripts.ScriptEntry;
import net.aufdemrand.denizencore.utilities.CoreUtilities;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -93,13 +94,13 @@ public boolean matches(String string) {
}

public boolean startsWith(String string) {
string = string.toLowerCase();
string = CoreUtilities.toLowerCase(string);
if (attributes.isEmpty()) return false;
return raw_tag.toLowerCase().startsWith(string);
return CoreUtilities.toLowerCase(raw_tag).startsWith(string);
}

public boolean startsWith(String string, int attribute) {
return getAttribute(attribute).toLowerCase().startsWith(string);
return CoreUtilities.toLowerCase(getAttribute(attribute)).startsWith(string);
}

int fulfilled = 0;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/aufdemrand/denizen/tags/TagManager.java
Expand Up @@ -9,6 +9,7 @@
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.depends.Depends;
import net.aufdemrand.denizencore.tags.TagContext;
import net.aufdemrand.denizencore.utilities.CoreUtilities;
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
Expand Down Expand Up @@ -178,7 +179,7 @@ public static String escapeOutput(String input) {
public void fetchObject(ReplaceableTagEvent event) {
if (!event.getName().contains("@")) return;

String object_type = StringUtils.split(event.getName(), '@')[0].toLowerCase();
String object_type = CoreUtilities.toLowerCase(CoreUtilities.Split(event.getName(), '@').get(0));
Class object_class = ObjectFetcher.getObjectClass(object_type);

if (object_class == null) {
Expand Down

0 comments on commit 6c4518e

Please sign in to comment.