From baa60a1b577a5a3006c70a9202b60e4099184d24 Mon Sep 17 00:00:00 2001 From: Vhati Date: Tue, 2 Jan 2018 07:59:02 -0500 Subject: [PATCH] Moderate code cleanup (via mercutiodesign) --- src/main/java/net/vhati/ftldat/FTLPack.java | 14 +++++------ .../ftldat/FileChannelRegionInputStream.java | 2 +- .../java/net/vhati/ftldat/FolderPack.java | 2 +- src/main/java/net/vhati/ftldat/PkgPack.java | 23 +++++++++---------- .../modmanager/core/SloppyXMLParser.java | 2 +- .../vhati/modmanager/ui/FieldEditorPanel.java | 2 +- 6 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/main/java/net/vhati/ftldat/FTLPack.java b/src/main/java/net/vhati/ftldat/FTLPack.java index 613f303..1bf00d9 100644 --- a/src/main/java/net/vhati/ftldat/FTLPack.java +++ b/src/main/java/net/vhati/ftldat/FTLPack.java @@ -208,7 +208,7 @@ public class FTLPack extends AbstractPack { if ( pathToIndexMap.containsKey( entry.innerPath ) ) { throw new IOException( "InnerPath occurs more than once: "+ entry.innerPath ); } - pathToIndexMap.put( entry.innerPath, new Integer( i ) ); + pathToIndexMap.put( entry.innerPath, i ); } } @@ -323,7 +323,7 @@ public class FTLPack extends AbstractPack { @Override public void add( String innerPath, InputStream is ) throws IOException { - if ( innerPath.indexOf( "\\" ) != -1 ) { + if ( innerPath.contains( "\\" ) ) { throw new IllegalArgumentException( "InnerPath contains backslashes: "+ innerPath ); } if ( pathToIndexMap.containsKey( innerPath ) ) { @@ -370,7 +370,7 @@ public class FTLPack extends AbstractPack { @Override public void extractTo( String innerPath, OutputStream os ) throws FileNotFoundException, IOException { - if ( innerPath.indexOf( "\\" ) != -1 ) { + if ( innerPath.contains( "\\" ) ) { throw new IllegalArgumentException( "InnerPath contains backslashes: "+ innerPath ); } if ( !pathToIndexMap.containsKey( innerPath ) ) { @@ -398,7 +398,7 @@ public class FTLPack extends AbstractPack { @Override public void remove( String innerPath ) throws FileNotFoundException, IOException { - if ( innerPath.indexOf( "\\" ) != -1 ) { + if ( innerPath.contains( "\\" ) ) { throw new IllegalArgumentException( "InnerPath contains backslashes: "+ innerPath ); } if ( !pathToIndexMap.containsKey( innerPath ) ) { @@ -420,7 +420,7 @@ public class FTLPack extends AbstractPack { @Override public boolean contains( String innerPath ) { - if ( innerPath.indexOf( "\\" ) != -1 ) { + if ( innerPath.contains( "\\" ) ) { throw new IllegalArgumentException( "InnerPath contains backslashes: "+ innerPath ); } return pathToIndexMap.containsKey( innerPath ); @@ -428,7 +428,7 @@ public class FTLPack extends AbstractPack { @Override public InputStream getInputStream( String innerPath ) throws FileNotFoundException, IOException { - if ( innerPath.indexOf( "\\" ) != -1 ) { + if ( innerPath.contains( "\\" ) ) { throw new IllegalArgumentException( "InnerPath contains backslashes: "+ innerPath ); } if ( !pathToIndexMap.containsKey( innerPath ) ) { @@ -501,7 +501,7 @@ public class FTLPack extends AbstractPack { for ( int i=0; i < tmpEntries.size(); i++ ) { DatEntry entry = tmpEntries.get ( i ); - pathToIndexMap.put( entry.innerPath, new Integer( i ) ); + pathToIndexMap.put( entry.innerPath, i ); // Write the header index. raf.seek( getHeaderIndexPosition( i ) ); diff --git a/src/main/java/net/vhati/ftldat/FileChannelRegionInputStream.java b/src/main/java/net/vhati/ftldat/FileChannelRegionInputStream.java index 5ab2d2f..8bee178 100644 --- a/src/main/java/net/vhati/ftldat/FileChannelRegionInputStream.java +++ b/src/main/java/net/vhati/ftldat/FileChannelRegionInputStream.java @@ -64,7 +64,7 @@ public class FileChannelRegionInputStream extends InputStream { // Do an absolute get() from the buffer, // and interpret the byte as if it were unsigned. - int result = (int)(buf.get( (int)(intraPos - bufOffset) ) & 0xff); + int result = buf.get( (int)(intraPos - bufOffset) ) & 0xff; intraPos++; return result; } diff --git a/src/main/java/net/vhati/ftldat/FolderPack.java b/src/main/java/net/vhati/ftldat/FolderPack.java index 2fef3ae..ea744fd 100644 --- a/src/main/java/net/vhati/ftldat/FolderPack.java +++ b/src/main/java/net/vhati/ftldat/FolderPack.java @@ -143,7 +143,7 @@ public class FolderPack extends AbstractPack { * The location it represents is not guaranteed to exist. */ public File getFile( String innerPath ) { - if ( innerPath.indexOf( "\\" ) != -1 ) { + if ( innerPath.contains( "\\" ) ) { throw new IllegalArgumentException( "InnerPath contains backslashes: "+ innerPath ); } File tmpFile = new File( rootDir, innerPath ); diff --git a/src/main/java/net/vhati/ftldat/PkgPack.java b/src/main/java/net/vhati/ftldat/PkgPack.java index 04abfd4..423bee7 100644 --- a/src/main/java/net/vhati/ftldat/PkgPack.java +++ b/src/main/java/net/vhati/ftldat/PkgPack.java @@ -364,8 +364,8 @@ public class PkgPack extends AbstractPack { raf.seek( 0 ); raf.setLength( 0 ); - for ( int i=0; i < signature.length; i++ ) { - raf.writeByte( signature[i] ); + for ( int x : signature ) { + raf.writeByte( x ); } writeBigUShort( HEADER_SIZE ); writeBigUShort( ENTRY_SIZE ); @@ -379,8 +379,8 @@ public class PkgPack extends AbstractPack { raf.seek( 0 ); // Check the file signature. - for ( int i=0; i < signature.length; i++ ) { - if ( raf.readUnsignedByte() != signature[i] ) { + for ( int x : signature ) { + if ( raf.readUnsignedByte() != x ) { throw new IOException( "Unexpected file signature" ); } } @@ -438,7 +438,7 @@ public class PkgPack extends AbstractPack { bigByteBuf.position( entry.innerPathOffset ); entry.innerPath = readNullTerminatedString( bigByteBuf ); - pathToIndexMap.put( entry.innerPath, new Integer( i ) ); + pathToIndexMap.put( entry.innerPath, i ); } } @@ -571,7 +571,7 @@ public class PkgPack extends AbstractPack { */ @Override public void add( String innerPath, InputStream is ) throws IOException { - if ( innerPath.indexOf( "\\" ) != -1 ) { + if ( innerPath.contains( "\\" ) ) { throw new IllegalArgumentException( "InnerPath contains backslashes: "+ innerPath ); } if ( pathToIndexMap.containsKey( innerPath ) ) { @@ -664,7 +664,7 @@ public class PkgPack extends AbstractPack { @Override public void remove( String innerPath ) throws FileNotFoundException, IOException { - if ( innerPath.indexOf( "\\" ) != -1 ) { + if ( innerPath.contains( "\\" ) ) { throw new IllegalArgumentException( "InnerPath contains backslashes: "+ innerPath ); } if ( !pathToIndexMap.containsKey( innerPath ) ) { @@ -686,7 +686,7 @@ public class PkgPack extends AbstractPack { @Override public boolean contains( String innerPath ) { - if ( innerPath.indexOf( "\\" ) != -1 ) { + if ( innerPath.contains( "\\" ) ) { throw new IllegalArgumentException( "InnerPath contains backslashes: "+ innerPath ); } return pathToIndexMap.containsKey( innerPath ); @@ -694,7 +694,7 @@ public class PkgPack extends AbstractPack { @Override public InputStream getInputStream( String innerPath ) throws FileNotFoundException, IOException { - if ( innerPath.indexOf( "\\" ) != -1 ) { + if ( innerPath.contains( "\\" ) ) { throw new IllegalArgumentException( "InnerPath contains backslashes: "+ innerPath ); } if ( !pathToIndexMap.containsKey( innerPath ) ) { @@ -805,8 +805,7 @@ public class PkgPack extends AbstractPack { // Move data toward the top. long pendingDataOffset = neededMinDataOffset; - for ( int i=0; i < tmpEntries.size(); i++ ) { - PkgEntry entry = tmpEntries.get ( i ); + for ( PkgEntry entry : tmpEntries ) { if ( pendingDataOffset != entry.dataOffset ) { long totalBytes = entry.dataSize; @@ -838,7 +837,7 @@ public class PkgPack extends AbstractPack { pathToIndexMap.clear(); for ( PkgEntry entry : entryList ) { - pathToIndexMap.put( entry.innerPath, new Integer( pathToIndexMap.size() ) ); + pathToIndexMap.put( entry.innerPath, pathToIndexMap.size() ); } // Update the header. diff --git a/src/main/java/net/vhati/modmanager/core/SloppyXMLParser.java b/src/main/java/net/vhati/modmanager/core/SloppyXMLParser.java index 8ae6718..9f9e960 100644 --- a/src/main/java/net/vhati/modmanager/core/SloppyXMLParser.java +++ b/src/main/java/net/vhati/modmanager/core/SloppyXMLParser.java @@ -323,7 +323,7 @@ public class SloppyXMLParser { int colNum = lineAndCol[1]; String hint = ""; - if ( e.getMessage() != null && e.getMessage().indexOf( "not allowed at the document root" ) != -1 ) { + if ( e.getMessage() != null && e.getMessage().contains( "not allowed at the document root" ) ) { hint = " (There's likely an extraneous closing tag before this point.)"; } SAXParseException cause = new SAXParseException( String.format( "At line %d, column %d: %s%s", lineNum, colNum, e.getMessage(), hint ), null, null, lineNum, colNum, e ); diff --git a/src/main/java/net/vhati/modmanager/ui/FieldEditorPanel.java b/src/main/java/net/vhati/modmanager/ui/FieldEditorPanel.java index 3b4f868..f4b8ad0 100644 --- a/src/main/java/net/vhati/modmanager/ui/FieldEditorPanel.java +++ b/src/main/java/net/vhati/modmanager/ui/FieldEditorPanel.java @@ -29,7 +29,7 @@ import net.vhati.modmanager.ui.RegexDocument; public class FieldEditorPanel extends JPanel { - public enum ContentType { WRAPPED_LABEL, LABEL, STRING, TEXT_AREA, INTEGER, BOOLEAN, SLIDER, COMBO, CHOOSER }; + public enum ContentType { WRAPPED_LABEL, LABEL, STRING, TEXT_AREA, INTEGER, BOOLEAN, SLIDER, COMBO, CHOOSER } private Map wrappedLabelMap = new HashMap(); private Map labelMap = new HashMap();