Replaced dynamic regular expressions with compiled pattern

This commit is contained in:
thatsIch 2015-03-26 11:33:08 +01:00
parent dff3364eb5
commit 58db877006
5 changed files with 35 additions and 15 deletions

View file

@ -54,6 +54,7 @@ import appeng.core.localization.ButtonToolTips;
public class GuiImgButton extends GuiButton implements ITooltip
{
private static final Pattern COMPILE = Pattern.compile( "%s" );
private static final Pattern PATTERN_NEW_LINE = Pattern.compile( "\\n", Pattern.LITERAL );
private static Map<EnumPair, ButtonAppearance> appearances;
private final Enum buttonSetting;
public boolean halfSize = false;
@ -281,7 +282,7 @@ public class GuiImgButton extends GuiButton implements ITooltip
if ( this.fillVar != null )
value = COMPILE.matcher( value ).replaceFirst( this.fillVar );
value = value.replace( "\\n", "\n" );
value = PATTERN_NEW_LINE.matcher( value ).replaceAll( "\n" );
StringBuilder sb = new StringBuilder( value );
int i = sb.lastIndexOf( "\n" );

View file

@ -19,6 +19,8 @@
package appeng.client.gui.widgets;
import java.util.regex.Pattern;
import org.lwjgl.opengl.GL11;
import net.minecraft.client.Minecraft;
@ -30,6 +32,7 @@ import appeng.client.texture.ExtraBlockTextures;
public class GuiToggleButton extends GuiButton implements ITooltip
{
private static final Pattern PATTERN_NEW_LINE = Pattern.compile( "\\n", Pattern.LITERAL );
private final int iconIdxOn;
private final int iconIdxOff;
@ -94,7 +97,7 @@ public class GuiToggleButton extends GuiButton implements ITooltip
if ( value == null || value.isEmpty() )
value = this.displayHint;
value = value.replace( "\\n", "\n" );
value = PATTERN_NEW_LINE.matcher( value ).replaceAll( "\n" );
StringBuilder sb = new StringBuilder( value );
int i = sb.lastIndexOf( "\n" );

View file

@ -20,6 +20,7 @@ package appeng.core.features;
import java.util.EnumSet;
import java.util.regex.Pattern;
import net.minecraft.block.Block;
import net.minecraft.block.BlockStairs;
@ -44,6 +45,10 @@ import appeng.util.Platform;
public class AEFeatureHandler implements AEItemDefinition
{
private static final Pattern PATTERN_ITEM_MULTI_PART = Pattern.compile( "ItemMultiPart", Pattern.LITERAL );
private static final Pattern PATTERN_ITEM_MULTI_MATERIAL = Pattern.compile( "ItemMultiMaterial", Pattern.LITERAL );
private static final Pattern PATTERN_QUARTZ = Pattern.compile( "Quartz", Pattern.LITERAL );
private final EnumSet<AEFeature> features;
private final String subName;
@ -149,9 +154,9 @@ public class AEFeatureHandler implements AEItemDefinition
String name = o.getSimpleName();
if ( name.startsWith( "ItemMultiPart" ) )
name = name.replace( "ItemMultiPart", "ItemPart" );
name = PATTERN_ITEM_MULTI_PART.matcher( name ).replaceAll( "ItemPart" );
else if ( name.startsWith( "ItemMultiMaterial" ) )
name = name.replace( "ItemMultiMaterial", "ItemMaterial" );
name = PATTERN_ITEM_MULTI_MATERIAL.matcher( name ).replaceAll( "ItemMaterial" );
if ( subName != null )
{
@ -161,9 +166,9 @@ public class AEFeatureHandler implements AEItemDefinition
return "ItemPart.P2PTunnel";
if ( subName.equals( "CertusQuartzTools" ) )
return name.replace( "Quartz", "CertusQuartz" );
return PATTERN_QUARTZ.matcher( name ).replaceAll( "CertusQuartz" );
if ( subName.equals( "NetherQuartzTools" ) )
return name.replace( "Quartz", "NetherQuartz" );
return PATTERN_QUARTZ.matcher( name ).replaceAll( "NetherQuartz" );
name += '.' + subName;
}

View file

@ -19,11 +19,17 @@
package appeng.core.features;
import java.util.regex.Pattern;
import com.google.common.base.Optional;
public class FeatureNameExtractor
{
private static final Pattern PATTERN_ITEM_MULTI_PART = Pattern.compile( "ItemMultiPart", Pattern.LITERAL );
private static final Pattern PATTERN_ITEM_MULTI_MATERIAL = Pattern.compile( "ItemMultiMaterial", Pattern.LITERAL );
private static final Pattern PATTERN_QUARTZ = Pattern.compile( "Quartz", Pattern.LITERAL );
private final Class<?> clazz;
private final Optional<String> subName;
@ -39,11 +45,11 @@ public class FeatureNameExtractor
if ( name.startsWith( "ItemMultiPart" ) )
{
name = name.replace( "ItemMultiPart", "ItemPart" );
name = PATTERN_ITEM_MULTI_PART.matcher( name ).replaceAll( "ItemPart" );
}
else if ( name.startsWith( "ItemMultiMaterial" ) )
{
name = name.replace( "ItemMultiMaterial", "ItemMaterial" );
name = PATTERN_ITEM_MULTI_MATERIAL.matcher( name ).replaceAll( "ItemMaterial" );
}
if ( this.subName.isPresent() )
@ -57,11 +63,11 @@ public class FeatureNameExtractor
}
else if ( subName.equals( "CertusQuartzTools" ) )
{
return name.replace( "Quartz", "CertusQuartz" );
return PATTERN_QUARTZ.matcher( name ).replaceAll( "CertusQuartz" );
}
else if ( subName.equals( "NetherQuartzTools" ) )
{
return name.replace( "Quartz", "NetherQuartz" );
return PATTERN_QUARTZ.matcher( name ).replaceAll( "NetherQuartz" );
}
name += '.' + subName;

View file

@ -20,6 +20,7 @@ package appeng.core.sync;
import java.lang.reflect.Constructor;
import java.util.regex.Pattern;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
@ -190,6 +191,8 @@ public enum GuiBridge implements IGuiHandler
GUI_CRAFTING_STATUS(ContainerCraftingStatus.class, ITerminalHost.class, ITEM_OR_WORLD, SecurityPermissions.CRAFT);
private static final Pattern PATTERN_PRE_CONTAINER = Pattern.compile( ".Container", Pattern.LITERAL );
private static final Pattern PATTERN_POST_CONTAINER = Pattern.compile( "container." );
private final Class Tile;
private Class Gui;
private final Class Container;
@ -210,13 +213,15 @@ public enum GuiBridge implements IGuiHandler
{
if ( Platform.isClient() )
{
String start = this.Container.getName();
String GuiClass = start.replaceFirst( "container.", "client.gui." ).replace( ".Container", ".Gui" );
if ( start.equals( GuiClass ) )
final String start = this.Container.getName();
final String guiClassPostReplaced = PATTERN_POST_CONTAINER.matcher( start ).replaceFirst( "client.gui." );
final String guiClassPreReplaced = PATTERN_PRE_CONTAINER.matcher( guiClassPostReplaced ).replaceAll( ".Gui" );
if ( start.equals( guiClassPreReplaced ) )
throw new RuntimeException( "Unable to find gui class" );
this.Gui = ReflectionHelper.getClass( this.getClass().getClassLoader(), GuiClass );
this.Gui = ReflectionHelper.getClass( this.getClass().getClassLoader(), guiClassPreReplaced );
if ( this.Gui == null )
throw new RuntimeException( "Cannot Load class: " + GuiClass );
throw new RuntimeException( "Cannot Load class: " + guiClassPreReplaced );
}
}