Use Java 5 enhanced 'for' loops.
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1407076 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7201c0c216
commit
20de472dd7
|
@ -252,16 +252,16 @@ public class URIUtils {
|
|||
}
|
||||
String[] inputSegments = path.split("/");
|
||||
Stack<String> outputSegments = new Stack<String>();
|
||||
for (int i = 0; i < inputSegments.length; i++) {
|
||||
if ((inputSegments[i].length() == 0)
|
||||
|| (".".equals(inputSegments[i]))) {
|
||||
for (String inputSegment : inputSegments) {
|
||||
if ((inputSegment.length() == 0)
|
||||
|| (".".equals(inputSegment))) {
|
||||
// Do nothing
|
||||
} else if ("..".equals(inputSegments[i])) {
|
||||
} else if ("..".equals(inputSegment)) {
|
||||
if (!outputSegments.isEmpty()) {
|
||||
outputSegments.pop();
|
||||
}
|
||||
} else {
|
||||
outputSegments.push(inputSegments[i]);
|
||||
outputSegments.push(inputSegment);
|
||||
}
|
||||
}
|
||||
StringBuilder outputBuffer = new StringBuilder();
|
||||
|
|
|
@ -358,8 +358,8 @@ public final class HttpRoute implements RouteInfo, Cloneable {
|
|||
int hash = LangUtils.HASH_SEED;
|
||||
hash = LangUtils.hashCode(hash, this.targetHost);
|
||||
hash = LangUtils.hashCode(hash, this.localAddress);
|
||||
for (int i = 0; i < this.proxyChain.length; i++) {
|
||||
hash = LangUtils.hashCode(hash, this.proxyChain[i]);
|
||||
for (HttpHost element : this.proxyChain) {
|
||||
hash = LangUtils.hashCode(hash, element);
|
||||
}
|
||||
hash = LangUtils.hashCode(hash, this.secure);
|
||||
hash = LangUtils.hashCode(hash, this.tunnelled);
|
||||
|
|
|
@ -329,8 +329,8 @@ public final class RouteTracker implements RouteInfo, Cloneable {
|
|||
hash = LangUtils.hashCode(hash, this.targetHost);
|
||||
hash = LangUtils.hashCode(hash, this.localAddress);
|
||||
if (this.proxyChain != null) {
|
||||
for (int i = 0; i < this.proxyChain.length; i++) {
|
||||
hash = LangUtils.hashCode(hash, this.proxyChain[i]);
|
||||
for (HttpHost element : this.proxyChain) {
|
||||
hash = LangUtils.hashCode(hash, element);
|
||||
}
|
||||
}
|
||||
hash = LangUtils.hashCode(hash, this.connected);
|
||||
|
@ -365,8 +365,8 @@ public final class RouteTracker implements RouteInfo, Cloneable {
|
|||
cab.append('s');
|
||||
cab.append("}->");
|
||||
if (this.proxyChain != null) {
|
||||
for (int i=0; i<this.proxyChain.length; i++) {
|
||||
cab.append(this.proxyChain[i]);
|
||||
for (HttpHost element : this.proxyChain) {
|
||||
cab.append(element);
|
||||
cab.append("->");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -709,8 +709,8 @@ final class NTLMEngineImpl implements NTLMEngine {
|
|||
* the bytes to add.
|
||||
*/
|
||||
protected void addBytes(byte[] bytes) {
|
||||
for (int i = 0; i < bytes.length; i++) {
|
||||
messageContents[currentOutputPosition] = bytes[i];
|
||||
for (byte b : bytes) {
|
||||
messageContents[currentOutputPosition] = b;
|
||||
currentOutputPosition++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -92,8 +92,8 @@ public class RFC2965PortAttributeHandler implements CookieAttributeHandler {
|
|||
*/
|
||||
private static boolean portMatch(int port, int[] ports) {
|
||||
boolean portInList = false;
|
||||
for (int i = 0, len = ports.length; i < len; i++) {
|
||||
if (port == ports[i]) {
|
||||
for (int port2 : ports) {
|
||||
if (port == port2) {
|
||||
portInList = true;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -194,8 +194,8 @@ public class TestURLEncodedUtils {
|
|||
private static String constructString(int [] unicodeChars) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
if (unicodeChars != null) {
|
||||
for (int i = 0; i < unicodeChars.length; i++) {
|
||||
buffer.append((char)unicodeChars[i]);
|
||||
for (int unicodeChar : unicodeChars) {
|
||||
buffer.append((char)unicodeChar);
|
||||
}
|
||||
}
|
||||
return buffer.toString();
|
||||
|
|
|
@ -58,8 +58,8 @@ public class TestBasicScheme {
|
|||
public void testBasicAuthenticationWith88591Chars() throws Exception {
|
||||
int[] germanChars = { 0xE4, 0x2D, 0xF6, 0x2D, 0xFc };
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
for (int i = 0; i < germanChars.length; i++) {
|
||||
buffer.append((char)germanChars[i]);
|
||||
for (int germanChar : germanChars) {
|
||||
buffer.append((char)germanChar);
|
||||
}
|
||||
|
||||
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("dh", buffer.toString());
|
||||
|
|
|
@ -421,8 +421,7 @@ public class TestDigestScheme {
|
|||
}
|
||||
HeaderElement[] elements = BasicHeaderValueParser.parseElements(s.substring(7), null);
|
||||
Map<String, String> map = new HashMap<String, String>(elements.length);
|
||||
for (int i = 0; i < elements.length; i++) {
|
||||
HeaderElement element = elements[i];
|
||||
for (HeaderElement element : elements) {
|
||||
map.put(element.getName(), element.getValue());
|
||||
}
|
||||
return map;
|
||||
|
|
|
@ -95,13 +95,11 @@ public class TestConnectionReuse {
|
|||
10, false);
|
||||
}
|
||||
|
||||
for (int i = 0; i < workers.length; i++) {
|
||||
WorkerThread worker = workers[i];
|
||||
for (WorkerThread worker : workers) {
|
||||
worker.start();
|
||||
}
|
||||
for (int i = 0; i < workers.length; i++) {
|
||||
WorkerThread worker = workers[i];
|
||||
workers[i].join(10000);
|
||||
for (WorkerThread worker : workers) {
|
||||
worker.join(10000);
|
||||
Exception ex = worker.getException();
|
||||
if (ex != null) {
|
||||
throw ex;
|
||||
|
@ -155,13 +153,11 @@ public class TestConnectionReuse {
|
|||
10, false);
|
||||
}
|
||||
|
||||
for (int i = 0; i < workers.length; i++) {
|
||||
WorkerThread worker = workers[i];
|
||||
for (WorkerThread worker : workers) {
|
||||
worker.start();
|
||||
}
|
||||
for (int i = 0; i < workers.length; i++) {
|
||||
WorkerThread worker = workers[i];
|
||||
workers[i].join(10000);
|
||||
for (WorkerThread worker : workers) {
|
||||
worker.join(10000);
|
||||
Exception ex = worker.getException();
|
||||
if (ex != null) {
|
||||
throw ex;
|
||||
|
@ -205,13 +201,11 @@ public class TestConnectionReuse {
|
|||
10, true);
|
||||
}
|
||||
|
||||
for (int i = 0; i < workers.length; i++) {
|
||||
WorkerThread worker = workers[i];
|
||||
for (WorkerThread worker : workers) {
|
||||
worker.start();
|
||||
}
|
||||
for (int i = 0; i < workers.length; i++) {
|
||||
WorkerThread worker = workers[i];
|
||||
workers[i].join(10000);
|
||||
for (WorkerThread worker : workers) {
|
||||
worker.join(10000);
|
||||
Exception ex = worker.getException();
|
||||
if (ex != null) {
|
||||
throw ex;
|
||||
|
|
|
@ -72,12 +72,12 @@ public class TestIdleConnectionEviction extends LocalServerTestBase {
|
|||
for (int i = 0; i < workers.length; i++) {
|
||||
workers[i] = new WorkerThread(httpclient, target, httpget, 200);
|
||||
}
|
||||
for (int i = 0; i < workers.length; i++) {
|
||||
workers[i].start();
|
||||
for (WorkerThread worker : workers) {
|
||||
worker.start();
|
||||
}
|
||||
for (int i = 0; i < workers.length; i++) {
|
||||
workers[i].join();
|
||||
Exception ex = workers[i].getException();
|
||||
for (WorkerThread worker : workers) {
|
||||
worker.join();
|
||||
Exception ex = worker.getException();
|
||||
if (ex != null) {
|
||||
throw ex;
|
||||
}
|
||||
|
|
|
@ -119,22 +119,21 @@ public class TestStatefulConnManagement extends IntegrationTestBase {
|
|||
context, requestCount, target, this.httpclient);
|
||||
}
|
||||
|
||||
for (int i = 0; i < workers.length; i++) {
|
||||
workers[i].start();
|
||||
for (HttpWorker worker : workers) {
|
||||
worker.start();
|
||||
}
|
||||
for (int i = 0; i < workers.length; i++) {
|
||||
workers[i].join(10000);
|
||||
for (HttpWorker worker : workers) {
|
||||
worker.join(10000);
|
||||
}
|
||||
for (int i = 0; i < workers.length; i++) {
|
||||
Exception ex = workers[i].getException();
|
||||
for (HttpWorker worker : workers) {
|
||||
Exception ex = worker.getException();
|
||||
if (ex != null) {
|
||||
throw ex;
|
||||
}
|
||||
Assert.assertEquals(requestCount, workers[i].getCount());
|
||||
Assert.assertEquals(requestCount, worker.getCount());
|
||||
}
|
||||
|
||||
for (int i = 0; i < contexts.length; i++) {
|
||||
HttpContext context = contexts[i];
|
||||
for (HttpContext context : contexts) {
|
||||
String uid = (String) context.getAttribute("user");
|
||||
|
||||
for (int r = 0; r < requestCount; r++) {
|
||||
|
|
|
@ -65,11 +65,11 @@ public class ConnPoolBench {
|
|||
workers[i] = new WorkerThread1(pool, reps);
|
||||
}
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < workers.length; i++) {
|
||||
workers[i].start();
|
||||
for (WorkerThread1 worker : workers) {
|
||||
worker.start();
|
||||
}
|
||||
for (int i = 0; i < workers.length; i++) {
|
||||
workers[i].join();
|
||||
for (WorkerThread1 worker : workers) {
|
||||
worker.join();
|
||||
}
|
||||
long finish = System.currentTimeMillis();
|
||||
float totalTimeSec = (float) (finish - start) / 1000;
|
||||
|
@ -93,11 +93,11 @@ public class ConnPoolBench {
|
|||
workers[i] = new WorkerThread2(pool, reps);
|
||||
}
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < workers.length; i++) {
|
||||
workers[i].start();
|
||||
for (WorkerThread2 worker : workers) {
|
||||
worker.start();
|
||||
}
|
||||
for (int i = 0; i < workers.length; i++) {
|
||||
workers[i].join();
|
||||
for (WorkerThread2 worker : workers) {
|
||||
worker.join();
|
||||
}
|
||||
long finish = System.currentTimeMillis();
|
||||
float totalTimeSec = (float) (finish - start) / 1000;
|
||||
|
|
|
@ -33,7 +33,6 @@ import java.net.ServerSocket;
|
|||
import java.net.Socket;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
|
@ -281,8 +280,7 @@ public class LocalTestServer {
|
|||
t.shutdown();
|
||||
}
|
||||
synchronized (workers) {
|
||||
for (Iterator<Worker> it = workers.iterator(); it.hasNext(); ) {
|
||||
Worker worker = it.next();
|
||||
for (Worker worker : workers) {
|
||||
worker.shutdown();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -215,8 +215,8 @@ public class TestMultipartForm {
|
|||
private static String constructString(int [] unicodeChars) {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
if (unicodeChars != null) {
|
||||
for (int i = 0; i < unicodeChars.length; i++) {
|
||||
buffer.append((char)unicodeChars[i]);
|
||||
for (int unicodeChar : unicodeChars) {
|
||||
buffer.append((char)unicodeChar);
|
||||
}
|
||||
}
|
||||
return buffer.toString();
|
||||
|
|
Loading…
Reference in New Issue