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