You are viewing a plain text version of this content. The canonical link for it is here.
Posted to droids-commits@incubator.apache.org by bc...@apache.org on 2011/02/21 17:13:17 UTC

svn commit: r1073071 - in /incubator/droids/trunk/droids-core: ./ src/main/java/org/apache/droids/protocol/http/ src/main/java/org/apache/droids/robot/crawler/ src/main/java/org/apache/droids/robot/walker/ src/test/java/org/apache/droids/examples/ src/...

Author: bchapuis
Date: Mon Feb 21 17:13:17 2011
New Revision: 1073071

URL: http://svn.apache.org/viewvc?rev=1073071&view=rev
Log:
DROIDS-106: Introduce Guava (the former google collections) into the droids project. Thanks to Eugen Paraschiv who provided the patch.

Modified:
    incubator/droids/trunk/droids-core/pom.xml
    incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/protocol/http/DroidHttpEntity.java
    incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/protocol/http/DroidsRequestRetryHandler.java
    incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/robot/crawler/CrawlingDroid.java
    incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/robot/walker/SimpleWalkingDroid.java
    incubator/droids/trunk/droids-core/src/test/java/org/apache/droids/examples/FileRenameDroid.java
    incubator/droids/trunk/droids-core/src/test/java/org/apache/droids/localserver/LocalHttpServer.java

Modified: incubator/droids/trunk/droids-core/pom.xml
URL: http://svn.apache.org/viewvc/incubator/droids/trunk/droids-core/pom.xml?rev=1073071&r1=1073070&r2=1073071&view=diff
==============================================================================
--- incubator/droids/trunk/droids-core/pom.xml (original)
+++ incubator/droids/trunk/droids-core/pom.xml Mon Feb 21 17:13:17 2011
@@ -76,6 +76,11 @@
       <groupId>net.sourceforge.nekohtml</groupId>
       <artifactId>nekohtml</artifactId>
     </dependency>
+    <dependency>
+      <groupId>com.google.guava</groupId>
+      <artifactId>guava</artifactId>
+      <version>r07</version>
+    </dependency>
     
     <!-- TEST -->
     <dependency>

Modified: incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/protocol/http/DroidHttpEntity.java
URL: http://svn.apache.org/viewvc/incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/protocol/http/DroidHttpEntity.java?rev=1073071&r1=1073070&r2=1073071&view=diff
==============================================================================
--- incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/protocol/http/DroidHttpEntity.java (original)
+++ incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/protocol/http/DroidHttpEntity.java Mon Feb 21 17:13:17 2011
@@ -21,6 +21,8 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 
+import com.google.common.base.Preconditions;
+
 import org.apache.http.HttpEntity;
 import org.apache.http.entity.HttpEntityWrapper;
 import org.apache.http.util.ByteArrayBuffer;
