Moderate code cleanup (via mercutiodesign)

This commit is contained in:
Vhati 2018-01-02 07:59:02 -05:00
parent bbe58e05a9
commit baa60a1b57
6 changed files with 22 additions and 23 deletions

View file

@ -208,7 +208,7 @@ public class FTLPack extends AbstractPack {
if ( pathToIndexMap.containsKey( entry.innerPath ) ) { if ( pathToIndexMap.containsKey( entry.innerPath ) ) {
throw new IOException( "InnerPath occurs more than once: "+ 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 @Override
public void add( String innerPath, InputStream is ) throws IOException { public void add( String innerPath, InputStream is ) throws IOException {
if ( innerPath.indexOf( "\\" ) != -1 ) { if ( innerPath.contains( "\\" ) ) {
throw new IllegalArgumentException( "InnerPath contains backslashes: "+ innerPath ); throw new IllegalArgumentException( "InnerPath contains backslashes: "+ innerPath );
} }
if ( pathToIndexMap.containsKey( innerPath ) ) { if ( pathToIndexMap.containsKey( innerPath ) ) {
@ -370,7 +370,7 @@ public class FTLPack extends AbstractPack {
@Override @Override
public void extractTo( String innerPath, OutputStream os ) throws FileNotFoundException, IOException { public void extractTo( String innerPath, OutputStream os ) throws FileNotFoundException, IOException {
if ( innerPath.indexOf( "\\" ) != -1 ) { if ( innerPath.contains( "\\" ) ) {
throw new IllegalArgumentException( "InnerPath contains backslashes: "+ innerPath ); throw new IllegalArgumentException( "InnerPath contains backslashes: "+ innerPath );
} }
if ( !pathToIndexMap.containsKey( innerPath ) ) { if ( !pathToIndexMap.containsKey( innerPath ) ) {
@ -398,7 +398,7 @@ public class FTLPack extends AbstractPack {
@Override @Override
public void remove( String innerPath ) throws FileNotFoundException, IOException { public void remove( String innerPath ) throws FileNotFoundException, IOException {
if ( innerPath.indexOf( "\\" ) != -1 ) { if ( innerPath.contains( "\\" ) ) {
throw new IllegalArgumentException( "InnerPath contains backslashes: "+ innerPath ); throw new IllegalArgumentException( "InnerPath contains backslashes: "+ innerPath );
} }
if ( !pathToIndexMap.containsKey( innerPath ) ) { if ( !pathToIndexMap.containsKey( innerPath ) ) {
@ -420,7 +420,7 @@ public class FTLPack extends AbstractPack {
@Override @Override
public boolean contains( String innerPath ) { public boolean contains( String innerPath ) {
if ( innerPath.indexOf( "\\" ) != -1 ) { if ( innerPath.contains( "\\" ) ) {
throw new IllegalArgumentException( "InnerPath contains backslashes: "+ innerPath ); throw new IllegalArgumentException( "InnerPath contains backslashes: "+ innerPath );
} }
return pathToIndexMap.containsKey( innerPath ); return pathToIndexMap.containsKey( innerPath );
@ -428,7 +428,7 @@ public class FTLPack extends AbstractPack {
@Override @Override
public InputStream getInputStream( String innerPath ) throws FileNotFoundException, IOException { public InputStream getInputStream( String innerPath ) throws FileNotFoundException, IOException {
if ( innerPath.indexOf( "\\" ) != -1 ) { if ( innerPath.contains( "\\" ) ) {
throw new IllegalArgumentException( "InnerPath contains backslashes: "+ innerPath ); throw new IllegalArgumentException( "InnerPath contains backslashes: "+ innerPath );
} }
if ( !pathToIndexMap.containsKey( innerPath ) ) { if ( !pathToIndexMap.containsKey( innerPath ) ) {
@ -501,7 +501,7 @@ public class FTLPack extends AbstractPack {
for ( int i=0; i < tmpEntries.size(); i++ ) { for ( int i=0; i < tmpEntries.size(); i++ ) {
DatEntry entry = tmpEntries.get ( i ); DatEntry entry = tmpEntries.get ( i );
pathToIndexMap.put( entry.innerPath, new Integer( i ) ); pathToIndexMap.put( entry.innerPath, i );
// Write the header index. // Write the header index.
raf.seek( getHeaderIndexPosition( i ) ); raf.seek( getHeaderIndexPosition( i ) );

View file

@ -64,7 +64,7 @@ public class FileChannelRegionInputStream extends InputStream {
// Do an absolute get() from the buffer, // Do an absolute get() from the buffer,
// and interpret the byte as if it were unsigned. // 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++; intraPos++;
return result; return result;
} }

View file

@ -143,7 +143,7 @@ public class FolderPack extends AbstractPack {
* The location it represents is not guaranteed to exist. * The location it represents is not guaranteed to exist.
*/ */
public File getFile( String innerPath ) { public File getFile( String innerPath ) {
if ( innerPath.indexOf( "\\" ) != -1 ) { if ( innerPath.contains( "\\" ) ) {
throw new IllegalArgumentException( "InnerPath contains backslashes: "+ innerPath ); throw new IllegalArgumentException( "InnerPath contains backslashes: "+ innerPath );
} }
File tmpFile = new File( rootDir, innerPath ); File tmpFile = new File( rootDir, innerPath );

View file

@ -364,8 +364,8 @@ public class PkgPack extends AbstractPack {
raf.seek( 0 ); raf.seek( 0 );
raf.setLength( 0 ); raf.setLength( 0 );
for ( int i=0; i < signature.length; i++ ) { for ( int x : signature ) {
raf.writeByte( signature[i] ); raf.writeByte( x );
} }
writeBigUShort( HEADER_SIZE ); writeBigUShort( HEADER_SIZE );
writeBigUShort( ENTRY_SIZE ); writeBigUShort( ENTRY_SIZE );
@ -379,8 +379,8 @@ public class PkgPack extends AbstractPack {
raf.seek( 0 ); raf.seek( 0 );
// Check the file signature. // Check the file signature.
for ( int i=0; i < signature.length; i++ ) { for ( int x : signature ) {
if ( raf.readUnsignedByte() != signature[i] ) { if ( raf.readUnsignedByte() != x ) {
throw new IOException( "Unexpected file signature" ); throw new IOException( "Unexpected file signature" );
} }
} }
@ -438,7 +438,7 @@ public class PkgPack extends AbstractPack {
bigByteBuf.position( entry.innerPathOffset ); bigByteBuf.position( entry.innerPathOffset );
entry.innerPath = readNullTerminatedString( bigByteBuf ); 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 @Override
public void add( String innerPath, InputStream is ) throws IOException { public void add( String innerPath, InputStream is ) throws IOException {
if ( innerPath.indexOf( "\\" ) != -1 ) { if ( innerPath.contains( "\\" ) ) {
throw new IllegalArgumentException( "InnerPath contains backslashes: "+ innerPath ); throw new IllegalArgumentException( "InnerPath contains backslashes: "+ innerPath );
} }
if ( pathToIndexMap.containsKey( innerPath ) ) { if ( pathToIndexMap.containsKey( innerPath ) ) {
@ -664,7 +664,7 @@ public class PkgPack extends AbstractPack {
@Override @Override
public void remove( String innerPath ) throws FileNotFoundException, IOException { public void remove( String innerPath ) throws FileNotFoundException, IOException {
if ( innerPath.indexOf( "\\" ) != -1 ) { if ( innerPath.contains( "\\" ) ) {
throw new IllegalArgumentException( "InnerPath contains backslashes: "+ innerPath ); throw new IllegalArgumentException( "InnerPath contains backslashes: "+ innerPath );
} }
if ( !pathToIndexMap.containsKey( innerPath ) ) { if ( !pathToIndexMap.containsKey( innerPath ) ) {
@ -686,7 +686,7 @@ public class PkgPack extends AbstractPack {
@Override @Override
public boolean contains( String innerPath ) { public boolean contains( String innerPath ) {
if ( innerPath.indexOf( "\\" ) != -1 ) { if ( innerPath.contains( "\\" ) ) {
throw new IllegalArgumentException( "InnerPath contains backslashes: "+ innerPath ); throw new IllegalArgumentException( "InnerPath contains backslashes: "+ innerPath );
} }
return pathToIndexMap.containsKey( innerPath ); return pathToIndexMap.containsKey( innerPath );
@ -694,7 +694,7 @@ public class PkgPack extends AbstractPack {
@Override @Override
public InputStream getInputStream( String innerPath ) throws FileNotFoundException, IOException { public InputStream getInputStream( String innerPath ) throws FileNotFoundException, IOException {
if ( innerPath.indexOf( "\\" ) != -1 ) { if ( innerPath.contains( "\\" ) ) {
throw new IllegalArgumentException( "InnerPath contains backslashes: "+ innerPath ); throw new IllegalArgumentException( "InnerPath contains backslashes: "+ innerPath );
} }
if ( !pathToIndexMap.containsKey( innerPath ) ) { if ( !pathToIndexMap.containsKey( innerPath ) ) {
@ -805,8 +805,7 @@ public class PkgPack extends AbstractPack {
// Move data toward the top. // Move data toward the top.
long pendingDataOffset = neededMinDataOffset; long pendingDataOffset = neededMinDataOffset;
for ( int i=0; i < tmpEntries.size(); i++ ) { for ( PkgEntry entry : tmpEntries ) {
PkgEntry entry = tmpEntries.get ( i );
if ( pendingDataOffset != entry.dataOffset ) { if ( pendingDataOffset != entry.dataOffset ) {
long totalBytes = entry.dataSize; long totalBytes = entry.dataSize;
@ -838,7 +837,7 @@ public class PkgPack extends AbstractPack {
pathToIndexMap.clear(); pathToIndexMap.clear();
for ( PkgEntry entry : entryList ) { for ( PkgEntry entry : entryList ) {
pathToIndexMap.put( entry.innerPath, new Integer( pathToIndexMap.size() ) ); pathToIndexMap.put( entry.innerPath, pathToIndexMap.size() );
} }
// Update the header. // Update the header.

View file

@ -323,7 +323,7 @@ public class SloppyXMLParser {
int colNum = lineAndCol[1]; int colNum = lineAndCol[1];
String hint = ""; 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.)"; 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 ); SAXParseException cause = new SAXParseException( String.format( "At line %d, column %d: %s%s", lineNum, colNum, e.getMessage(), hint ), null, null, lineNum, colNum, e );

View file

@ -29,7 +29,7 @@ import net.vhati.modmanager.ui.RegexDocument;
public class FieldEditorPanel extends JPanel { 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<String, JTextArea> wrappedLabelMap = new HashMap<String, JTextArea>(); private Map<String, JTextArea> wrappedLabelMap = new HashMap<String, JTextArea>();
private Map<String, JLabel> labelMap = new HashMap<String, JLabel>(); private Map<String, JLabel> labelMap = new HashMap<String, JLabel>();