Replaced dynamic regular expressions with compiled pattern
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user