@@ -94,10 +96,7 @@ class DroidHttpEntity extends HttpEntity
 
   public void writeTo(final OutputStream outstream) throws IOException
   {
-    if (outstream == null)
-    {
-      throw new IllegalArgumentException("Output stream may not be null");
-    }
+    Preconditions.checkArgument( outstream != null, "Output stream may not be null" );
     if (this.buffer != null)
     {
       outstream.write(this.buffer);

Modified: incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/protocol/http/DroidsRequestRetryHandler.java
URL: http://svn.apache.org/viewvc/incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/protocol/http/DroidsRequestRetryHandler.java?rev=1073071&r1=1073070&r2=1073071&view=diff
==============================================================================
--- incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/protocol/http/DroidsRequestRetryHandler.java (original)
+++ incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/protocol/http/DroidsRequestRetryHandler.java Mon Feb 21 17:13:17 2011
@@ -22,6 +22,8 @@ import java.io.InterruptedIOException;
 
 import javax.net.ssl.SSLHandshakeException;
 
+import com.google.common.base.Preconditions;
+
 import org.apache.http.NoHttpResponseException;
 import org.apache.http.client.HttpRequestRetryHandler;
 import org.apache.http.conn.HttpHostConnectException;
@@ -46,12 +48,9 @@ class DroidsRequestRetryHandler implemen
   public boolean retryRequest(final IOException exception, int executionCount,
       final HttpContext context)
   {
-    if (exception == null) {
-      throw new IllegalArgumentException("Exception parameter may not be null");
-    }
-    if (context == null) {
-      throw new IllegalArgumentException("HTTP context may not be null");
-    }
+    Preconditions.checkArgument(exception != null, "Exception parameter may not be null" );
+    Preconditions.checkArgument(context != null, "HTTP context may not be null" );
+    
     if (executionCount > this.retryCount) {
       // Do not retry if over max retry count
       return false;

Modified: incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/robot/crawler/CrawlingDroid.java
URL: http://svn.apache.org/viewvc/incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/robot/crawler/CrawlingDroid.java?rev=1073071&r1=1073070&r2=1073071&view=diff
==============================================================================
--- incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/robot/crawler/CrawlingDroid.java (original)
+++ incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/robot/crawler/CrawlingDroid.java Mon Feb 21 17:13:17 2011
@@ -20,6 +20,8 @@ import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.Collection;
 
+import com.google.common.base.Preconditions;
+
 import org.apache.droids.AbstractDroid;
 import org.apache.droids.LinkTask;
 import org.apache.droids.api.Link;
@@ -49,9 +51,8 @@ public abstract class CrawlingDroid exte
   }
   
   public void init() throws InvalidTaskException {
-    if( initialLocations == null || initialLocations.isEmpty() ) {
-      throw new IllegalStateException( "WebCrawlerDroid requires at least one starting file" );
-    }
+    Preconditions.checkState( initialLocations != null, "WebCrawlerDroid requires at least one starting file" );
+    Preconditions.checkState( !initialLocations.isEmpty(), "WebCrawlerDroid requires at least one starting file" );
     for( String location : initialLocations ) {
       URI uri;
       try {

Modified: incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/robot/walker/SimpleWalkingDroid.java
URL: http://svn.apache.org/viewvc/incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/robot/walker/SimpleWalkingDroid.java?rev=1073071&r1=1073070&r2=1073071&view=diff
==============================================================================
--- incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/robot/walker/SimpleWalkingDroid.java (original)
+++ incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/robot/walker/SimpleWalkingDroid.java Mon Feb 21 17:13:17 2011
@@ -21,6 +21,8 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.concurrent.TimeUnit;
 
+import com.google.common.base.Preconditions;
+
 import org.apache.droids.AbstractDroid;
 import org.apache.droids.exception.InvalidTaskException;
 import org.apache.droids.impl.MultiThreadedTaskMaster;
@@ -41,9 +43,8 @@ public class SimpleWalkingDroid extends 
   }
   
   public void init() throws InvalidTaskException {
-    if( initialFiles == null || initialFiles.isEmpty() ) {
-      throw new IllegalStateException( "FileSystemWalker requires at least one starting file" );
-    }
+    Preconditions.checkState(initialFiles != null, "FileSystemWalker requires at least one starting file" );
+    Preconditions.checkState( !initialFiles.isEmpty(), "FileSystemWalker requires at least one starting file" );
     for( File file : initialFiles ) {
       queue.merge( new FileTask( file, 0 ) );
     }

Modified: incubator/droids/trunk/droids-core/src/test/java/org/apache/droids/examples/FileRenameDroid.java
URL: http://svn.apache.org/viewvc/incubator/droids/trunk/droids-core/src/test/java/org/apache/droids/examples/FileRenameDroid.java?rev=1073071&r1=1073070&r2=1073071&view=diff
==============================================================================
--- incubator/droids/trunk/droids-core/src/test/java/org/apache/droids/examples/FileRenameDroid.java (original)
+++ incubator/droids/trunk/droids-core/src/test/java/org/apache/droids/examples/FileRenameDroid.java Mon Feb 21 17:13:17 2011
@@ -21,6 +21,8 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.LinkedHashMap;
 
+import com.google.common.base.Preconditions;
+
 import org.apache.droids.AbstractDroid;
 import org.apache.droids.api.*;
 import org.apache.droids.exception.InvalidTaskException;
@@ -46,9 +48,8 @@ public class FileRenameDroid extends Abs
   }
   
   public void init() {
-    if( initialFiles == null || initialFiles.isEmpty() ) {
-      throw new RuntimeException( "FileSystemWalker requires at least one starting file" );
-    }
+    Preconditions.checkNotNull(initialFiles);
+    Preconditions.checkState( !initialFiles.isEmpty() );
     try {
       for( File file : initialFiles ) {
         queue.merge( new FileTask( file, 0 ) );

Modified: incubator/droids/trunk/droids-core/src/test/java/org/apache/droids/localserver/LocalHttpServer.java
URL: http://svn.apache.org/viewvc/incubator/droids/trunk/droids-core/src/test/java/org/apache/droids/localserver/LocalHttpServer.java?rev=1073071&r1=1073070&r2=1073071&view=diff
==============================================================================
--- incubator/droids/trunk/droids-core/src/test/java/org/apache/droids/localserver/LocalHttpServer.java (original)
+++ incubator/droids/trunk/droids-core/src/test/java/org/apache/droids/localserver/LocalHttpServer.java Mon Feb 21 17:13:17 2011
@@ -26,6 +26,8 @@ import java.util.HashSet;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import com.google.common.base.Preconditions;
+
 import org.apache.droids.helper.Loggable;
 import org.apache.http.HttpException;
 import org.apache.http.HttpServerConnection;
@@ -191,9 +193,7 @@ public class LocalHttpServer extends Log
    */
   public int getServicePort() {
     ServerSocket ssock = this.servicedSocket; // avoid synchronization
-    if (ssock == null) {
-      throw new IllegalStateException("not running");
-    }
+    Preconditions.checkState(ssock != null, "not running" );
     return ssock.getLocalPort();
   }
 
@@ -204,9 +204,7 @@ public class LocalHttpServer extends Log
    */
   public SocketAddress getServiceAddress() {
     ServerSocket ssock = this.servicedSocket; // avoid synchronization
-    if (ssock == null) {
-      throw new IllegalStateException("not running");
-    }
+    Preconditions.checkState(ssock != null, "not running" );
     return ssock.getLocalSocketAddress();
   }