Clean up single char indexOf()

This commit is contained in:
zzz
2016-12-02 18:52:37 +00:00
parent 5b31540fe8
commit 5be077e25d
29 changed files with 51 additions and 51 deletions

View File

@ -165,7 +165,7 @@ public class BOB implements Runnable, ClientApp {
if (classResource != null) {
String classPath = classResource.toString();
if (classPath.startsWith("jar")) {
String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) +
String manifestPath = classPath.substring(0, classPath.lastIndexOf('!') + 1) +
"/META-INF/MANIFEST.MF";
try {
Manifest manifest = new Manifest(new URL(manifestPath).openStream());

View File

@ -76,7 +76,7 @@ class HostTxtParser {
public static HostTxtEntry parse(String inputLine, boolean allowCommandOnly) {
if (inputLine.startsWith(";"))
return null;
int comment = inputLine.indexOf("#");
int comment = inputLine.indexOf('#');
String kv;
String sprops;
if (comment >= 0) {

View File

@ -958,7 +958,7 @@ public class TrackerClient implements Runnable {
{
announce = a;
String s = a.substring(7);
host = s.substring(0, s.indexOf("/"));
host = s.substring(0, s.indexOf('/'));
isPrimary = p;
interval = INITIAL_SLEEP;
}

View File

@ -1466,7 +1466,7 @@ public class I2PSnarkServlet extends BasicServlet {
String fullBasename = basename;
if (basename.length() > MAX_DISPLAYED_FILENAME_LENGTH) {
String start = basename.substring(0, MAX_DISPLAYED_FILENAME_LENGTH);
if (start.indexOf(" ") < 0 && start.indexOf("-") < 0) {
if (start.indexOf(' ') < 0 && start.indexOf('-') < 0) {
// browser has nowhere to break it
basename = start + HELLIP;
}
@ -3086,7 +3086,7 @@ public class I2PSnarkServlet extends BasicServlet {
: tx + ": " + directory);
if (showSort)
buf.append("</a>");
int dirSlash = directory.indexOf("/");
int dirSlash = directory.indexOf('/');
if (dirSlash > 0) {
buf.append("&nbsp;");
buf.append(DataHelper.escapeHTML(directory.substring(dirSlash + 1)));

View File

@ -96,7 +96,7 @@ public class InclusiveByteRange
long first = -1;
long last = -1;
int d = t.indexOf('-');
if (d < 0 || t.indexOf("-",d + 1) >= 0)
if (d < 0 || t.indexOf('-',d + 1) >= 0)
{
if ("bytes".equals(t))
continue;

View File

@ -105,7 +105,7 @@ class MimeTypes
int i=-1;
while(type==null)
{
i=filename.indexOf(".",i+1);
i=filename.indexOf('.',i+1);
if (i<0 || i>=filename.length())
break;

View File

@ -380,8 +380,8 @@ public class I2PTunnel extends EventDispatcherImpl implements Logging {
}
public void runCommand(String cmd, Logging l) {
if (cmd.indexOf(" ") == -1) cmd += " ";
int iii = cmd.indexOf(" ");
if (cmd.indexOf(' ') == -1) cmd += ' ';
int iii = cmd.indexOf(' ');
String cmdname = cmd.substring(0, iii).toLowerCase(Locale.US);
String allargs = cmd.substring(iii + 1);
String[] args = split(allargs, " "); // .split(" "); // java 1.4

View File

@ -166,14 +166,14 @@ public class I2PTunnelConnectClient extends I2PTunnelHTTPClientBase implements R
_log.debug(getPrefix(requestId) + "Line=[" + line + "]");
if (method == null) { // first line CONNECT blah.i2p:80 HTTP/1.1
int pos = line.indexOf(" ");
int pos = line.indexOf(' ');
if (pos == -1) break; // empty first line
method = line.substring(0, pos);
String request = line.substring(pos + 1);
pos = request.indexOf(":");
pos = request.indexOf(':');
if (pos == -1)
pos = request.indexOf(" ");
pos = request.indexOf(' ');
if (pos == -1) {
host = request;
restofline = "";
@ -185,7 +185,7 @@ public class I2PTunnelConnectClient extends I2PTunnelHTTPClientBase implements R
if (host.toLowerCase(Locale.US).endsWith(".i2p")) {
// Destination gets the host name
destination = host;
} else if (host.indexOf(".") != -1) {
} else if (host.indexOf('.') != -1) {
// The request must be forwarded to a outproxy
currentProxy = selectProxy();
if (currentProxy == null) {

View File

@ -430,7 +430,7 @@ public class I2PTunnelServer extends I2PTunnelTask implements Runnable {
try {
int myPort = Integer.parseInt(key);
String host = (String) e.getValue();
int colon = host.indexOf(":");
int colon = host.indexOf(':');
int port = Integer.parseInt(host.substring(colon + 1));
host = host.substring(0, colon);
InetSocketAddress isa = new InetSocketAddress(host, port);

View File

@ -167,8 +167,8 @@ public class I2Ping extends I2PTunnelClientBase {
if (line.startsWith("#")) continue; // comments
if (line.startsWith(";")) continue;
if (line.startsWith("!")) continue;
if (line.indexOf("=") != -1) { // maybe file is hosts.txt?
line = line.substring(0, line.indexOf("="));
if (line.indexOf('=') != -1) { // maybe file is hosts.txt?
line = line.substring(0, line.indexOf('='));
}
PingHandler ph = new PingHandler(line, count, localPort, remotePort,
timeout, countPing, reportTimes);

View File

@ -380,7 +380,7 @@ abstract class IRCFilter {
if("USER".equals(command)) {
if (field.length < 3)
return s; // invalid, allow server response
int idx = field[2].lastIndexOf(":");
int idx = field[2].lastIndexOf(':');
if(idx<0)
return "USER user hostname localhost :realname";
String realname = field[2].substring(idx+1);

View File

@ -139,7 +139,7 @@ public class RequestWrapper {
String key = e.getKey();
if( key.toLowerCase(Locale.US).compareToIgnoreCase( "content-type") == 0 ) {
String value = e.getValue();
int i = value.indexOf( ";" );
int i = value.indexOf( ';' );
if( i != -1 )
result = value.substring( 0, i );
else

View File

@ -31,7 +31,7 @@ public class I2PSocketAddress extends SocketAddress {
*/
public I2PSocketAddress(String host) {
int port = 0;
int colon = host.indexOf(":");
int colon = host.indexOf(':');
if (colon > 0) {
try {
port = Integer.parseInt(host.substring(colon + 1));

View File

@ -128,7 +128,7 @@ public class I2PSocketEepGet extends EepGet {
if ("i2p".equals(host)) {
String file = url.getRawPath();
try {
int slash = 1 + file.substring(1).indexOf("/");
int slash = 1 + file.substring(1).indexOf('/');
host = file.substring(1, slash);
_actualURL = "http://" + host + file.substring(slash);
String query = url.getRawQuery();

View File

@ -370,9 +370,9 @@ class PluginUpdateRunner extends UpdateRunner {
String appName = props.getProperty("name");
String version = props.getProperty("version");
if (appName == null || version == null || appName.length() <= 0 || version.length() <= 0 ||
appName.indexOf("<") >= 0 || appName.indexOf(">") >= 0 ||
version.indexOf("<") >= 0 || version.indexOf(">") >= 0 ||
appName.startsWith(".") || appName.indexOf("/") >= 0 || appName.indexOf("\\") >= 0) {
appName.indexOf('<') >= 0 || appName.indexOf('>') >= 0 ||
version.indexOf('<') >= 0 || version.indexOf('>') >= 0 ||
appName.startsWith(".") || appName.indexOf('/') >= 0 || appName.indexOf('\\') >= 0) {
to.delete();
statusDone("<b>" + _t("Plugin from {0} has invalid name or version", url) + "</b>");
return;

View File

@ -246,7 +246,7 @@ public class ConfigClientsHandler extends FormHandler {
isAdvanced()) {
String desc = getJettyString("nofilter_desc" + cur);
if (desc != null) {
int spc = desc.indexOf(" ");
int spc = desc.indexOf(' ');
String clss = desc;
String args = null;
if (spc >= 0) {
@ -267,7 +267,7 @@ public class ConfigClientsHandler extends FormHandler {
String newDesc = getJettyString("nofilter_desc" + newClient);
if (newDesc != null && newDesc.trim().length() > 0) {
// new entry
int spc = newDesc.indexOf(" ");
int spc = newDesc.indexOf(' ');
String clss = newDesc;
String args = null;
if (spc >= 0) {

View File

@ -250,7 +250,7 @@ public class ConfigClientsHelper extends HelperBase {
.append(_t("Signed by")).append("</b></td><td>");
String s = stripHTML(appProps, "signer");
if (s != null) {
if (s.indexOf("@") > 0)
if (s.indexOf('@') > 0)
desc.append("<a href=\"mailto:").append(s).append("\">").append(s).append("</a>");
else
desc.append(s);
@ -271,7 +271,7 @@ public class ConfigClientsHelper extends HelperBase {
if (s != null) {
desc.append("<tr><td><b>")
.append(_t("Author")).append("</b></td><td>");
if (s.indexOf("@") > 0)
if (s.indexOf('@') > 0)
desc.append("<a href=\"mailto:").append(s).append("\">").append(s).append("</a>");
else
desc.append(s);

View File

@ -61,7 +61,7 @@ public class LocaleWebAppHandler extends HandlerWrapper
if (pathInContext.equals("/") || pathInContext.equals("/index.html")) {
// home page
pathInContext = "/index.jsp";
} else if (pathInContext.indexOf("/", 1) < 0 &&
} else if (pathInContext.indexOf('/', 1) < 0 &&
(!pathInContext.endsWith(".jsp")) &&
(!pathInContext.endsWith(".log")) &&
(!pathInContext.endsWith(".txt"))) {

View File

@ -725,7 +725,7 @@ public class PluginStarter implements Runnable {
// argument array comparison in getClientApp() works.
// Do this after parsing so we don't need to worry about quoting
for (int i = 0; i < argVal.length; i++) {
if (argVal[i].indexOf("$") >= 0) {
if (argVal[i].indexOf('$') >= 0) {
argVal[i] = argVal[i].replace("$I2P", ctx.getBaseDir().getAbsolutePath());
argVal[i] = argVal[i].replace("$CONFIG", ctx.getConfigDir().getAbsolutePath());
argVal[i] = argVal[i].replace("$PLUGIN", pluginDir.getAbsolutePath());
@ -764,7 +764,7 @@ public class PluginStarter implements Runnable {
}
// do this after parsing so we don't need to worry about quoting
for (int i = 0; i < argVal.length; i++) {
if (argVal[i].indexOf("$") >= 0) {
if (argVal[i].indexOf('$') >= 0) {
argVal[i] = argVal[i].replace("$I2P", ctx.getBaseDir().getAbsolutePath());
argVal[i] = argVal[i].replace("$CONFIG", ctx.getConfigDir().getAbsolutePath());
argVal[i] = argVal[i].replace("$PLUGIN", pluginDir.getAbsolutePath());
@ -774,7 +774,7 @@ public class PluginStarter implements Runnable {
ClassLoader cl = null;
if (app.classpath != null) {
String cp = app.classpath;
if (cp.indexOf("$") >= 0) {
if (cp.indexOf('$') >= 0) {
cp = cp.replace("$I2P", ctx.getBaseDir().getAbsolutePath());
cp = cp.replace("$CONFIG", ctx.getConfigDir().getAbsolutePath());
cp = cp.replace("$PLUGIN", pluginDir.getAbsolutePath());

View File

@ -52,7 +52,7 @@ class ProfileOrganizerRenderer {
continue;
if (mode == 2) {
RouterInfo info = _context.netDb().lookupRouterInfoLocally(peer);
if (info != null && info.getCapabilities().indexOf("f") >= 0)
if (info != null && info.getCapabilities().indexOf('f') >= 0)
order.add(prof);
continue;
}

View File

@ -172,7 +172,7 @@ class SAMHandlerFactory {
private static int getMajor(String ver) {
if (ver == null)
return -1;
int dot = ver.indexOf(".");
int dot = ver.indexOf('.');
if (dot == 0)
return -1;
if (dot > 0)
@ -189,7 +189,7 @@ class SAMHandlerFactory {
if ( (ver == null) || (ver.indexOf('.') < 0) )
return -1;
try {
String major = ver.substring(ver.indexOf(".") + 1);
String major = ver.substring(ver.indexOf('.') + 1);
return Integer.parseInt(major);
} catch (NumberFormatException e) {
return -1;

View File

@ -187,8 +187,8 @@ class Mail {
address = address.trim();
if( address.indexOf( "\n" ) != -1 ||
address.indexOf( "\r" ) != -1 )
if( address.indexOf('\n') != -1 ||
address.indexOf('\r') != -1 )
return false;
String[] tokens = DataHelper.split(address, "[ \t]+");

View File

@ -213,7 +213,7 @@ class MailPart {
String result = null;
int i = line.indexOf( ": " );
if( i != - 1 ) {
int j = line.indexOf( ";", i + 2 );
int j = line.indexOf(';', i + 2 );
if( j == -1 )
result = line.substring( i + 2 );
else
@ -234,11 +234,11 @@ class MailPart {
if( i == -1 )
break;
h = i + l;
int j = line.indexOf( "=", i + l );
int j = line.indexOf('=', i + l );
// System.err.println( "j=" + j );
if( j != -1 ) {
int k = line.indexOf( "\"", j + 1 );
int m = line.indexOf( ";", j + 1 );
int k = line.indexOf('"', j + 1 );
int m = line.indexOf(';', j + 1 );
// System.err.println( "k=" + k );
if( k != -1 && ( m == -1 || k < m ) ) {
/*
@ -249,7 +249,7 @@ class MailPart {
m = -1;
int k2 = k + 1;
while( true ) {
m = line.indexOf( "\"", k2 );
m = line.indexOf('"', k2 );
// System.err.println( "m=" + m + " '" + line.substring( m ) + "'" );
if( m == -1 ) {
break;

View File

@ -1197,10 +1197,10 @@ public class WebMail extends HttpServlet
if (filename != null &&
(buttonPressed(request, NEW_UPLOAD) || buttonPressed(request, SEND))) {
Debug.debug(Debug.DEBUG, "Got filename in compose form: " + filename);
int i = filename.lastIndexOf( "/" );
int i = filename.lastIndexOf('/');
if( i != - 1 )
filename = filename.substring( i + 1 );
i = filename.lastIndexOf( "\\" );
i = filename.lastIndexOf('\\');
if( i != -1 )
filename = filename.substring( i + 1 );
if( filename != null && filename.length() > 0 ) {

View File

@ -490,7 +490,7 @@ public class POP3MailBox implements NewMailListener {
}
response = response.trim();
try {
int i = response.indexOf(" ", 5);
int i = response.indexOf(' ', 5);
mails =
Integer.parseInt(
i != -1
@ -510,7 +510,7 @@ public class POP3MailBox implements NewMailListener {
uidlToID.clear();
if (lines != null) {
for (String line : lines) {
int j = line.indexOf( " " );
int j = line.indexOf(' ');
if( j != -1 ) {
try {
int n = Integer.parseInt( line.substring( 0, j ) );
@ -541,7 +541,7 @@ public class POP3MailBox implements NewMailListener {
sizes.clear();
if (lines != null) {
for (String line : lines) {
int j = line.indexOf(" ");
int j = line.indexOf(' ');
if (j != -1) {
try {
int key = Integer.parseInt(line.substring(0, j));

View File

@ -117,7 +117,7 @@ public class HostTxtEntry {
String[] entries = DataHelper.split(line, "#");
for (int i = 0; i < entries.length; i++) {
String kv = entries[i];
int eq = kv.indexOf("=");
int eq = kv.indexOf('=');
if (eq <= 0 || eq == kv.length() - 1)
throw new IllegalArgumentException("No value: \"" + kv + '"');
String k = kv.substring(0, eq);

View File

@ -190,7 +190,7 @@ public abstract class Addresses {
* @since IPv6
*/
private static String stripScope(String ip) {
int pct = ip.indexOf("%");
int pct = ip.indexOf('%');
if (pct > 0)
ip = ip.substring(0, pct);
return ip;

View File

@ -58,7 +58,7 @@ public class CommandLine {
protected static void exec(String args[], List<String> classes) {
String cmd = args[0].toLowerCase(Locale.US);
for (String cls : classes) {
String ccmd = cls.substring(cls.lastIndexOf(".") + 1).toLowerCase(Locale.US);
String ccmd = cls.substring(cls.lastIndexOf('.') + 1).toLowerCase(Locale.US);
if (cmd.equals(ccmd)) {
try {
String[] cargs = new String[args.length - 1];
@ -85,7 +85,7 @@ public class CommandLine {
System.err.println("Available commands:");
List<String> cmds = new ArrayList<String>(classes.size());
for (String cls : classes) {
String ccmd = cls.substring(cls.lastIndexOf(".") + 1).toLowerCase(Locale.US);
String ccmd = cls.substring(cls.lastIndexOf('.') + 1).toLowerCase(Locale.US);
cmds.add(ccmd);
}
Collections.sort(cmds);

View File

@ -170,7 +170,7 @@ class FloodfillMonitorJob extends JobImpl {
if (wasFF)
ffcount++;
int good = ffcount - failcount;
boolean happy = getContext().router().getRouterInfo().getCapabilities().indexOf("R") >= 0;
boolean happy = getContext().router().getRouterInfo().getCapabilities().indexOf('R') >= 0;
// TODO - limit may still be too high
// For reference, the avg lifetime job lag on my Pi is 6.
// Should we consider avg. dropped ff jobs?