abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r1198949 [1/3] - in /abdera/abdera2: activities/src/main/java/org/apache/abdera2/activities/io/gson/ activities/src/main/java/org/apache/abdera2/activities/model/ activities/src/main/java/org/apache/abdera2/activities/model/objects/ activit...
Date Mon, 07 Nov 2011 21:31:55 GMT
Author: jmsnell
Date: Mon Nov  7 21:31:52 2011
New Revision: 1198949

URL: http://svn.apache.org/viewvc?rev=1198949&view=rev
Log:
General code design improvements, bug fixes, immutability of objects for thread-safety

Added:
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/Pair.java   (with props)
Modified:
    abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/io/gson/AdaptedType.java
    abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/io/gson/GsonIO.java
    abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/io/gson/MimeTypeAdapter.java
    abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/ASBase.java
    abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/Verb.java
    abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/FileObject.java
    abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/ActivitiesResponseContext.java
    abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/ProtocolException.java
    abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/basic/BasicAdapter.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/AnnoUtil.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/Context.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/DefaultImplementation.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/Name.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/Namespace.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/Param.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/QName.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/URIRoute.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/URITemplate.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/Version.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Coordinate.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Multiple.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Point.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Position.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/Authentication.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/CacheControl.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/CacheControlUtil.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/EntityTag.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/Method.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/Preference.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/QualityHelper.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/WebLink.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/io/CharsetSniffingInputStream.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/io/Compression.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/io/FilteredCharReader.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/io/PeekAheadInputStream.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/iri/AbstractScheme.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/iri/IRI.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/lang/Lang.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/lang/Range.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/lang/Subtag.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/lang/SubtagSet.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/mediatype/MimeTypeHelper.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/Chain.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/Comparisons.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/MapRed.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/MoreFunctions.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractCollectionAdapter.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractProvider.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractResponseContext.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/BasicCollectionInfo.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/BasicWorkspaceInfo.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/ProtocolException.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/RegexTargetResolver.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/SimpleSubjectResolver.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/SimpleTarget.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/TargetFunctionResolver.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/TargetType.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/pusher/AbstractPusher.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/security/ApiKey.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/security/KeyBase.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/security/Otp.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/templates/DefaultingContext.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/templates/Expression.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/templates/MapContext.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/templates/ObjectContext.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/templates/Route.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/templates/Template.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/templates/TemplateManager.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/text/CharUtils.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/text/Slug.java
    abdera/abdera2/core/src/main/java/org/apache/abdera2/Abdera.java
    abdera/abdera2/core/src/main/java/org/apache/abdera2/factory/AbstractExtensionFactory.java
    abdera/abdera2/core/src/main/java/org/apache/abdera2/model/selector/CollectionAcceptSelector.java
    abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMAttribute.java
    abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMCollection.java
    abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/filter/UnacceptableException.java
    abdera/abdera2/core/src/main/java/org/apache/abdera2/protocol/error/AbderaProtocolException.java
    abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/MapRedExample.java
    abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/features/Feature.java
    abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/features/FeatureSelector.java
    abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/media/MediaContent.java
    abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/rss/RssEnclosure.java
    abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/AbstractConventions.java
    abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/thread/InReplyTo.java
    abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/SimpleCategoriesInfo.java
    abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/SimpleCategoryInfo.java
    abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/SimpleCollectionInfo.java

Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/io/gson/AdaptedType.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/io/gson/AdaptedType.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/io/gson/AdaptedType.java (original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/io/gson/AdaptedType.java Mon Nov  7 21:31:52 2011
@@ -3,6 +3,7 @@ package org.apache.abdera2.activities.io
 import static java.lang.annotation.ElementType.TYPE;
 import static java.lang.annotation.RetentionPolicy.RUNTIME;
 
+import java.lang.annotation.Documented;
 import java.lang.annotation.Inherited;
 import java.lang.annotation.Retention;
 import java.lang.annotation.Target;
@@ -11,6 +12,7 @@ import java.lang.annotation.Target;
  * Intended to be used on TypeAdapter instances to 
  * identify the adapted type
  */
+@Documented
 @Retention(RUNTIME)
 @Target( {TYPE})
 @Inherited

Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/io/gson/GsonIO.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/io/gson/GsonIO.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/io/gson/GsonIO.java (original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/io/gson/GsonIO.java Mon Nov  7 21:31:52 2011
@@ -85,6 +85,7 @@ public class GsonIO extends IO {
     gb.registerTypeHierarchyAdapter(Lang.class, new LangAdapter());
     gb.registerTypeHierarchyAdapter(ASBase.class,  asbs);  
     gb.registerTypeHierarchyAdapter(Multimap.class, new MultimapAdapter());
+    gb.registerTypeHierarchyAdapter(MimeType.class, new MimeTypeAdapter());
     gb.registerTypeAdapter(ASBase.class, asbs);
     gb.registerTypeAdapter(Date.class, new DateAdapter());
     gb.registerTypeAdapter(DateTime.class, new DateTimeAdapter());

Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/io/gson/MimeTypeAdapter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/io/gson/MimeTypeAdapter.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/io/gson/MimeTypeAdapter.java (original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/io/gson/MimeTypeAdapter.java Mon Nov  7 21:31:52 2011
@@ -19,16 +19,14 @@ package org.apache.abdera2.activities.io
 
 import javax.activation.MimeType;
 
+import org.apache.abdera2.common.mediatype.MimeTypeHelper;
+
 @AdaptedType(MimeType.class)
 public class MimeTypeAdapter
   extends SimpleAdapter<MimeType> {
 
   protected MimeType deserialize(String v) {
-    try {
-      return new MimeType(v);
-    } catch (Throwable t) {
-      throw new RuntimeException(t);
-    }
+    return MimeTypeHelper.unmodifiableMimeType(v);
   }
 
 }

Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/ASBase.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/ASBase.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/ASBase.java (original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/ASBase.java Mon Nov  7 21:31:52 2011
@@ -34,9 +34,13 @@ import org.apache.abdera2.activities.mod
 import org.apache.abdera2.common.http.EntityTag;
 import org.apache.abdera2.common.iri.IRI;
 import org.apache.abdera2.common.lang.Lang;
+import org.apache.abdera2.common.mediatype.MimeTypeHelper;
 import org.apache.abdera2.common.mediatype.MimeTypeParseException;
+import org.apache.abdera2.common.misc.ExceptionHelper;
+import org.apache.abdera2.common.misc.MoreFunctions;
 
 import static com.google.common.base.Preconditions.*;
+
 import com.google.common.base.Function;
 import com.google.common.collect.Iterators;
 
@@ -109,16 +113,13 @@ public class ASBase 
 
   @Override
   public int hashCode() {
-    final int prime = 31;
-    int result = 1;
-    result = prime * result + ((exts == null) ? 0 : exts.hashCode());
-    return result;
+    return MoreFunctions.genHashCode(1,exts);
   }
 
   @Override
   public boolean equals(Object obj) {
     if (this == obj)
-      return true;
+      return true;    
     if (obj == null)
       return false;
     if (getClass() != obj.getClass())
@@ -151,7 +152,7 @@ public class ASBase 
       t.base = base;      
       return type.cast(t);
     } catch (Throwable t) {
-      throw new RuntimeException(t);
+      throw ExceptionHelper.propogate(t);
     }
   }
   
@@ -233,15 +234,11 @@ public class ASBase 
   }
   
   public void setContentType(String mimeType) {
-    try {
-      this.contentType = new MimeType(mimeType);
-    } catch (javax.activation.MimeTypeParseException t) {
-      throw new MimeTypeParseException(t);
-    }
+    this.contentType = MimeTypeHelper.unmodifiableMimeType(mimeType);
   }
   
   public void setContentType(MimeType mimeType) {
-    this.contentType = mimeType;
+    this.contentType = MimeTypeHelper.unmodifiableMimeType(mimeType);
   }
   
   public DateTime getLastModified() {

Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/Verb.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/Verb.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/Verb.java (original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/Verb.java Mon Nov  7 21:31:52 2011
@@ -20,6 +20,8 @@ package org.apache.abdera2.activities.mo
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
+import org.apache.abdera2.common.misc.MoreFunctions;
+
 /**
  * Activity Verbs... contains the core set of verbs and allows the creation
  * of new verbs on the fly.
@@ -99,10 +101,7 @@ public abstract class Verb {
 
   @Override
   public int hashCode() {
-    final int prime = 31;
-    int result = 1;
-    result = prime * result + ((name == null) ? 0 : name.hashCode());
-    return result;
+    return MoreFunctions.genHashCode(1,name);
   }
 
   @Override

Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/FileObject.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/FileObject.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/FileObject.java (original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/FileObject.java Mon Nov  7 21:31:52 2011
@@ -23,6 +23,7 @@ import javax.activation.MimeTypeParseExc
 import org.apache.abdera2.activities.model.ASObject;
 import org.apache.abdera2.common.anno.Name;
 import org.apache.abdera2.common.iri.IRI;
+import org.apache.abdera2.common.mediatype.MimeTypeHelper;
 
 @Name("file")
 public class FileObject 
@@ -55,15 +56,11 @@ public class FileObject 
   }
   
   public void setMimeType(MimeType mimeType) {
-    setProperty("mimeType", mimeType);
+    setProperty("mimeType", MimeTypeHelper.unmodifiableMimeType(mimeType));
   }
   
   public void setMimeType(String mimeType) {
-    try {
-      setProperty("mimeType", new MimeType(mimeType));
-    } catch (MimeTypeParseException e) {
-      throw new org.apache.abdera2.common.mediatype.MimeTypeParseException(e);
-    }
+    setProperty("mimeType", MimeTypeHelper.unmodifiableMimeType(mimeType));
   }
   
   public static <T extends FileObject>FileObjectGenerator<T> makeFile() {

Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/ActivitiesResponseContext.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/ActivitiesResponseContext.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/ActivitiesResponseContext.java (original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/ActivitiesResponseContext.java Mon Nov  7 21:31:52 2011
@@ -24,6 +24,7 @@ import java.io.OutputStream;
 import javax.activation.MimeType;
 
 import org.apache.abdera2.activities.model.ASBase;
+import org.apache.abdera2.common.mediatype.MimeTypeHelper;
 import org.apache.abdera2.common.protocol.AbstractResponseContext;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -79,11 +80,7 @@ public class ActivitiesResponseContext<T
   }
 
   public MimeType getContentType() {
-    try {
-      return new MimeType("application/json");
-    } catch (Throwable t) {
-      throw new RuntimeException(t); // won't happen
-    }
+    return MimeTypeHelper.unmodifiableMimeType("application/json");
   }
 
   public long getContentLength() {

Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/ProtocolException.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/ProtocolException.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/ProtocolException.java (original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/ProtocolException.java Mon Nov  7 21:31:52 2011
@@ -17,6 +17,8 @@
  */
 package org.apache.abdera2.activities.protocol;
 
+import org.apache.abdera2.common.misc.MoreFunctions;
+
 public class ProtocolException extends RuntimeException {
 
     private static final long serialVersionUID = 1017447143200419489L;
@@ -40,13 +42,9 @@ public class ProtocolException extends R
 
     @Override
     public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        String message = error != null ? error.getDisplayName() : null;
-        int code = error != null ? error.getCode() : 0;
-        result = prime * result + ((message == null) ? 0 : message.hashCode());
-        result = prime * result + code;
-        return result;
+      String message = error != null ? error.getDisplayName() : null;
+      int code = error != null ? error.getCode() : 0;
+      return MoreFunctions.genHashCode(1,message,code);
     }
 
     @Override

Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/basic/BasicAdapter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/basic/BasicAdapter.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/basic/BasicAdapter.java (original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/basic/BasicAdapter.java Mon Nov  7 21:31:52 2011
@@ -35,7 +35,6 @@ import org.apache.abdera2.activities.pro
 import org.apache.abdera2.common.mediatype.MimeTypeHelper;
 import org.apache.abdera2.common.protocol.RequestContext;
 import org.apache.abdera2.common.protocol.ResponseContext;
-import org.apache.abdera2.common.protocol.ProviderHelper;
 import org.apache.abdera2.common.protocol.Target;
 import org.apache.abdera2.common.protocol.TargetType;
 import org.apache.abdera2.common.protocol.RequestContext.Scope;
@@ -46,6 +45,7 @@ import org.joda.time.DateTime;
 import com.google.common.base.Function;
 import static com.google.common.base.Preconditions.*;
 import static org.apache.abdera2.common.misc.ExceptionHelper.*;
+import static org.apache.abdera2.common.protocol.ProviderHelper.*;
 
 /**
  * The BasicAdapter provides a simplistic interface for working with Atompub collections with a restricted set of
@@ -133,7 +133,7 @@ public abstract class BasicAdapter exten
         MimeType mimeType = request.getContentType();
         String contentType = mimeType == null ? null : mimeType.toString();
         if (contentType != null && !MimeTypeHelper.isJson(contentType))
-          return ProviderHelper.notsupported(request);
+          return notsupported(request);
            
         ASBase base = getEntryFromRequest(request);
         Target target = request.getTarget();
@@ -176,11 +176,11 @@ public abstract class BasicAdapter exten
                 .setStatus(createFlag?201:200)
                 .setLocation(loc);
           } else
-            return ProviderHelper.notfound(request);
+            return notfound(request);
         } else
-          return ProviderHelper.notallowed(request);
+          return notallowed(request);
       } catch (Exception e) {
-        return ProviderHelper.servererror(request, e.getMessage(), e);
+        return servererror(request, e.getMessage(), e);
       }
     }
 
@@ -199,10 +199,10 @@ public abstract class BasicAdapter exten
           String entryId = target.getParameter(BasicProvider.PARAM_ENTRY);
           try {
               return deleteItem(entryId) ? 
-                ProviderHelper.nocontent() : 
-                ProviderHelper.notfound(input);
+                nocontent() : 
+                notfound(input);
           } catch (Exception e) {
-              return ProviderHelper.servererror(
+              return servererror(
                 input, e.getMessage(), e);
           }
         }
@@ -228,9 +228,9 @@ public abstract class BasicAdapter exten
                 return 
                   new ActivitiesResponseContext<ASObject>(object)
                     .setStatus(200);
-              } else return ProviderHelper.notfound(input);       
+              } else return notfound(input);       
           } catch (Exception e) {
-              return ProviderHelper.servererror(input, e.getMessage(), e);
+              return servererror(input, e.getMessage(), e);
           }
         }
       };
@@ -247,9 +247,9 @@ public abstract class BasicAdapter exten
               return 
                 new ActivitiesResponseContext<Collection<ASObject>>(collection)
                   .setStatus(200);
-            } else return ProviderHelper.notfound(input);
+            } else return notfound(input);
           } catch (Exception e) {
-            return ProviderHelper.servererror(input, e.getMessage(), e);
+            return servererror(input, e.getMessage(), e);
           }
         }
       };

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/AnnoUtil.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/AnnoUtil.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/AnnoUtil.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/AnnoUtil.java Mon Nov  7 21:31:52 2011
@@ -17,12 +17,19 @@
  */
 package org.apache.abdera2.common.anno;
 
+import java.lang.annotation.Annotation;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.HashSet;
 import java.util.Set;
 
 import javax.xml.namespace.QName;
 
+import org.apache.abdera2.common.misc.MoreFunctions;
+
+import com.google.common.base.Equivalence;
+import com.google.common.base.Predicate;
+
 public final class AnnoUtil {
 
   private AnnoUtil() {}
@@ -126,4 +133,187 @@ public final class AnnoUtil {
       return qNameFromAnno(_class.getAnnotation(org.apache.abdera2.common.anno.QName.class));
     return null;
   }
+  
+  public static Equivalence<Version> versionEquivalence() {
+    return versionEquivalence(true);
+  }
+  
+  public static Equivalence<Version> versionEquivalence(final boolean ignoreStatus) {
+    return new Equivalence<Version>() {
+      protected boolean doEquivalent(Version a, Version b) {
+        if (!a.name().equalsIgnoreCase(b.name())) return false;
+        if (!a.uri().equals(b.uri())) return false;
+        if (!a.value().equals(b.value())) return false;
+        if (!ignoreStatus && !a.status().equals(b.status())) return false;
+        int cmp = a.major() - b.major();
+        if(cmp == 0 && a.minor() > -1 && b.minor() > -1)
+          cmp = a.minor() - b.minor();
+        if(cmp == 0 && a.revision() > -1 && b.revision() > -1)
+          cmp = a.revision() - b.revision();
+        return cmp == 0;
+      }
+      protected int doHash(Version t) {
+        return t.hashCode();
+      }
+    };
+  }
+  
+  public static final Predicate<Version> equalOrGreater(
+    final Version version) {
+    return new Predicate<Version>() {
+      public boolean apply(Version input) {
+        int cmp = input.major() - version.major();
+        if(cmp == 0)
+          if(input.minor() > -1 && version.minor() > -1)
+            cmp = input.minor() - version.minor();
+          else
+            cmp = input.minor();
+        if(cmp == 0)
+          if(input.revision() > -1 && version.revision() > -1)
+            cmp = input.revision() - version.revision();
+          else
+            cmp = input.revision();
+        return cmp <= 0;
+      }
+    };
+  }
+  
+  public static final Comparator<Version> VERSION_COMPARATOR =
+    new Comparator<Version>() {
+      public int compare(Version v1, Version v2) {
+        int cmp = v1.major() - v2.major();
+        if(cmp == 0)
+          cmp = v1.minor() - v2.minor();
+        if(cmp == 0)
+          cmp = v1.revision() - v2.revision();
+        return cmp;
+      }
+  };
+
+  
+  public static final Version version(String value, String name, String uri) {
+    return new VersionImpl(value,name,uri,0,0,0,Version.Status.STABLE);
+  }
+  
+  public static final Version version(
+    String value, 
+    String name, 
+    String uri, 
+    int major, 
+    int minor, 
+    int revision,
+    Version.Status status) {
+    return new VersionImpl(
+      value,
+      name,
+      uri,
+      major,
+      minor,
+      revision,
+      status);
+  }
+  
+  private static class VersionImpl 
+    implements Version {
+
+      @Override
+    public int hashCode() {
+      return MoreFunctions.genHashCode(1,
+        major,minor,name,revision,uri,value,status);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+      if (this == obj)
+        return true;
+      if (obj == null)
+        return false;
+      if (getClass() != obj.getClass())
+        return false;
+      VersionImpl other = (VersionImpl) obj;
+      if (major != other.major)
+        return false;
+      if (minor != other.minor)
+        return false;
+      if (name == null) {
+        if (other.name != null)
+          return false;
+      } else if (!name.equals(other.name))
+        return false;
+      if (revision != other.revision)
+        return false;
+      if (uri == null) {
+        if (other.uri != null)
+          return false;
+      } else if (!uri.equals(other.uri))
+        return false;
+      if (value == null) {
+        if (other.value != null)
+          return false;
+      } else if (!value.equals(other.value))
+        return false;
+      if (status == null) {
+        if (other.status != null)
+          return false;
+      } else if (!status.equals(other.status))
+        return false;
+      return true;
+    }
+
+      private final String value;
+      private final String name;
+      private final String uri;
+      private final int major,minor,revision;
+      private final Version.Status status;
+      
+      VersionImpl(
+        String value, 
+        String name, 
+        String uri, 
+        int major, 
+        int minor, 
+        int revision,
+        Version.Status status) {
+        this.value = value;
+        this.name = name;
+        this.uri = uri;
+        this.major = major;
+        this.minor = minor;
+        this.revision = revision;
+        this.status = status;
+      }
+      
+      public Class<? extends Annotation> annotationType() {
+        return Version.class;
+      }
+
+      public String value() {
+        return value;
+      }
+
+      public String name() {
+        return name;
+      }
+
+      public String uri() {
+        return uri;
+      }
+
+      public int major() {
+        return major;
+      }
+
+      public int minor() {
+        return minor;
+      }
+
+      public int revision() {
+        return revision;
+      }
+
+      public Status status() {
+        return status;
+      }
+      
+  }
 }

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/Context.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/Context.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/Context.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/Context.java Mon Nov  7 21:31:52 2011
@@ -3,6 +3,7 @@ package org.apache.abdera2.common.anno;
 import static java.lang.annotation.ElementType.TYPE;
 import static java.lang.annotation.RetentionPolicy.RUNTIME;
 
+import java.lang.annotation.Documented;
 import java.lang.annotation.Retention;
 import java.lang.annotation.Target;
 
@@ -12,6 +13,7 @@ import java.lang.annotation.Target;
  * default context. Each Context Annotation contains a 
  * list of static Param annotations
  */
+@Documented
 @Retention(RUNTIME)
 @Target( {TYPE})
 public @interface Context {

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/DefaultImplementation.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/DefaultImplementation.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/DefaultImplementation.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/DefaultImplementation.java Mon Nov  7 21:31:52 2011
@@ -20,6 +20,7 @@ package org.apache.abdera2.common.anno;
 import static java.lang.annotation.ElementType.TYPE;
 import static java.lang.annotation.RetentionPolicy.RUNTIME;
 
+import java.lang.annotation.Documented;
 import java.lang.annotation.Retention;
 import java.lang.annotation.Target;
 
@@ -27,6 +28,7 @@ import java.lang.annotation.Target;
  * Used on Interface classes to identify the default implementation
  * class when using the Abdera Discover mechanism
  */
+@Documented
 @Retention(RUNTIME)
 @Target( {TYPE})
 public @interface DefaultImplementation {

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/Name.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/Name.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/Name.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/Name.java Mon Nov  7 21:31:52 2011
@@ -22,10 +22,12 @@ import static java.lang.annotation.Eleme
 import static java.lang.annotation.ElementType.METHOD;
 import static java.lang.annotation.RetentionPolicy.RUNTIME;
 
+import java.lang.annotation.Documented;
 import java.lang.annotation.Inherited;
 import java.lang.annotation.Retention;
 import java.lang.annotation.Target;
 
+@Documented
 @Retention(RUNTIME)
 @Target( {TYPE,FIELD,METHOD})
 @Inherited

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/Namespace.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/Namespace.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/Namespace.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/Namespace.java Mon Nov  7 21:31:52 2011
@@ -19,6 +19,7 @@ package org.apache.abdera2.common.anno;
 import static java.lang.annotation.ElementType.TYPE;
 import static java.lang.annotation.RetentionPolicy.RUNTIME;
 
+import java.lang.annotation.Documented;
 import java.lang.annotation.Retention;
 import java.lang.annotation.Target;
 
@@ -26,6 +27,7 @@ import java.lang.annotation.Target;
  * Used by Extension Factory classes to specify the XML namespaces
  * handled by the factory
  */
+@Documented
 @Retention(RUNTIME)
 @Target( {TYPE})
 public @interface Namespace {

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/Param.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/Param.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/Param.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/Param.java Mon Nov  7 21:31:52 2011
@@ -3,6 +3,7 @@ package org.apache.abdera2.common.anno;
 import static java.lang.annotation.ElementType.TYPE;
 import static java.lang.annotation.RetentionPolicy.RUNTIME;
 
+import java.lang.annotation.Documented;
 import java.lang.annotation.Retention;
 import java.lang.annotation.Target;
 
@@ -10,6 +11,7 @@ import java.lang.annotation.Target;
  * Used with the Context Annotation to establish a static context 
  * primarily for use with the URI Template implementation
  */
+@Documented
 @Retention(RUNTIME)
 @Target( {TYPE})
 public @interface Param {

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/QName.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/QName.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/QName.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/QName.java Mon Nov  7 21:31:52 2011
@@ -20,6 +20,7 @@ package org.apache.abdera2.common.anno;
 import static java.lang.annotation.ElementType.TYPE;
 import static java.lang.annotation.RetentionPolicy.RUNTIME;
 
+import java.lang.annotation.Documented;
 import java.lang.annotation.Inherited;
 import java.lang.annotation.Retention;
 import java.lang.annotation.Target;
@@ -27,6 +28,7 @@ import java.lang.annotation.Target;
 /**
  * Used primarily to associate an XML Qualified name with an interface
  */
+@Documented
 @Retention(RUNTIME)
 @Target( {TYPE})
 @Inherited

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/URIRoute.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/URIRoute.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/URIRoute.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/URIRoute.java Mon Nov  7 21:31:52 2011
@@ -20,6 +20,7 @@ package org.apache.abdera2.common.anno;
 import static java.lang.annotation.ElementType.TYPE;
 import static java.lang.annotation.RetentionPolicy.RUNTIME;
 
+import java.lang.annotation.Documented;
 import java.lang.annotation.Retention;
 import java.lang.annotation.Target;
 
@@ -29,6 +30,7 @@ import java.lang.annotation.Target;
  * be automatically mapped to URI Template variable names. Alternative varnames can be specified for each field/getter
  * using the VarName annotation
  */
+@Documented
 @Retention(RUNTIME)
 @Target(TYPE)
 public @interface URIRoute {

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/URITemplate.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/URITemplate.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/URITemplate.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/URITemplate.java Mon Nov  7 21:31:52 2011
@@ -20,6 +20,7 @@ package org.apache.abdera2.common.anno;
 import static java.lang.annotation.ElementType.TYPE;
 import static java.lang.annotation.RetentionPolicy.RUNTIME;
 
+import java.lang.annotation.Documented;
 import java.lang.annotation.Retention;
 import java.lang.annotation.Target;
 
@@ -29,6 +30,7 @@ import java.lang.annotation.Target;
  * be automatically mapped to URI Template variable names. Alternative varnames can be specified for each field/getter
  * using the VarName annotation
  */
+@Documented
 @Retention(RUNTIME)
 @Target(TYPE)
 public @interface URITemplate {

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/Version.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/Version.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/Version.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/Version.java Mon Nov  7 21:31:52 2011
@@ -20,15 +20,26 @@ package org.apache.abdera2.common.anno;
 import static java.lang.annotation.ElementType.TYPE;
 import static java.lang.annotation.RetentionPolicy.RUNTIME;
 
+import java.lang.annotation.Documented;
 import java.lang.annotation.Inherited;
 import java.lang.annotation.Retention;
 import java.lang.annotation.Target;
 
+@Documented
 @Retention(RUNTIME)
 @Target( {TYPE})
 @Inherited
 public @interface Version {
+  public static enum Status {
+    STABLE, 
+    DEVELOPMENT, 
+    DEPRECATED
+  }
   String value(); // Version Number
   String name();  // App Name
   String uri();   // App URI
+  int major() default 0; // major code
+  int minor() default 0; // minor code
+  int revision() default 0; // revision code
+  Status status() default Status.DEVELOPMENT;
 }

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Coordinate.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Coordinate.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Coordinate.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Coordinate.java Mon Nov  7 21:31:52 2011
@@ -18,7 +18,11 @@
 package org.apache.abdera2.common.geo;
 
 import java.io.Serializable;
+
+import org.apache.abdera2.common.misc.MoreFunctions;
+
 import static com.google.common.base.Preconditions.*;
+import static java.lang.Double.compare;
 
 public class Coordinate 
   implements Serializable, 
@@ -46,11 +50,30 @@ public class Coordinate 
       this(pos.getLatitude(),pos.getLongitude());
     }
 
+    private static final String LAT = "Latitude %s %s90.0 degrees";
+    private static final String LONG = "Longitude %s= %s180.0 degrees";
+    
+    private void checkLatitude(double latitude) {
+      checkArgument(
+        !(compare(latitude, 90.0d) > 0), 
+        String.format(LAT,'>','+'));
+      checkArgument(
+        !(compare(latitude, -90.0d) < 0), 
+        String.format(LAT,'<','-'));
+    }
+    
+    private void checkLongitude(double longitude) {
+      checkArgument(
+        !(compare(longitude, 180.0d) >= 0), 
+        String.format(LONG,'>','+'));
+      checkArgument(
+        !(compare(longitude, -180.0d) <= 0), 
+        String.format(LONG,'<','-'));
+    }
+    
     public Coordinate(double latitude, double longitude) {
-      checkArgument(!(Double.compare(latitude, 90.0d) > 0), "Latitude > 90.0 degrees");
-      checkArgument(!(Double.compare(latitude, -90.0d) < 0), "Latitude < -90.0 degrees");
-      checkArgument(!(Double.compare(longitude, 180.0d) >= 0), "Longitude >= 180.0 degrees");
-      checkArgument(!(Double.compare(longitude, -180.0d) <= 0), "Longitude <= -180.0 degrees");
+      checkLatitude(latitude);
+      checkLongitude(longitude);
       this.latitude = latitude;
       this.longitude = longitude;
     }
@@ -59,10 +82,8 @@ public class Coordinate 
       Coordinate c = parse(value);
       this.latitude = c.latitude;
       this.longitude = c.longitude;
-      checkArgument(!(Double.compare(latitude, 90.0d) > 0), "Latitude > 90.0 degrees");
-      checkArgument(!(Double.compare(latitude, -90.0d) < 0), "Latitude < -90.0 degrees");
-      checkArgument(!(Double.compare(longitude, 180.0d) >= 0), "Longitude >= 180.0 degrees");
-      checkArgument(!(Double.compare(longitude, -180.0d) <= 0), "Longitude <= -180.0 degrees");
+      checkLatitude(latitude);
+      checkLongitude(longitude);
     }
 
     public double getLatitude() {
@@ -95,14 +116,9 @@ public class Coordinate 
 
     @Override
     public int hashCode() {
-        final int PRIME = 31;
-        int result = 1;
-        long temp;
-        temp = Double.doubleToLongBits(latitude);
-        result = PRIME * result + (int)(temp ^ (temp >>> 32));
-        temp = Double.doubleToLongBits(longitude);
-        result = PRIME * result + (int)(temp ^ (temp >>> 32));
-        return result;
+      return MoreFunctions.genHashCode(1,
+        latitude,
+        longitude);
     }
 
     @Override

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Multiple.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Multiple.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Multiple.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Multiple.java Mon Nov  7 21:31:52 2011
@@ -24,6 +24,8 @@ import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
 
+import org.apache.abdera2.common.misc.MoreFunctions;
+
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 import static com.google.common.base.Preconditions.*;
@@ -41,33 +43,37 @@ public abstract class Multiple extends P
       return (P)this;
     }
     
+    private static void checkMaxPoints(int points, int max) {
+      checkState(points <= max, "Maximum coordinates exceeded", max);
+    }
+    
     public <P extends Builder<X>>P maximumCoordinates(int max) {
       checkArgument(max > -1, "Maximum must not be negative");
       this.maxpoints = max;
-      checkState(coordinates.size() <= max, "Maximum coordinates exceeded", maxpoints);
+      checkMaxPoints(coordinates.size(),max);
       return (P)this;
     }
     
     public <P extends Builder<X>>P add(Coordinate coordinate) {
-      checkState(maxpoints < 0 || coordinates.size()+1 <= maxpoints, "Maximum coordinates exceeded", maxpoints);
+      checkMaxPoints(coordinates.size()+1,maxpoints);
       this.coordinates.add(coordinate);
       return (P)this;
     }
     
     public <P extends Builder<X>>P add(double latitude, double longitude) {
-      checkState(maxpoints < 0 || coordinates.size()+1 <= maxpoints, "Maximum coordinates exceeded", maxpoints);
+      checkMaxPoints(coordinates.size()+1,maxpoints);
       this.coordinates.add(Coordinate.at(latitude,longitude));
       return (P)this;
     }
     
     public <P extends Builder<X>>P add(String position) {
-      checkState(maxpoints < 0 || coordinates.size()+1 <= maxpoints, "Maximum coordinates exceeded", maxpoints);
+      checkMaxPoints(coordinates.size()+1,maxpoints);
       this.coordinates.add(Coordinate.at(position));
       return (P)this;
     }
     
     public <P extends Builder<X>>P add(IsoPosition position) {
-      checkState(maxpoints < 0 || coordinates.size()+1 <= maxpoints, "Maximum coordinates [%d] exceeded", maxpoints);
+      checkMaxPoints(coordinates.size()+1,maxpoints);
       this.coordinates.add(Coordinate.at(position));
       return (P)this;
     }
@@ -95,10 +101,7 @@ public abstract class Multiple extends P
 
     @Override
     public int hashCode() {
-        final int PRIME = 31;
-        int result = super.hashCode();
-        result = PRIME * result + ((coordinates == null) ? 0 : coordinates.hashCode());
-        return result;
+      return MoreFunctions.genHashCode(super.hashCode(),coordinates);
     }
 
     @Override
@@ -148,7 +151,7 @@ public abstract class Multiple extends P
             }
             return list;
         } catch (Throwable t) {
-            throw new RuntimeException("Error parsing coordinate pairs", t);
+          throw new RuntimeException("Error parsing coordinate pairs", t);
         }
     }
 }

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Point.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Point.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Point.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Point.java Mon Nov  7 21:31:52 2011
@@ -17,6 +17,8 @@
  */
 package org.apache.abdera2.common.geo;
 
+import org.apache.abdera2.common.misc.MoreFunctions;
+
 public class Point extends Position {
 
     public static Point at(Coordinate coordinate) {
@@ -107,10 +109,7 @@ public class Point extends Position {
     
     @Override
     public int hashCode() {
-        final int PRIME = 31;
-        int result = super.hashCode();
-        result = PRIME * result + ((coordinate == null) ? 0 : coordinate.hashCode());
-        return result;
+      return MoreFunctions.genHashCode(super.hashCode(),coordinate);
     }
 
     @Override

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Position.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Position.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Position.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Position.java Mon Nov  7 21:31:52 2011
@@ -19,6 +19,8 @@ package org.apache.abdera2.common.geo;
 
 import java.io.Serializable;
 
+import org.apache.abdera2.common.misc.MoreFunctions;
+
 import com.google.common.base.Supplier;
 
 public abstract class Position 
@@ -102,19 +104,13 @@ public abstract class Position 
 
     @Override
     public int hashCode() {
-        final int PRIME = 31;
-        // int result = super.hashCode();
-        int result = this.getClass().hashCode();
-        result = PRIME * result + ((elevation == null) ? 0 : elevation.hashCode());
-        result =
-            PRIME * result
-                + ((featureTypeTag == null) ? DEFAULT_FEATURE_TYPE_TAG.hashCode() : featureTypeTag.hashCode());
-        result = PRIME * result + ((floor == null) ? 0 : floor.hashCode());
-        result = PRIME * result + ((radius == null) ? 0 : radius.hashCode());
-        result =
-            PRIME * result
-                + ((relationshipTag == null) ? DEFAULT_RELATIONSHIP_TAG.hashCode() : relationshipTag.hashCode());
-        return result;
+      return MoreFunctions.genHashCode(
+        getClass().hashCode(),
+        elevation,
+        featureTypeTag == null ? DEFAULT_FEATURE_TYPE_TAG : featureTypeTag,
+        floor, radius, 
+        relationshipTag == null ? DEFAULT_RELATIONSHIP_TAG : relationshipTag
+        );
     }
 
     @Override

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/Authentication.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/Authentication.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/Authentication.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/Authentication.java Mon Nov  7 21:31:52 2011
@@ -31,8 +31,11 @@ import java.util.Set;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import org.apache.abdera2.common.misc.MoreFunctions;
 import org.apache.abdera2.common.text.CharUtils.Profile;
 import org.apache.abdera2.common.text.Codec;
+
+import static org.apache.abdera2.common.text.CharUtils.appendcomma;
 import static org.apache.abdera2.common.text.CharUtils.unquote;
 import static org.apache.abdera2.common.text.CharUtils.quotedIfNotToken;
 import static org.apache.abdera2.common.text.CharUtils.quoted;
@@ -41,6 +44,8 @@ import org.apache.commons.codec.binary.S
 
 import com.google.common.base.Function;
 import com.google.common.base.Supplier;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterators;
 
 /**
  * Implementation of the HTTP Challenge/Credentials Construct. This is helpful when 
@@ -66,15 +71,13 @@ public class Authentication implements I
     Pattern.compile("("+PARAM+")");
   
   private final static Set<String> ALWAYS = 
-    new HashSet<String>();
-  static {
-      alwaysQuote(
+    new HashSet<String>(
+      ImmutableSet.of(
         "domain",
         "nonce",
         "opaque",
         "qop",
-        "realm");
-  }
+        "realm"));
   
   public static synchronized void alwaysQuote(String... names) {
     checkNotNull(names);
@@ -124,9 +127,9 @@ public class Authentication implements I
     implements Supplier<Authentication> {
     private String scheme;
     private String b64token;
-    private Map<String,String> params = 
+    private final Map<String,String> params = 
       new LinkedHashMap<String,String>();
-    private Set<String> quoted = 
+    private final Set<String> quoted = 
       new HashSet<String>();
     
     public Authentication get() {
@@ -171,8 +174,7 @@ public class Authentication implements I
   private final String b64token;
   private final Map<String,String> params = 
     new LinkedHashMap<String,String>();
-  private final Set<String> quoted = 
-    new HashSet<String>();
+  private final Set<String> quoted;
     
   public Authentication(String scheme) {
     this(scheme,null);
@@ -182,13 +184,14 @@ public class Authentication implements I
     checkNotNull(scheme);
     this.scheme = scheme.toLowerCase(Locale.US);
     this.b64token = b64token;
+    this.quoted = ImmutableSet.<String>of();
   }
   
   private Authentication(Builder builder) {
     this.scheme = builder.scheme;
     this.b64token = builder.b64token;
     this.params.putAll(builder.params);
-    this.quoted.addAll(builder.quoted);
+    this.quoted = ImmutableSet.copyOf(builder.quoted);
   }
   
   public String getScheme() {
@@ -212,7 +215,7 @@ public class Authentication implements I
   }
   
   public Iterator<String> iterator() {
-    return params.keySet().iterator();
+    return Iterators.unmodifiableIterator(params.keySet().iterator());
   }
   
   private boolean isquoted(String param) {
@@ -228,9 +231,7 @@ public class Authentication implements I
     else {
       boolean first = true;
       for (String param : this) {
-        if (!first) {
-          buf.append(',').append(' ');
-        } else first = false;
+        first = appendcomma(first,buf);
         String val = getParam(param);
         buf.append(param);
         boolean always = is_always_quoted(param) || isquoted(param);
@@ -248,12 +249,7 @@ public class Authentication implements I
 
   @Override
   public int hashCode() {
-    final int prime = 31;
-    int result = 1;
-    result = prime * result + ((b64token == null) ? 0 : b64token.hashCode());
-    result = prime * result + ((params == null) ? 0 : params.hashCode());
-    result = prime * result + ((scheme == null) ? 0 : scheme.hashCode());
-    return result;
+    return MoreFunctions.genHashCode(1,b64token,params,scheme);
   }
 
   @Override
@@ -284,11 +280,11 @@ public class Authentication implements I
   }
   
   public static Authentication basic(String userid, String password) {
-    String b64token = 
+    return new Authentication(
+      BASIC, 
       StringUtils.newStringUsAscii(
         Base64.encodeBase64(
-          bytes(userid,":",password)));
-    return new Authentication(BASIC, b64token);
+          bytes(userid,":",password))));
   }
   
   private static byte[] bytes(String val, String... vals) {
@@ -316,8 +312,7 @@ public class Authentication implements I
     StringBuilder buf = new StringBuilder();
     boolean first = true;
     for (Authentication auth : auths) {
-      if (!first) buf.append(", ");
-      else first = !first;
+      first = appendcomma(first,buf);
       buf.append(auth.toString());
     }
     return buf.toString();

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/CacheControl.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/CacheControl.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/CacheControl.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/CacheControl.java Mon Nov  7 21:31:52 2011
@@ -18,17 +18,28 @@
 package org.apache.abdera2.common.http;
 
 import java.io.Serializable;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Locale;
 import java.util.Map;
+import java.util.Set;
+
+import org.apache.abdera2.common.misc.MoreFunctions;
 
 import com.google.common.base.Function;
 import com.google.common.base.Supplier;
+import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkArgument;
 
 public final class CacheControl implements Serializable {
 
+  private static final Set<String> reserved = 
+    ImmutableSet.of(
+      "private","public","no-cache","no-store","no-transform","only-if-cached",
+      "must-revalidate", "proxy-revalidate", "max-age", "max-stale", "min-fresh",
+      "stale-if-error", "stale-while-revalidate");
+  
   public static Builder make() {
     return new Builder();
   }
@@ -40,16 +51,17 @@ public final class CacheControl implemen
   public static class Builder implements Supplier<CacheControl> {
 
     protected int flags = 0;
-    protected String[] nocache_headers = {},
-                       private_headers = {};
+    protected Iterable<String>
+      nocache_headers,
+      private_headers;
     protected long max_age = -1,
                    max_stale = -1,
                    min_fresh = -1,
                    smax_age = -1,
                    staleiferror = -1,
                    stalewhilerevalidate = -1;
-    protected final HashMap<String,Object> exts =
-      new HashMap<String,Object>();
+    protected final Map<String,Object> exts =
+      new LinkedHashMap<String,Object>();
     
     public Builder() {
       defaults();
@@ -94,13 +106,31 @@ public final class CacheControl implemen
       return new CacheControl(this);
     }
     
+    private void checkReserved(String name) {
+      checkNotNull(name);
+      checkArgument(!reserved.contains(name.toLowerCase()), "Reserved directive", name);
+    }
+    
     public Builder extensions(Map<String,Object> exts) {
-      this.exts.putAll(exts);
+      for (Map.Entry<String, Object> entry : exts.entrySet()) {
+        String name = entry.getKey().toLowerCase(Locale.US);
+        checkReserved(name);
+        exts.put(
+          name, 
+          entry.getValue());
+      }
       return this;
     }
     
     public Builder extension(String name, Object value) {
-      exts.put(name,value);
+      checkReserved(name);
+      exts.put(name.toLowerCase(Locale.US),value);
+      return this;
+    }
+    
+    public Builder extension(String name) {
+      checkReserved(name);
+      exts.put(name.toLowerCase(Locale.US),null);
       return this;
     }
     
@@ -119,48 +149,85 @@ public final class CacheControl implemen
       return this;
     }
 
+    public Builder mustRevalidate() {
+      toggle(true,REVALIDATE);
+      return this;
+    }
+    
     public Builder mustRevalidate(boolean val) {
       toggle(val,REVALIDATE);
       return this;
     }
 
+    public Builder proxyRevalidate() {
+      toggle(true,PROXYREVALIDATE);
+      return this;
+    }
+    
     public Builder proxyRevalidate(boolean val) {
       toggle(val,PROXYREVALIDATE);
       return this;
     }
 
+    public Builder noCache() {
+      toggle(true,NOCACHE);
+      return this;
+    }
+    
     public Builder noCache(boolean val) {
       toggle(val,NOCACHE);
       return this;
     }
 
+    public Builder noStore() {
+      toggle(true,NOSTORE);
+      return this;
+    }
+    
     public Builder noStore(boolean val) {
       toggle(val,NOSTORE);
       return this;
     }
 
+    public Builder noTransform() {
+      toggle(true,NOTRANSFORM);
+      return this;
+    }
+    
     public Builder noTransform(boolean val) {
       toggle(val,NOTRANSFORM);
       return this;
     }
     
+    public Builder isPublic() {
+      toggle(true,PUBLIC);
+      return this;
+    }
+    
     public Builder isPublic(boolean val) {
       toggle(val,PUBLIC);
       return this;
     }
 
+    public Builder isPrivate() {
+      toggle(true,PRIVATE);
+      return this;
+    }
+    
     public Builder isPrivate(boolean val) {
       toggle(val,PRIVATE);
       return this;
     }
 
     public Builder privateHeaders(String... headers) {
-      this.private_headers = headers;
+      this.private_headers = ImmutableSet.copyOf(headers);
+      if (headers.length > 0) isPrivate();
       return this;
     }
 
     public Builder noCacheHeaders(String... headers) {
-      this.nocache_headers = headers;
+      this.nocache_headers = ImmutableSet.copyOf(headers);
+      if (headers.length > 0) noCache();
       return this;
     }
 
@@ -174,16 +241,19 @@ public final class CacheControl implemen
       return this;
     }
     
+    public Builder onlyIfCached() {
+      toggle(true,ONLYIFCACHED);
+      return this;
+    }
+    
     public Builder onlyIfCached(boolean val) {
       toggle(val,ONLYIFCACHED);
       return this;
     }
     
     private void toggle(boolean val, int flag) {
-      if (val)
-          flags |= flag;
-      else
-          flags &= ~flag;
+      if (val) flags |= flag;
+      else flags &= ~flag;
     }
   
   }
@@ -209,21 +279,28 @@ public final class CacheControl implemen
                           PROXYREVALIDATE = 64,
                           ONLYIFCACHED = 128;
   protected final int flags;
-  protected final String[] nocache_headers,
-                     private_headers;
+  protected final Iterable<String> 
+    nocache_headers,
+    private_headers;
   protected final long max_age,
                  max_stale,
                  min_fresh,
                  smax_age,
                  staleiferror,
                  stalewhilerevalidate;
-  protected HashMap<String,Object> exts =
-    new HashMap<String,Object>();
+  protected final Map<String,Object> exts =
+    new LinkedHashMap<String,Object>();
   
   private CacheControl(Builder builder) {
     this.flags = builder.flags;
-    this.nocache_headers = builder.nocache_headers;
-    this.private_headers = builder.private_headers;
+    this.nocache_headers = 
+      builder.nocache_headers != null ?
+        builder.nocache_headers : 
+        ImmutableSet.<String>of();
+    this.private_headers = 
+      builder.private_headers != null ?
+        builder.private_headers : 
+        ImmutableSet.<String>of();
     this.max_age = builder.max_age;
     this.max_stale = builder.max_stale;
     this.min_fresh = builder.min_fresh;
@@ -262,11 +339,15 @@ public final class CacheControl implemen
   }
   
   public Iterable<String> getNoCacheHeaders() {
-    return isNoCache() ? Arrays.asList(nocache_headers) : Collections.<String>emptySet();
+    return isNoCache() ? 
+      nocache_headers : 
+      ImmutableSet.<String>of();
   }
 
   public Iterable<String> getPrivateHeaders() {
-    return isPrivate() ? Arrays.asList(private_headers) : Collections.<String>emptySet();
+    return isPrivate() ? 
+      private_headers : 
+      ImmutableSet.<String>of();
   }
 
   public long getSMaxAge() {
@@ -315,19 +396,16 @@ public final class CacheControl implemen
   
   @Override
   public int hashCode() {
-    final int prime = 31;
-    int result = 1;
-    result = prime * result + flags;
-    result = prime * result + (int) (max_age ^ (max_age >>> 32));
-    result = prime * result + (int) (max_stale ^ (max_stale >>> 32));
-    result = prime * result + (int) (min_fresh ^ (min_fresh >>> 32));
-    result = prime * result + Arrays.hashCode(nocache_headers);
-    result = prime * result + Arrays.hashCode(private_headers);
-    result = prime * result + (int) (smax_age ^ (smax_age >>> 32));
-    result = prime * result + (int) (staleiferror ^ (staleiferror >>> 32));
-    result = prime * result
-        + (int) (stalewhilerevalidate ^ (stalewhilerevalidate >>> 32));
-    return result;
+    return MoreFunctions.genHashCode(
+      1, flags, 
+      max_age,
+      max_stale,
+      min_fresh,
+      nocache_headers,
+      private_headers,
+      smax_age,
+      staleiferror,
+      stalewhilerevalidate);
   }
 
   @Override
@@ -347,9 +425,9 @@ public final class CacheControl implemen
       return false;
     if (min_fresh != other.min_fresh)
       return false;
-    if (!Arrays.equals(nocache_headers, other.nocache_headers))
+    if (!Iterables.elementsEqual(nocache_headers, other.nocache_headers))
       return false;
-    if (!Arrays.equals(private_headers, other.private_headers))
+    if (!Iterables.elementsEqual(private_headers, other.private_headers))
       return false;
     if (smax_age != other.smax_age)
       return false;

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/CacheControlUtil.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/CacheControlUtil.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/CacheControlUtil.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/CacheControlUtil.java Mon Nov  7 21:31:52 2011
@@ -17,16 +17,17 @@
  */
 package org.apache.abdera2.common.http;
 
-import java.util.HashMap;
+import java.util.Collections;
 import java.util.Iterator;
+import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import org.apache.abdera2.common.text.CharUtils;
+import com.google.common.collect.Iterators;
 
-import com.google.common.base.Joiner;
-import com.google.common.collect.Iterables;
+import static java.lang.String.format;
+import static org.apache.abdera2.common.text.CharUtils.*;
 
 /**
  * Provides parsing and properly handling of the HTTP Cache-Control header.
@@ -38,73 +39,39 @@ public final class CacheControlUtil {
     private static long value(String val) {
         return (val != null) ? Long.parseLong(val) : -1;
     }
-
-    private static void append(StringBuilder buf, String value) {
-        if (buf.length() > 0)
-            buf.append(", ");
-        buf.append(value);
-    }
-
-    private static final Joiner joiner = Joiner.on(',').skipNulls();
     
     /**
      * Construct the Cache-Control header from info in the request object
      */
-    public static String buildCacheControl(CacheControl cacheControl) {
+    public static String buildCacheControl(CacheControl cc) {
         StringBuilder buf = new StringBuilder();
-        if (cacheControl.isPrivate()) {
-            append(buf, "private");
-            Iterable<String> headers = cacheControl.getPrivateHeaders();
-            if (!Iterables.isEmpty(headers)) {
-              buf.append("=\"");
-              joiner.appendTo(buf, headers);
-              buf.append("\"");
-            }
-        }
-        if (cacheControl.isPublic())
-            append(buf, "public");
-        if (cacheControl.isNoCache()) {
-            append(buf, "no-cache");
-            Iterable<String> headers = cacheControl.getNoCacheHeaders();
-            if (!Iterables.isEmpty(headers)) {
-              buf.append("=\"");
-              joiner.appendTo(buf,headers);
-              buf.append("\"");
-            }   
-        }
-        if (cacheControl.isNoStore())
-            append(buf, "no-store");
-        if (cacheControl.isNoTransform())
-            append(buf, "no-transform");
-        if (cacheControl.isOnlyIfCached())
-            append(buf, "only-if-cached");
-        if (cacheControl.isMustRevalidate())
-            append(buf, "must-revalidate");
-        if (cacheControl.isProxyRevalidate())
-            append(buf, "proxy-revalidate");
-        if (cacheControl.getMaxAge() != -1)
-            append(buf, String.format("max-age=%d", cacheControl.getMaxAge()));
-        if (cacheControl.getMaxStale() != -1)
-            append(buf, String.format("max-stale=%d", cacheControl.getMaxStale()));
-        if (cacheControl.getMinFresh() != -1)
-            append(buf, String.format("min-fresh=%d", cacheControl.getMinFresh()));
-        if (cacheControl.getStaleIfError() != -1)
-            append(buf, String.format("stale-if-error=%d", cacheControl.getStaleIfError()));
-        if (cacheControl.getStaleWhileRevalidate() != -1)
-            append(buf, String.format("stale-while-revalidate=%d", cacheControl.getStaleWhileRevalidate()));
-        for (String ext : cacheControl.listExtensions()) {
+        appendif(cc.isPrivate(), buf, "private");
+        appendif(cc.isPrivate(), buf, cc.getPrivateHeaders());
+        appendif(cc.isPublic(), buf, "public");
+        appendif(cc.isNoCache(), buf, "no-cache");
+        appendif(cc.isNoCache(), buf, cc.getNoCacheHeaders());  
+        appendif(cc.isNoStore(), buf, "no-store");
+        appendif(cc.isNoTransform(), buf, "no-transform");
+        appendif(cc.isOnlyIfCached(), buf, "only-if-cached");
+        appendif(cc.isMustRevalidate(), buf, "must-revalidate");
+        appendif(cc.isProxyRevalidate(), buf, "proxy-revalidate");
+        appendif(cc.getMaxAge() != -1, buf, "max-age=%d", cc.getMaxAge());
+        appendif (cc.getMaxStale() != -1, buf, "max-stale=%d", cc.getMaxStale());
+        appendif (cc.getMinFresh() != -1, buf, "min-fresh=%d", cc.getMinFresh());
+        appendif (cc.getStaleIfError() != -1, buf, "stale-if-error=%d", cc.getStaleIfError());
+        appendif (cc.getStaleWhileRevalidate() != -1, buf, "stale-while-revalidate=%d", cc.getStaleWhileRevalidate());
+        for (String ext : cc.listExtensions()) {
           append(buf, ext);
-          Object val = cacheControl.getExtension(ext);
-          if (val instanceof Long || val instanceof Integer || val instanceof Short || val instanceof Byte) {
-            buf.append('=')
-               .append(val);            
-          } else {
-            String v = val.toString();
-            if (val != null && v.length() > 0)
-              buf.append('=')
-                 .append('"')
-                 .append(val)
-                 .append('"');
+          Object val = cc.getExtension(ext); 
+          if (val != null) {
+            if (Number.class.isAssignableFrom(val.getClass()))
+              buf.append('=').append(val);            
+            else {
+              String v = val.toString();
+              if (v.length() > 0)
+                buf.append(
+                  format("=%s",quotedIfNotToken(v)));
+            }
           }
         }
         return buf.toString();
@@ -154,17 +121,17 @@ public final class CacheControlUtil {
         public void set(CacheControl.Builder builder, CacheControlParser parser) {
           switch (this) {
           case NOCACHE:
-              builder.noCache(true);
+              builder.noCache();
               builder.noCacheHeaders(parser.getValues(this));
               break;
           case NOSTORE:
-              builder.noStore(true);
+              builder.noStore();
               break;
           case NOTRANSFORM:
-              builder.noTransform(true);
+              builder.noTransform();
               break;
           case ONLYIFCACHED:
-              builder.onlyIfCached(true);
+              builder.onlyIfCached();
               break;
           case MAXAGE:
               builder.maxAge(value(parser.getValue(this)));
@@ -179,16 +146,16 @@ public final class CacheControlUtil {
               builder.staleIfError(value(parser.getValue(this)));
               break;
           case MUSTREVALIDATE:
-              builder.mustRevalidate(true);
+              builder.mustRevalidate();
               break;
           case PROXYREVALIDATE:
-              builder.proxyRevalidate(true);
+              builder.proxyRevalidate();
               break;
           case PUBLIC:
-              builder.isPublic(true);
+              builder.isPublic();
               break;
           case PRIVATE:
-              builder.isPrivate(true);
+              builder.isPrivate();
               builder.privateHeaders(parser.getValues(this));
             break;
           case STALEWHILEREVALIDATE:
@@ -209,8 +176,10 @@ public final class CacheControlUtil {
 
         private static final Pattern pattern = Pattern.compile(REGEX);
 
-        private final HashMap<Directive, String> values = new HashMap<Directive, String>();
-        private final HashMap<String,Object> exts = new HashMap<String,Object>();
+        private final Map<Directive, String> values = 
+          new LinkedHashMap<Directive, String>();
+        private final Map<String,Object> exts = 
+          new LinkedHashMap<String,Object>();
 
         public CacheControlParser(String value) {
             Matcher matcher = pattern.matcher(value);
@@ -225,33 +194,33 @@ public final class CacheControlUtil {
                     Long l = Long.parseLong(val);
                     exts.put(d, l);
                   } catch (Throwable t) {
-                    exts.put(d, val != null ? CharUtils.unquote(val) : "");
+                    exts.put(d, unquote(val!=null?val:""));
                   }
                 }
             }
         }
 
         public Map<String,Object> getExtensions() {
-          return exts;
+          return Collections.unmodifiableMap(exts);
         }
         
         public Map<Directive, String> getValues() {
-            return values;
+          return Collections.unmodifiableMap(values);
         }
 
         public String getValue(Directive directive) {
-            return values.get(directive);
+          return values.get(directive);
         }
 
         public Iterator<Directive> iterator() {
-            return values.keySet().iterator();
+          return Iterators.unmodifiableIterator(values.keySet().iterator());
         }
 
         public String[] getValues(Directive directive) {
-            String value = getValue(directive);
-            return value == null ?
-                null :
-                CharUtils.splitAndTrim(value);
+          String value = getValue(directive);
+          return value == null ?
+            null :
+            splitAndTrim(value);
         }
 
     }

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/EntityTag.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/EntityTag.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/EntityTag.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/EntityTag.java Mon Nov  7 21:31:52 2011
@@ -26,11 +26,16 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
+import org.apache.abdera2.common.misc.ExceptionHelper;
+import org.apache.abdera2.common.misc.MoreFunctions;
 import org.apache.abdera2.common.text.UrlEncoding;
 
 import com.google.common.base.Function;
 import com.google.common.base.Predicate;
+import com.google.common.collect.ImmutableSet;
+
 import static com.google.common.base.Preconditions.*;
+import static org.apache.abdera2.common.text.CharUtils.*;
 
 /**
  * Implements an EntityTag.
@@ -49,9 +54,8 @@ public class EntityTag 
       boolean wild = 
         entity_tag.charAt(0) == '*' && l == 0;
       if (wild) return EntityTag.WILD;
-      boolean weak = (entity_tag.charAt(0) == 'W' || 
-                     entity_tag.charAt(0) == 'w');
-      checkArgument(!(weak && entity_tag.charAt(1) !='/'),"Invalid");
+      boolean weak = Character.toUpperCase(entity_tag.charAt(0)) == 'W';
+      checkArgument(!weak || entity_tag.charAt(1) =='/',"Invalid");
       int pos = weak?2:0;
       checkArgument(
         entity_tag.charAt(pos) == '"' && 
@@ -63,14 +67,14 @@ public class EntityTag 
     public static Iterable<EntityTag> parseTags(String entity_tags) {
         if (entity_tags == null || 
             entity_tags.length() == 0)
-          return Collections.emptyList();
+          return ImmutableSet.<EntityTag>of();
         String[] tags = 
           entity_tags.split("((?<=\")\\s*,\\s*(?=([wW]/)?\"|\\*))");
         List<EntityTag> etags = 
           new ArrayList<EntityTag>();
         for (String tag : tags)
             etags.add(EntityTag.parse(tag.trim()));
-        return etags;
+        return ImmutableSet.<EntityTag>copyOf(etags);
     }
 
     public static Predicate<String> matchesAny(final EntityTag tag) {
@@ -296,26 +300,19 @@ public class EntityTag 
 
     public String toString() {
         StringBuilder buf = new StringBuilder();
-        if (wild) {
+        if (wild)
             buf.append("*");
-        } else {
-            if (weak)
-                buf.append("W/");
-            buf.append('"')
-               .append(tag)
-               .append('"');
+        else {
+          appendif(weak,buf,"W/");
+          buf.append(quoted(tag,true));
         }
         return buf.toString();
     }
 
     @Override
     public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ((tag == null) ? 0 : tag.hashCode());
-        result = prime * result + (weak ? 1231 : 1237);
-        result = prime * result + (wild ? 1231 : 1237);
-        return result;
+      return MoreFunctions.genHashCode(
+        1,tag,weak,wild);
     }
 
     @Override
@@ -450,28 +447,19 @@ public class EntityTag 
       StringBuilder buf = new StringBuilder();
       boolean first = true;
       for (EntityTag tag : tags) {
-        if (!first) buf.append(", ");
-        else first = !first;
+        first = appendcomma(first,buf);
         buf.append(tag.toString());
       }
       return buf.toString();
     }
     
     public int compareTo(EntityTag o) {
-        if (o.isWild() && !isWild())
-            return 1;
-        if (isWild() && !o.isWild())
-            return -1;
-        if (o.isWeak() && !isWeak())
-            return -1;
-        if (isWeak() && !o.isWeak())
-            return 1;
-        return tag.compareTo(o.tag);
+      return o.wild && !wild || weak && !o.weak ?
+        1 : wild && !o.wild || o.weak && !weak ? 
+       -1 : tag.compareTo(o.tag);
     }
     
-    public static interface EntityTagGenerator<T> {
-      EntityTag generateFor(T t);
-    }
+    public static interface EntityTagGenerator<T> extends Function<T,EntityTag> {}
     
     @Retention(RUNTIME)
     @Target( {TYPE})
@@ -483,27 +471,23 @@ public class EntityTag 
     public static <T>EntityTag generate(T t) {
       EntityTag etag = null;
       try {
-        if (t == null)
-          throw new IllegalArgumentException();
-        Class<?> _class = t.getClass();
+        Class<?> _class = checkNotNull(t).getClass();
         if (_class.isAnnotationPresent(ETagGenerator.class)) {
           ETagGenerator g = _class.getAnnotation(ETagGenerator.class);
           Class<? extends EntityTagGenerator<T>> gen = 
             (Class<? extends EntityTagGenerator<T>>) g.value();
           EntityTagGenerator<T> etg = 
             gen.newInstance();
-          etag = etg.generateFor(t);
+          etag = etg.apply(t);
         } else etag = generate(new String[] {t.toString()});
       } catch (Throwable e) {
-        throw new RuntimeException(e);
+        throw ExceptionHelper.propogate(e);
       }
       return etag;
     }
     
-    public static <T>EntityTag generator(T t, EntityTagGenerator<T> gen) {
-      if (t == null)
-        throw new IllegalArgumentException();
-      return gen.generateFor(t);
+    public static <T>EntityTag generate(T t, EntityTagGenerator<T> gen) {
+      return gen.apply(checkNotNull(t));
     }
     
 }

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/Method.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/Method.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/Method.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/Method.java Mon Nov  7 21:31:52 2011
@@ -20,6 +20,8 @@ package org.apache.abdera2.common.http;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
+import org.apache.abdera2.common.misc.MoreFunctions;
+
 public final class Method {
   
   private static final Map<String, Method> methods = 
@@ -120,12 +122,8 @@ public final class Method {
 
   @Override
   public int hashCode() {
-    final int prime = 31;
-    int result = 1;
-    result = prime * result + (idempotent ? 1231 : 1237);
-    result = prime * result + ((name == null) ? 0 : name.hashCode());
-    result = prime * result + (safe ? 1231 : 1237);
-    return result;
+    return MoreFunctions.genHashCode(
+      1, idempotent, name, safe);
   }
 
   @Override

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/Preference.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/Preference.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/Preference.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/Preference.java Mon Nov  7 21:31:52 2011
@@ -6,18 +6,25 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.LinkedHashMap;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import org.apache.abdera2.common.misc.MoreFunctions;
 import org.apache.abdera2.common.text.CharUtils;
+
+import static org.apache.abdera2.common.text.CharUtils.appendcomma;
 import static org.apache.abdera2.common.text.CharUtils.quotedIfNotToken;
 import org.apache.abdera2.common.text.Codec;
 import org.apache.abdera2.common.text.CharUtils.Profile;
+import static com.google.common.base.Preconditions.*;
 
 import com.google.common.base.Supplier;
+import com.google.common.collect.Iterables;
 
 /**
  * Implementation of the Prefer HTTP Header, e.g.
@@ -75,7 +82,7 @@ public class Preference implements Seria
     private String token;
     private String value;
     private final Map<String,String> params = 
-      new HashMap<String,String>();
+      new LinkedHashMap<String,String>();
     
     public Preference get() {
       return new Preference(this);
@@ -112,14 +119,20 @@ public class Preference implements Seria
     }
     
     public Builder param(String key, String val) {
-      if (key == null || reserved(key)) 
-        throw new IllegalArgumentException();
+      checkNotNull(key);
+      key = key.toLowerCase(Locale.US);
+      checkArgument(!reserved(key));
       this.params.put(key,val);
       return this;
     }
     
     public Builder params(Map<String,String> params) {
-      this.params.putAll(params);
+      checkNotNull(params);
+      for (Map.Entry<String,String> entry : params.entrySet()) {
+        String name = entry.getKey().toLowerCase(Locale.US);
+        checkArgument(!reserved(name));
+        this.params.put(name,entry.getValue());
+      }
       return this;
     }
     
@@ -151,7 +164,7 @@ public class Preference implements Seria
   
   public Preference(String token, String value) {
     Profile.TOKEN.verify(token);
-    this.token = token.toLowerCase();
+    this.token = token.toLowerCase(Locale.US);
     this.value = value;
   }
   
@@ -180,10 +193,8 @@ public class Preference implements Seria
   }
   
   private static final Set<String> reserved = 
-    new HashSet<String>();
-  static {
-    // no reserved yet
-  }
+    new HashSet<String>(); // no reserved yet
+  
   private static boolean reserved(String name) {
     return reserved.contains(name);
   }
@@ -195,12 +206,8 @@ public class Preference implements Seria
   
   @Override
   public int hashCode() {
-    final int prime = 31;
-    int result = 1;
-    result = prime * result + ((params == null) ? 0 : params.hashCode());
-    result = prime * result + ((token == null) ? 0 : token.hashCode());
-    result = prime * result + ((value == null) ? 0 : value.hashCode());
-    return result;
+    return MoreFunctions.genHashCode(
+      1, params, token, value);
   }
 
   @Override
@@ -231,8 +238,9 @@ public class Preference implements Seria
   }
 
   public String getParam(String name) {
-    if (name == null || reserved(name))
-      throw new IllegalArgumentException();
+    checkNotNull(name);
+    name = name.toLowerCase(Locale.US);
+    checkArgument(!reserved(name));
     return params.get(name);
   }
   
@@ -308,7 +316,7 @@ public class Preference implements Seria
       }
       prefs.add(maker.get());
     }
-    return prefs;
+    return Iterables.unmodifiableIterable(prefs);
   }
   
   public static String toString(
@@ -328,8 +336,7 @@ public class Preference implements Seria
     StringBuilder buf = new StringBuilder();
     boolean first = true;
     for (Preference pref : preferences) {
-      if (!first) buf.append(',');
-      else first = !first;
+      first = appendcomma(first,buf);
       buf.append(pref.toString());
     }
     return buf.toString();

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/QualityHelper.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/QualityHelper.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/QualityHelper.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/QualityHelper.java Mon Nov  7 21:31:52 2011
@@ -20,6 +20,8 @@ package org.apache.abdera2.common.http;
 import java.io.Serializable;
 import java.util.Arrays;
 
+import org.apache.abdera2.common.misc.MoreFunctions;
+
 import com.google.common.base.Function;
 
 public final class QualityHelper {
@@ -59,13 +61,8 @@ public final class QualityHelper {
       }
       @Override
       public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        long temp;
-        temp = Double.doubleToLongBits(qvalue);
-        result = prime * result + (int) (temp ^ (temp >>> 32));
-        result = prime * result + ((token == null) ? 0 : token.hashCode());
-        return result;
+        return MoreFunctions.genHashCode(
+          1, qvalue, token);
       }
       @Override
       public boolean equals(Object obj) {



Mime
View raw message