abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r1198949 [2/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
Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/WebLink.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/WebLink.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/WebLink.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/WebLink.java Mon Nov  7 21:31:52 2011
@@ -3,8 +3,8 @@ package org.apache.abdera2.common.http;
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.HashMap;
 import java.util.HashSet;
+import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Locale;
@@ -16,15 +16,15 @@ import javax.activation.MimeType;
 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.text.CharUtils;
+import org.apache.abdera2.common.misc.MoreFunctions;
 import org.apache.abdera2.common.text.Codec;
 
 import com.google.common.base.Function;
 import com.google.common.base.Supplier;
-import com.google.common.collect.Iterables;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
 
-import static org.apache.abdera2.common.text.CharUtils.scanFor;
-import static org.apache.abdera2.common.text.CharUtils.quotedIfNotToken;
+import static org.apache.abdera2.common.text.CharUtils.*;
 import static com.google.common.base.Preconditions.*;
 /**
  * Implements the HTTP Link Header
@@ -65,7 +65,7 @@ public class WebLink implements Serializ
     private String title;
     private MimeType mediaType;
     private final Map<String,String> params = 
-      new HashMap<String,String>();
+      new LinkedHashMap<String,String>();
 
     public Builder () {}
     
@@ -144,7 +144,7 @@ public class WebLink implements Serializ
     }
     
     public Builder param(String name, String value) {
-      checkNotNull(null);
+      checkNotNull(name);
       checkArgument(!reserved(name));
       this.params.put(name,value);
       return this;
@@ -156,37 +156,40 @@ public class WebLink implements Serializ
     }
     
     public Builder mediaType(String type) {
-      this.mediaType = MimeTypeHelper.create(type);
+      this.mediaType = MimeTypeHelper.unmodifiableMimeType(type);
       return this;
     }
     
     public Builder mediaType(MimeType type) {
-      this.mediaType = type;
+      this.mediaType = MimeTypeHelper.unmodifiableMimeType(type);
       return this;
     }
   }
   
   private final IRI iri;
-  private final Set<String> rel = 
-    new LinkedHashSet<String>();
+  private final Set<String> rel;
   private IRI anchor;
-  private final Set<String> rev =
-    new LinkedHashSet<String>();
+  private final Set<String> rev;
   private Lang lang;
-  private final Set<String> media = 
-    new LinkedHashSet<String>();
+  private final Set<String> media;
   private String title;
   private MimeType mediaType;
   private final Map<String,String> params = 
-    new HashMap<String,String>();
+    new LinkedHashMap<String,String>();
   
   private WebLink(Builder builder) {
     this.iri = builder.iri;
-    this.rel.addAll(builder.rel);
+    this.rel = builder.rel != null ?
+      ImmutableSet.copyOf(builder.rel) :
+      ImmutableSet.<String>of();
+    this.rev = builder.rev != null ?
+      ImmutableSet.copyOf(builder.rev) :
+      ImmutableSet.<String>of();
+    this.media = builder.media != null ?
+      ImmutableSet.copyOf(builder.media) :
+      ImmutableSet.<String>of();
     this.anchor = builder.anchor;
-    this.rev.addAll(builder.rev);
     this.lang = builder.lang;
-    this.media.addAll(builder.media);
     this.title = builder.title;
     this.mediaType = builder.mediaType;
     this.params.putAll(builder.params);
@@ -203,7 +206,11 @@ public class WebLink implements Serializ
   public WebLink(IRI iri, String rel) {
     checkNotNull(iri);
     this.iri = iri.normalize();
-    if (rel != null) this.rel.add(rel);
+    this.rel = rel != null ?
+      ImmutableSet.of(rel) :
+      ImmutableSet.<String>of();
+    this.rev = ImmutableSet.<String>of();
+    this.media = ImmutableSet.<String>of();
     this.anchor = null;
     this.lang = null;
     this.title = null;
@@ -217,6 +224,9 @@ public class WebLink implements Serializ
     this.lang = null;
     this.title = null;
     this.mediaType = null;
+    this.rel = ImmutableSet.<String>of();
+    this.rev = ImmutableSet.<String>of();
+    this.media = ImmutableSet.<String>of();
   }
   
   public IRI getResolvedIri(IRI base) {
@@ -236,7 +246,7 @@ public class WebLink implements Serializ
   }
   
   public Iterable<String> getRel() {
-    return Iterables.unmodifiableIterable(this.rel);
+    return this.rel;
   }
   
   public IRI getAnchor() {
@@ -244,7 +254,7 @@ public class WebLink implements Serializ
   }
   
   public Iterable<String> getRev() {
-    return Iterables.unmodifiableIterable(this.rev);
+    return this.rev;
   }
   
   public Lang getHrefLang() {
@@ -252,7 +262,7 @@ public class WebLink implements Serializ
   }
   
   public Iterable<String> getMedia() {
-    return Iterables.unmodifiableIterable(this.media);
+    return this.media;
   }
   
   public String getTitle() {
@@ -265,18 +275,10 @@ public class WebLink implements Serializ
   
   @Override
   public int hashCode() {
-    final int prime = 31;
-    int result = 1;
-    result = prime * result + ((anchor == null) ? 0 : anchor.hashCode());
-    result = prime * result + ((iri == null) ? 0 : iri.hashCode());
-    result = prime * result + ((lang == null) ? 0 : lang.hashCode());
-    result = prime * result + ((media == null) ? 0 : media.hashCode());
-    result = prime * result + ((mediaType == null) ? 0 : mediaType.toString().hashCode());
-    result = prime * result + ((params == null) ? 0 : params.hashCode());
-    result = prime * result + ((rel == null) ? 0 : rel.hashCode());
-    result = prime * result + ((rev == null) ? 0 : rev.hashCode());
-    result = prime * result + ((title == null) ? 0 : title.hashCode());
-    return result;
+    return MoreFunctions.genHashCode(
+      1, anchor,iri,lang,media,
+      mediaType,
+      params,rel,rev,title);
   }
 
   @Override
@@ -339,17 +341,10 @@ public class WebLink implements Serializ
 
 
   private static final Set<String> reserved = 
-    new HashSet<String>();
-  static {
-    reserved.add("rel");
-    reserved.add("anchor");
-    reserved.add("rev");
-    reserved.add("hreflang");
-    reserved.add("media");
-    reserved.add("title");
-    reserved.add("type");
-    reserved.add("type");
-  }
+    new HashSet<String>(
+      ImmutableSet.of(
+        "rel","anchor","rev","hreflang",
+        "media","title","type"));
   private static boolean reserved(String name) {
     return reserved.contains(name);
   }
@@ -360,104 +355,45 @@ public class WebLink implements Serializ
     return params.get(name);
   }
   
+  private void append(Set<String> set, String name, StringBuilder buf) {
+    if (set.size() > 0) {
+      buf.append(String.format(";%s=\"",name));
+      boolean first = true;
+      for (String r : set) {
+        first = appendcomma(first,buf);
+        buf.append(quotedIfNotToken(r,false));
+      }
+      buf.append('"');
+    }
+  }
+  
   public String toString() {
     StringBuilder buf = new StringBuilder();
     buf.append('<')
        .append(iri.toASCIIString())
        .append('>');
-    
-    if (rel.size() > 0) {
-      buf.append(';')
-         .append("rel=");
-      boolean first = true;
-      if (rel.size() > 1)
-        buf.append('"');
-      for (String r : rel) {
-        if (!first) buf.append(' ');
-        else first = false;
-        buf.append(quotedIfNotToken(r));
-      }
-      if (rel.size() > 1)
-        buf.append('"');
-    }
-    
-    if (anchor != null) {
-      buf.append(';')
-         .append("anchor=<")
-         .append(anchor.toASCIIString())
-         .append('>');
-    }
-    
-    if (rev.size() > 0) {
-      buf.append(';')
-         .append("rev=");
-      boolean first = true;
-      if (rev.size() > 1)
-        buf.append('"');
-      for (String r : rev) {
-        if (!first) buf.append(' ');
-        else first = false;
-        buf.append(quotedIfNotToken(r));
-      }
-      if (rev.size() > 1)
-        buf.append('"');
-    }
-    
-    if (lang != null) {
-      buf.append(';')
-         .append("hreflang=")
-         .append(lang.toString());
-    }
-    
-    if (media.size() > 0) {
-      buf.append(';')
-         .append("media=");
-      boolean first = true;
-      if (media.size() > 1)
-        buf.append('"');
-      for (String r : media) {
-        if (!first) buf.append(' ');
-        else first = false;
-        buf.append(quotedIfNotToken(r));
-      }
-      if (media.size() > 1)
-        buf.append('"');
-    }
-    
+    appendif(anchor != null,buf,";anchor=<%s>",anchor.toASCIIString());
+    appendif(lang != null,buf,";hreflang=%s",lang.toString());
+    appendif(mediaType != null,buf,";type=%s",quotedIfNotToken(mediaType.toString()));
+    append(rel,"rel",buf);
+    append(rev,"rev",buf);
+    append(media,"media",buf);
     if (title != null) {
       String enctitle = Codec.encode(title,Codec.STAR);
+      boolean test = title.equals(enctitle);
+      buf.append(";title");
+      appendif(!test,buf,"*=%s",enctitle);
+      appendif(test,buf,"=%s",quotedIfNotToken(title));
+    }
+    for (Map.Entry<String, String> entry : params.entrySet()) {
+      String val = entry.getValue();
+      String encval = Codec.encode(val,Codec.STAR);
+      boolean test = val.equals(encval);
       buf.append(';')
-         .append("title");
-      if (!title.equals(enctitle))
-        buf.append('*')
-           .append('=')
-           .append(enctitle);
-      else
-        buf.append('=')
-           .append(quotedIfNotToken(title));
-    }
-    
-   if (mediaType != null) {
-     buf.append(';')
-        .append("type=")
-        .append(quotedIfNotToken(mediaType.toString()));
-   }
-   
-   for (Map.Entry<String, String> entry : params.entrySet()) {
-     String val = entry.getValue();
-     String encval = Codec.encode(val,Codec.STAR);
-     buf.append(';')
-        .append(entry.getKey());
-     if (!val.equals(encval)) {
-       buf.append('*')
-          .append('=')
-          .append(encval);
-     } else {
-       buf.append('=')
-          .append(quotedIfNotToken(entry.getValue()));
-     }
-   }
-    
+         .append(entry.getKey());
+      appendif(!test,buf,"*=%s", encval);
+      appendif(test,buf,"=%s", quotedIfNotToken(entry.getValue()));
+    }
     return buf.toString();
   }
 
@@ -473,55 +409,46 @@ public class WebLink implements Serializ
   
   public static Iterable<WebLink> parse(String text) {
     List<WebLink> links = new ArrayList<WebLink>();
-    if (text == null) return Collections.emptyList();
-    
+    if (text == null) return ImmutableList.<WebLink>of();
     int z = scanFor('<', text, 0, true);
-
     while(z != -1) {
       int s = z;
       int e = scanFor('>', text, s, false);
-      if (e == -1)
-        throw new IllegalArgumentException();
-      
+      checkArgument(e != -1);
       String uri = text.substring(s+1,e).trim();
       WebLink.Builder maker = WebLink.make().iri(uri);
-      
       s = scanFor(';', text,e+1,false);
       while(s != -1 && text.charAt(s) != ',') {
         e = scanFor('=', text,s+1,false);
         String name = text.substring(s+1,text.charAt(e-1)=='*'?e-1:e).trim();
         s = scanFor(';', text,e+1,false);
         String val = s!=-1?text.substring(e+1,s).trim():text.substring(e+1).trim();
-        val = Codec.decode(val);
-        if (name.equalsIgnoreCase("rel")) {
-          String[] vals = CharUtils.unquote(val).split("\\s+");
-          for (String v : vals)
+        val = Codec.decode(val).toLowerCase(Locale.US);
+        if (name.equals("rel"))
+          for (String v : unquote(val).split("\\s+"))
             maker.rel(v);
-        } else if (name.equalsIgnoreCase("anchor")) {
-          maker.anchor(CharUtils.unwrap(val, '<', '>'));
-        } else if (name.equalsIgnoreCase("rev")) {
-          String[] vals = CharUtils.unquote(val).split("\\s+");
-          for (String v : vals)
+        else if (name.equals("anchor"))
+          maker.anchor(unwrap(val, '<', '>'));
+        else if (name.equals("rev"))
+          for (String v : unquote(val).split("\\s+"))
             maker.rev(v);
-        } else if (name.equalsIgnoreCase("hreflang")) {
-          maker.lang(CharUtils.unquote(val));
-        } else if (name.equalsIgnoreCase("media")) {
-          String[] vals = CharUtils.unquote(val).split("\\s+");
-          for (String v : vals)
+        else if (name.equals("hreflang"))
+          maker.lang(unquote(val));
+        else if (name.equals("media"))
+          for (String v : unquote(val).split("\\s+"))
             maker.media(v);
-        } else if (name.equalsIgnoreCase("title")) {
-          maker.title(CharUtils.unquote(val));
-        } else if (name.equalsIgnoreCase("type")) {
-          maker.mediaType(CharUtils.unquote(val));
-        } else {
-          maker.param(name,CharUtils.unquote(val));
-        }
+        else if (name.equals("title"))
+          maker.title(unquote(val));
+        else if (name.equals("type"))
+          maker.mediaType(unquote(val));
+        else
+          maker.param(name,unquote(val));
       }
       links.add(maker.get());
       if (s == -1) break;
       z = scanFor('<', text, s+1, false);
     }
-    return links;
+    return ImmutableList.copyOf(links);
   }
     
   public static String toString(WebLink link, WebLink... links) {
@@ -537,8 +464,7 @@ public class WebLink implements Serializ
     StringBuilder buf = new StringBuilder();
     boolean first = true;
     for (WebLink link : links) {
-      if (!first) buf.append(", ");
-      else first = !first;
+      first = appendcomma(first,buf);
       buf.append(link.toString());
     }
     return buf.toString();

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/io/CharsetSniffingInputStream.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/io/CharsetSniffingInputStream.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/io/CharsetSniffingInputStream.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/io/CharsetSniffingInputStream.java Mon Nov  7 21:31:52 2011
@@ -22,7 +22,9 @@ import java.io.IOException;
 import java.io.InputStream;
 
 /**
- * Will attempt to autodetect the character encoding from the stream By default, this will preserve the BOM if it exists
+ * Will attempt to autodetect the character encoding from the stream by 
+ * looking for the Byte Order Mark. This is at most a best guess.
+ * By default, this will preserve the BOM if it exists
  */
 public class CharsetSniffingInputStream extends FilterInputStream {
 

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/io/Compression.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/io/Compression.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/io/Compression.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/io/Compression.java Mon Nov  7 21:31:52 2011
@@ -25,9 +25,9 @@ import java.util.zip.GZIPInputStream;
 import java.util.zip.GZIPOutputStream;
 import java.util.zip.InflaterInputStream;
 
-import org.apache.abdera2.common.text.CharUtils;
-
+import static org.apache.abdera2.common.text.CharUtils.splitAndTrim;
 import static com.google.common.base.Preconditions.*;
+
 public class Compression {
 
     public enum CompressionCodec {
@@ -73,12 +73,16 @@ public class Compression {
         return codec;
     }
 
+    private static void checkCodecs(boolean exp) {
+      checkArgument(exp, "At least one codec must be specified");
+    }
+    
     public static OutputStream wrap(
         OutputStream out, 
         CompressionCodec... codecs)
         throws IOException {
       checkNotNull(out);
-      checkArgument(codecs.length > 0, "At least one codec must be specified");
+      checkCodecs(codecs.length > 0);
       for (int n = codecs.length - 1; n >= 0; n--)
         out = codecs[n].wrap(out);
       return out;      
@@ -90,19 +94,16 @@ public class Compression {
         CompressionCodec... codecs)
         throws IOException {
         checkNotNull(out);
-        checkArgument(codec != null, "At least one codec must be specified");
-        for (int n = codecs.length - 1; n >= 0; n--)
-          out = codecs[n].wrap(out);
-        out = codec.wrap(out);
-        return out;
+        checkCodecs(codec != null);
+        return codec.wrap(wrap(out,codecs));
     }
 
     public static InputStream wrap(
       InputStream in, 
       CompressionCodec... codecs)
-    throws IOException {
+      throws IOException {
       checkNotNull(in);
-      checkArgument(codecs.length > 0, "At least one codec must be specified");
+      checkCodecs(codecs.length > 0);
       for (int n = codecs.length - 1; n >= 0; n--)
         in = codecs[n].wrap(in);
       return in;
@@ -114,11 +115,8 @@ public class Compression {
         CompressionCodec... codecs) 
           throws IOException {  
         checkNotNull(in);
-        checkArgument(codec != null, "At least one codec must be specified");
-        for (int n = codecs.length - 1; n >= 0; n--)
-          in = codecs[n].wrap(in);
-        in = codec.wrap(in);
-        return in;
+        checkCodecs(codec != null);
+        return codec.wrap(wrap(in,codecs));
     }
 
     public static InputStream wrap(
@@ -126,13 +124,13 @@ public class Compression {
         String ce) 
           throws IOException {
         checkNotNull(in);
-        String[] encodings = CharUtils.splitAndTrim(ce);
-        checkArgument(encodings.length > 0, "At least one codec must be specified");
+        String[] encodings = splitAndTrim(ce);
+        checkCodecs(encodings.length > 0);
         for (int n = encodings.length - 1; n >= 0; n--) {
-            CompressionCodec encoding = 
-              getCodec(encodings[n]);
-            checkNotNull(encoding,"Invalid Compression Codec");
-            in = encoding.wrap(in);
+          CompressionCodec encoding = 
+            getCodec(encodings[n]);
+          checkNotNull(encoding,"Invalid Compression Codec");
+          in = encoding.wrap(in);
         }
         return in;
     }
@@ -140,7 +138,7 @@ public class Compression {
     public static String describe(
         CompressionCodec codec, 
         CompressionCodec... codecs) {
-        checkArgument(codec != null || codecs.length > 0, "At least one codec must be specified");
+        checkCodecs(codec != null || codecs.length > 0);
         int i = 0;
         if (codec == null) {
           codec = codecs[0];

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/io/FilteredCharReader.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/io/FilteredCharReader.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/io/FilteredCharReader.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/io/FilteredCharReader.java Mon Nov  7 21:31:52 2011
@@ -22,9 +22,10 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.Reader;
-import java.io.UnsupportedEncodingException;
 
+import org.apache.abdera2.common.misc.ExceptionHelper;
 import org.apache.abdera2.common.text.CharUtils.Profile;
+import static com.google.common.base.Preconditions.checkArgument;
 
 /**
  * A reader implementation that profiles out unwanted characters By default, unwanted characters are simply removed from
@@ -39,69 +40,94 @@ public class FilteredCharReader extends 
     private final Profile profile;
     private final char replacement;
 
-    public FilteredCharReader(InputStream in, Profile profile) {
-        this(new InputStreamReader(in), profile);
+    public FilteredCharReader(
+      InputStream in, 
+      Profile profile) {
+        this(reader(in), profile);
+    }
+
+    public FilteredCharReader(
+      InputStream in, 
+      String charset, 
+      Profile profile) {
+        this(reader(in, charset), profile);
+    }
+
+    public FilteredCharReader(
+      InputStream in, 
+      Profile profile, 
+      char replacement) {
+        this(reader(in), profile, replacement);
+    }
+
+    public FilteredCharReader(
+      InputStream in, 
+      String charset, 
+      Profile profile, 
+      char replacement) {
+        this(reader(in, charset), profile, replacement);
+    }
+
+    private static Reader reader(InputStream in) {
+      return new InputStreamReader(in);
+    }
+    
+    private static Reader reader(InputStream in, String charset) {
+      try {
+        return new InputStreamReader(in,charset);
+      } catch (Throwable t) {
+        throw ExceptionHelper.propogate(t);
+      }
     }
-
-    public FilteredCharReader(InputStream in, String charset, Profile profile) throws UnsupportedEncodingException {
-        this(new InputStreamReader(in, charset), profile);
-    }
-
-    public FilteredCharReader(InputStream in, Profile profile, char replacement) {
-        this(new InputStreamReader(in), profile, replacement);
-    }
-
-    public FilteredCharReader(InputStream in, String charset, Profile profile, char replacement)
-        throws UnsupportedEncodingException {
-        this(new InputStreamReader(in, charset), profile, replacement);
-    }
-
+    
     public FilteredCharReader(Reader in) {
-        this(in, Profile.NONOP, (char)0);
+      this(in, Profile.NONOP, (char)0);
     }
 
     public FilteredCharReader(Reader in, Profile profile) {
-        this(in, profile, (char)0);
+      this(in, profile, (char)0);
     }
 
     public FilteredCharReader(Reader in, char replacement) {
-        this(in, Profile.NONOP, replacement);
+      this(in, Profile.NONOP, replacement);
     }
 
     public FilteredCharReader(Reader in, Profile profile, char replacement) {
-        super(in);
-        this.profile = profile;
-        this.replacement = replacement;
-        if (replacement != 0 && ((!Character.isValidCodePoint(replacement)) || profile.apply(replacement)))
-            throw new IllegalArgumentException();
+      super(in);
+      this.profile = profile;
+      this.replacement = replacement;
+      checkArgument(
+        replacement == 0 ||
+        Character.isValidCodePoint(replacement) ||
+        !profile.apply(replacement)
+      );
     }
 
     @Override
     public int read() throws IOException {
-        int c = -1;
-        if (replacement == 0) {
-            while (((c = super.read()) != -1 && profile.apply(c))) {
-            }
-        } else {
-            c = super.read();
-            if (c != -1 && profile.apply(c))
-                c = replacement;
-        }
-        return c;
+      int c = -1;
+      if (replacement == 0)
+        while (((c = super.read()) != -1 && profile.apply(c))) {}
+      else {
+        c = super.read();
+        if (c != -1 && profile.apply(c))
+          c = replacement;
+      }
+      return c;
     }
 
     @Override
     public int read(char[] cbuf, int off, int len) throws IOException {
-        int n = off;
-        for (; n < Math.min(len, cbuf.length - off); n++) {
-            int r = read();
-            if (r != -1)
-                cbuf[n] = (char)r;
-            else
-                break;
-        }
-        n -= off;
-        return n <= 0 ? -1 : n;
+      int n = off;
+      for (; n < Math.min(len, cbuf.length - off); n++) {
+        int r = read();
+        if (r != -1)
+            cbuf[n] = (char)r;
+        else
+            break;
+      }
+      n -= off;
+      return n <= 0 ? -1 : n;
     }
 
 }

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/io/PeekAheadInputStream.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/io/PeekAheadInputStream.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/io/PeekAheadInputStream.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/io/PeekAheadInputStream.java Mon Nov  7 21:31:52 2011
@@ -28,20 +28,20 @@ import java.io.InputStream;
 public class PeekAheadInputStream extends RewindableInputStream {
 
     public PeekAheadInputStream(InputStream in) {
-        super(in);
+      super(in);
     }
 
     public PeekAheadInputStream(InputStream in, int initialSize) {
-        super(in, initialSize);
+      super(in, initialSize);
     }
 
     /**
      * Peek the next byte in the stream
      */
     public int peek() throws IOException {
-        int m = read();
-        unread(m);
-        return m;
+      int m = read();
+      unread(m);
+      return m;
     }
 
     /**
@@ -49,7 +49,7 @@ public class PeekAheadInputStream extend
      * reached
      */
     public int peek(byte[] buf) throws IOException {
-        return peek(buf, 0, buf.length);
+      return peek(buf, 0, buf.length);
     }
 
     /**
@@ -57,9 +57,9 @@ public class PeekAheadInputStream extend
      * reached
      */
     public int peek(byte[] buf, int off, int len) throws IOException {
-        int r = read(buf, off, len);
-        if (r > -1) unread(buf, off, r);
-        return r;
+      int r = read(buf, off, len);
+      if (r > -1) unread(buf, off, r);
+      return r;
     }
 
 }

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/iri/AbstractScheme.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/iri/AbstractScheme.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/iri/AbstractScheme.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/iri/AbstractScheme.java Mon Nov  7 21:31:52 2011
@@ -17,6 +17,8 @@
  */
 package org.apache.abdera2.common.iri;
 import static com.google.common.base.Preconditions.*;
+
+import org.apache.abdera2.common.misc.MoreFunctions;
 /**
  * Base implementation for IRI scheme providers
  */
@@ -56,11 +58,7 @@ public abstract class AbstractScheme imp
 
     @Override
     public int hashCode() {
-      final int prime = 31;
-      int result = 1;
-      result = prime * result + ((name == null) ? 0 : name.hashCode());
-      result = prime * result + port;
-      return result;
+      return MoreFunctions.genHashCode(1, name,port);
     }
 
     @Override

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/iri/IRI.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/iri/IRI.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/iri/IRI.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/iri/IRI.java Mon Nov  7 21:31:52 2011
@@ -24,6 +24,7 @@ import java.net.URISyntaxException;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import org.apache.abdera2.common.misc.MoreFunctions;
 import org.apache.abdera2.common.text.InvalidCharacterException;
 import org.apache.abdera2.common.text.NormalizationForm;
 import org.apache.abdera2.common.text.UrlEncoding;
@@ -136,17 +137,9 @@ public final class IRI implements Serial
 
     @Override
     public int hashCode() {
-        final int PRIME = 31;
-        int result = 1;
-        result = PRIME * result + ((authority == null) ? 0 : authority.hashCode());
-        result = PRIME * result + ((fragment == null) ? 0 : fragment.hashCode());
-        result = PRIME * result + ((host == null) ? 0 : host.hashCode());
-        result = PRIME * result + ((path == null) ? 0 : path.hashCode());
-        result = PRIME * result + port;
-        result = PRIME * result + ((query == null) ? 0 : query.hashCode());
-        result = PRIME * result + ((_scheme == null) ? 0 : _scheme.hashCode());
-        result = PRIME * result + ((userinfo == null) ? 0 : userinfo.hashCode());
-        return result;
+      return MoreFunctions.genHashCode(
+        1, authority, fragment, host, path, 
+        port, query, _scheme, userinfo);
     }
 
     @Override

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/lang/Lang.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/lang/Lang.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/lang/Lang.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/lang/Lang.java Mon Nov  7 21:31:52 2011
@@ -25,7 +25,11 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import org.apache.abdera2.common.lang.Subtag.Type;
+import static org.apache.abdera2.common.misc.MoreFunctions.*;
+import static org.apache.abdera2.common.text.CharUtils.*;
+import static com.google.common.base.Preconditions.checkArgument;
 
+import com.google.common.base.Function;
 import com.google.common.collect.Iterables;
 
 /**
@@ -273,55 +277,46 @@ public final class Lang 
             return new Lang(primary);
         }
         m = p_langtag.matcher(lang);
-        if (m.find()) {
-            String langtag = m.group(1);
-            String script = m.group(2);
-            String region = m.group(3);
-            String variant = m.group(4);
-            String extension = m.group(5);
-            String privateuse = m.group(6);
-            Subtag current = null;
-            String[] tags = langtag.split(SEP);
-            for (String tag : tags)
-                current = current == null ? 
-                    primary = new Subtag(Type.LANGUAGE, tag) :
-                    new Subtag(Type.EXTLANG, tag, current);
-            if (script != null && script.length() > 0)
-                current = new Subtag(Type.SCRIPT, script.substring(1), current);
-            if (region != null && region.length() > 0)
-                current = new Subtag(Type.REGION, region.substring(1), current);
-            if (variant != null && variant.length() > 0) {
-                variant = variant.substring(1);
-                tags = variant.split(SEP);
-                for (String tag : tags)
-                    current = new Subtag(Type.VARIANT, tag, current);
-            }
-            if (extension != null && extension.length() > 0) {
-                extension = extension.substring(1);
-                tags = extension.split(SEP);
-                current = new Subtag(Type.SINGLETON, tags[0], current);
-                for (int i = 1; i < tags.length; i++) {
-                    String tag = tags[i];
-                    current = new Subtag(
-                        tag.length() == 1 ? 
-                            Type.SINGLETON : 
-                            Type.EXTENSION, 
-                        tag, 
-                        current);
-                }
-            }
-            if (privateuse != null && privateuse.length() > 0) {
-                privateuse = privateuse.substring(1);
-                tags = privateuse.split(SEP);
-                current = new Subtag(Type.SINGLETON, tags[0], current);
-                for (int i = 1; i < tags.length; i++)
-                    current = new Subtag(Type.PRIVATEUSE, tags[i], current);
-            }
-            return new Lang(primary);
+        checkArgument(m.find());
+        String langtag = m.group(1);
+        String script = m.group(2);
+        String region = m.group(3);
+        String variant = m.group(4);
+        String extension = m.group(5);
+        String privateuse = m.group(6);
+        Subtag current = null;
+        String[] tags = langtag.split(SEP);
+        for (String tag : tags)
+          current = current == null ? 
+            primary = Subtag.language(tag) :
+            Subtag.extlang(tag, current);
+        if (not_empty(script))
+          current = Subtag.script(script.substring(1), current);
+        if (not_empty(region))
+          current = Subtag.region(region.substring(1), current);
+        if (not_empty(variant))
+          for (String tag : variant.substring(1).split(SEP))
+            current = Subtag.variant(tag, current);
+        if (not_empty(extension)) {
+          tags = extension.substring(1).split(SEP);
+          current = Subtag.singleton(tags[0], current);
+          for (int i = 1; i < tags.length; i++) {
+            String tag = tags[i];
+            current = tag.length() == 1?
+              Subtag.singleton(tag, current) :
+              Subtag.extension(tag, current);
+          }
         }
-        throw new IllegalArgumentException();
-    }
+        if (not_empty(privateuse)) {
+          tags = privateuse.substring(1).split(SEP);
+          current = Subtag.singleton(tags[0], current);
+          for (int i = 1; i < tags.length; i++)
+            current = Subtag.privateuse(tags[i], current);
+        }
+        return new Lang(primary);
 
+    }
+    
     public static String fromLocale(Locale locale) {
         return new Lang(locale).toString();
     }
@@ -330,15 +325,15 @@ public final class Lang 
       return new Lang(Locale.getDefault());
     }
     
-    private static Lang[] available_langs;
-    static {
-      try {
-         Locale[] available_locales = Locale.getAvailableLocales();
-         available_langs = new Lang[available_locales.length];
-         for (int n = 0; n < available_locales.length; n++) 
-           available_langs[n] = new Lang(available_locales[n]);
-      } catch (Throwable t) {}
-    }
+    private static Lang[] available_langs = 
+      each(
+        Locale.getAvailableLocales(), 
+        new Function<Locale,Lang>() {
+          public Lang apply(Locale input) {
+            return new Lang(input);
+          }
+        },
+        Lang.class);
     
     public static Lang[] getAvailableLangs() {
       return available_langs;

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/lang/Range.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/lang/Range.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/lang/Range.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/lang/Range.java Mon Nov  7 21:31:52 2011
@@ -30,6 +30,9 @@ import com.google.common.base.Function;
 import com.google.common.base.Predicate;
 import com.google.common.collect.Iterables;
 
+import static org.apache.abdera2.common.text.CharUtils.*;
+import static com.google.common.base.Preconditions.*;
+
 /**
  * A language range used for matching language tags
  */
@@ -40,37 +43,41 @@ public final class Range 
     private final boolean extended;
 
     public Range(String range, boolean extended) {
-        super(parse(range, extended).root);
+        super(parse(checkNotNull(range), extended).root);
         this.extended = extended;
     }
 
     public Range(String range) {
-        this(parse(range).root);
+        this(parse(checkNotNull(range)).root);
     }
 
     public Range(Lang lang) {
-        this(lang.toString());
+        this(checkNotNull(lang).toString());
     }
 
     public Range(Lang lang, boolean extended) {
-        this(lang.toString(), extended);
+        this(checkNotNull(lang).toString(), extended);
     }
 
     Range(Subtag primary) {
-        super(primary);
+        super(checkNotNull(primary));
         this.extended = !checkBasic();
     }
 
     public Range append(Subtag subtag) {
-        Subtag last = null;
-        for (Subtag tag : this)
-            last = tag;
-        last.setNext(subtag);
-        return this;
+      Subtag last = null, first = null;
+      for (Subtag tag : this) {
+        last = new Subtag(tag,last);
+        if (first == null) first = last;
+      }
+      if (last == null)
+        last = subtag;
+      last.setNext(subtag);
+      return new Range(first);
     }
 
     public Range appendWildcard() {
-        return append(Subtag.newWildcard());
+      return append(Subtag.newWildcard());
     }
 
     public Range toBasicRange() {
@@ -317,39 +324,30 @@ public final class Range 
      */
     public static Range parse(String range, boolean extended) {
         if (!extended) {
-            Subtag primary = null, current = null;
-            Matcher m = p_range.matcher(range);
-            if (m.find()) {
-                String first = m.group(1);
-                String therest = m.group(2);
-                current = primary =
-                    new Subtag(first.equals("*") ? 
-                        Subtag.Type.WILDCARD : 
-                        Subtag.Type.SIMPLE, first
-                        .toLowerCase(Locale.US));
-                Matcher n = p_range_component.matcher(therest);
-                while (n.find()) {
-                    String name = n.group(1).toLowerCase(Locale.US);
-                    current = new Subtag(
-                        name.equals("*") ? 
-                            Subtag.Type.WILDCARD : 
-                            Subtag.Type.SIMPLE, 
-                        name, 
-                        current);
-                }
+          Subtag primary = null, current = null;
+          Matcher m = p_range.matcher(range);
+          if (m.find()) {
+            String first = m.group(1);
+            String therest = m.group(2);
+            current = primary =
+              Subtag.simple(first.toLowerCase(Locale.US));
+            Matcher n = p_range_component.matcher(therest);
+            while (n.find()) {
+              String name = n.group(1).toLowerCase(Locale.US);
+              current = Subtag.simple(name, current);
             }
-            return new Range(primary);
+          }
+          return new Range(primary);
         } else {
-
             Subtag primary = null;
             Matcher m = p_grandfathered.matcher(range);
             if (m.find()) {
                 String[] tags = range.split(SEP);
                 Subtag current = null;
                 for (String tag : tags)
-                    current = current == null ?
-                        primary = new Subtag(Type.GRANDFATHERED, tag) :
-                        new Subtag(Type.GRANDFATHERED,tag,current);
+                  current = current == null ?
+                    primary = Subtag.grandfathered(tag) :
+                    Subtag.grandfathered(tag,current);
                 return new Range(primary);
             }
             m = p_privateuse.matcher(range);
@@ -363,64 +361,53 @@ public final class Range 
                 return new Range(primary);
             }
             m = p_extended_range.matcher(range);
-            if (m.find()) {
-                String langtag = m.group(1);
-                String script = m.group(2);
-                String region = m.group(3);
-                String variant = m.group(4);
-                String extension = m.group(5);
-                String privateuse = m.group(6);
-                Subtag current = null;
-                String[] tags = langtag.split(SEP);
-                for (String tag : tags)
-                    current = current == null ?
-                        primary = new Subtag(tag.equals("*") ? Type.WILDCARD : Type.LANGUAGE, tag) :
-                        new Subtag(tag.equals("*") ? Type.WILDCARD : Type.EXTLANG, tag, current);
-                if (script != null && script.length() > 0)
-                    current =
-                        new Subtag(
-                            script.substring(1).equals("*") ? 
-                                Type.WILDCARD : 
-                                Type.SCRIPT, 
-                            script.substring(1),
-                            current);
-                if (region != null && region.length() > 0)
-                    current =
-                        new Subtag(
-                            region.substring(1).equals("*") ? 
-                                Type.WILDCARD : 
-                                Type.REGION, 
-                            region.substring(1),
-                            current);
-                if (variant != null && variant.length() > 0) {
-                    variant = variant.substring(1);
-                    tags = variant.split(SEP);
-                    for (String tag : tags)
-                        current = new Subtag(tag.equals("*") ? Type.WILDCARD : Type.VARIANT, tag, current);
-                }
-                if (extension != null && extension.length() > 0) {
-                    extension = extension.substring(1);
-                    tags = extension.split(SEP);
-                    current = new Subtag(tags[0].equals("*") ? Type.WILDCARD : Type.SINGLETON, tags[0], current);
-                    for (int i = 1; i < tags.length; i++) {
-                        String tag = tags[i];
-                        current =
-                            new Subtag(tag.equals("*") ? Type.WILDCARD : tag.length() == 1 ? Type.SINGLETON
-                                : Type.EXTENSION, tag, current);
-                    }
-                }
-                if (privateuse != null && privateuse.length() > 0) {
-                    privateuse = privateuse.substring(1);
-                    tags = privateuse.split(SEP);
-                    current = new Subtag(tags[0].equals("*") ? Type.WILDCARD : Type.SINGLETON, tags[0], current);
-                    for (int i = 1; i < tags.length; i++) {
-                        current = new Subtag(tags[i].equals("*") ? Type.WILDCARD : Type.PRIVATEUSE, tags[i], current);
-                    }
-                }
-                return new Range(primary);
+            checkArgument(m.find());
+            String langtag = m.group(1);
+            String script = m.group(2);
+            String region = m.group(3);
+            String variant = m.group(4);
+            String extension = m.group(5);
+            String privateuse = m.group(6);
+            Subtag current = null;
+            String[] tags = langtag.split(SEP);
+            for (String tag : tags)
+              current = current == null ?
+                primary = Subtag.language(tag) :
+                Subtag.extlang(tag, current);
+            if (not_empty(script))
+              current =
+                Subtag.script(
+                  script.substring(1),
+                  current);
+            if (not_empty(region))
+              current =
+                Subtag.region(
+                  region.substring(1),
+                  current);
+            if (not_empty(variant)) {
+              for (String tag : variant.substring(1).split(SEP))
+                current = Subtag.variant(tag, current);
+            }
+            if (not_empty(extension)) {
+              tags = extension.substring(1).split(SEP);
+              current = Subtag.singleton(tags[0], current);
+              for (int i = 1; i < tags.length; i++) {
+                String tag = tags[i];
+                current =
+                  tag.length() == 1 ?
+                    Subtag.singleton(tag, current) :
+                    Subtag.extension(tag, current);
+              }
+            }
+            if (not_empty(privateuse)) {
+              tags = privateuse.substring(1).split(SEP);
+              current = Subtag.singleton(tags[0], current);
+              for (int i = 1; i < tags.length; i++)
+                current = Subtag.privateuse(tags[i], current);
             }
+            return new Range(primary);
         }
-        throw new IllegalArgumentException("Invalid range");
+
     }
 
 }

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/lang/Subtag.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/lang/Subtag.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/lang/Subtag.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/lang/Subtag.java Mon Nov  7 21:31:52 2011
@@ -20,6 +20,8 @@ package org.apache.abdera2.common.lang;
 import java.io.Serializable;
 import java.util.Locale;
 
+import org.apache.abdera2.common.misc.MoreFunctions;
+
 /**
  * A Language Tab Subtag. Instances are immutable and safe to use by
  * multiple threads.
@@ -29,6 +31,86 @@ public final class Subtag 
 
     private static final long serialVersionUID = -4496128268514329138L;
 
+    public static Subtag language(String name) {
+      return new Subtag(name.equals("*") ? Type.WILDCARD : Type.LANGUAGE, name);
+    }
+    
+    public static Subtag language(String name, Subtag prev) {
+      return new Subtag(name.equals("*") ? Type.WILDCARD : Type.LANGUAGE, name, prev);
+    }
+    
+    public static Subtag extlang(String name) {
+      return new Subtag(name.equals("*") ? Type.WILDCARD : Type.EXTLANG, name);
+    }
+    
+    public static Subtag extlang(String name, Subtag prev) {
+      return new Subtag(name.equals("*") ? Type.WILDCARD : Type.EXTLANG, name, prev);
+    }
+    
+    public static Subtag script(String name) {
+      return new Subtag(name.equals("*") ? Type.WILDCARD : Type.SCRIPT, name);
+    }
+    
+    public static Subtag script(String name, Subtag prev) {
+      return new Subtag(name.equals("*") ? Type.WILDCARD : Type.SCRIPT, name, prev);
+    }
+    
+    public static Subtag region(String name) {
+      return new Subtag(name.equals("*") ? Type.WILDCARD : Type.REGION, name);
+    }
+    
+    public static Subtag region(String name, Subtag prev) {
+      return new Subtag(name.equals("*") ? Type.WILDCARD : Type.REGION, name, prev);
+    }
+    
+    public static Subtag variant(String name) {
+      return new Subtag(name.equals("*") ? Type.WILDCARD : Type.VARIANT, name);
+    }
+    
+    public static Subtag variant(String name, Subtag prev) {
+      return new Subtag(name.equals("*") ? Type.WILDCARD : Type.VARIANT, name, prev);
+    }
+    
+    public static Subtag singleton(String name) {
+      return new Subtag(name.equals("*") ? Type.WILDCARD : Type.SINGLETON, name);
+    }
+    
+    public static Subtag singleton(String name, Subtag prev) {
+      return new Subtag(name.equals("*") ? Type.WILDCARD : Type.SINGLETON, name, prev);
+    }
+    
+    public static Subtag extension(String name) {
+      return new Subtag(name.equals("*") ? Type.WILDCARD : Type.EXTENSION, name);
+    }
+    
+    public static Subtag extension(String name, Subtag prev) {
+      return new Subtag(name.equals("*") ? Type.WILDCARD : Type.EXTENSION, name, prev);
+    }
+    
+    public static Subtag privateuse(String name) {
+      return new Subtag(name.equals("*") ? Type.WILDCARD : Type.PRIVATEUSE, name);
+    }
+    
+    public static Subtag privateuse(String name, Subtag prev) {
+      return new Subtag(name.equals("*") ? Type.WILDCARD : Type.PRIVATEUSE, name, prev);
+    }
+    
+    public static Subtag grandfathered(String name) {
+      return new Subtag(name.equals("*") ? Type.WILDCARD : Type.GRANDFATHERED, name);
+    }
+    
+    public static Subtag grandfathered(String name, Subtag prev) {
+      return new Subtag(name.equals("*") ? Type.WILDCARD : Type.GRANDFATHERED, name, prev);
+    }
+   
+    public static Subtag simple(String name) {
+      return new Subtag(name.equals("*") ? Type.WILDCARD : Type.SIMPLE, name);
+    }
+    
+    public static Subtag simple(String name, Subtag prev) {
+      return new Subtag(name.equals("*") ? Type.WILDCARD : Type.SIMPLE, name, prev);
+    }
+    
     public enum Type {
         LANGUAGE,
         EXTLANG,
@@ -109,22 +191,22 @@ public final class Subtag 
         return toString();
     }
 
-    void setPrevious(Subtag prev) {
-        this.prev = prev;
-    }
-
     public Subtag previous() {
-        return prev;
+      return prev;
     }
 
+    void setPrevious(Subtag prev) {
+      this.prev = prev;
+    }
+    
     void setNext(Subtag next) {
-        this.next = next;
-        if (next != null)
-            next.setPrevious(this);
+      this.next = next;
+      if (next != null)
+          next.setPrevious(this);
     }
 
     public Subtag next() {
-        return next;
+      return next;
     }
 
     public String toString() {
@@ -149,13 +231,8 @@ public final class Subtag 
     }
 
     public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ((name == null) ? 0 : 
-          name.toLowerCase(Locale.US).hashCode());
-        result = prime * result + ((type == null) ? 0 : 
-          type.hashCode());
-        return result;
+      return MoreFunctions.genHashCode(
+        1, name.toLowerCase(Locale.US), type);
     }
 
     public boolean equals(Object obj) {

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/lang/SubtagSet.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/lang/SubtagSet.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/lang/SubtagSet.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/lang/SubtagSet.java Mon Nov  7 21:31:52 2011
@@ -24,6 +24,7 @@ import java.util.LinkedList;
 import java.util.List;
 
 import org.apache.abdera2.common.lang.Subtag.Type;
+import org.apache.abdera2.common.misc.MoreFunctions;
 
 public abstract class SubtagSet 
   implements Serializable, 
@@ -124,11 +125,7 @@ public abstract class SubtagSet 
     }
 
     public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        for (Subtag tag : this)
-            result = prime * result + tag.hashCode();
-        return result;
+      return MoreFunctions.genHashCode(1, this);
     }
 
     public boolean equals(Object obj) {

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/mediatype/MimeTypeHelper.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/mediatype/MimeTypeHelper.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/mediatype/MimeTypeHelper.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/mediatype/MimeTypeHelper.java Mon Nov  7 21:31:52 2011
@@ -27,11 +27,15 @@ import javax.activation.MimeType;
 import javax.activation.MimeTypeParameterList;
 
 import org.apache.abdera2.common.Constants;
+import org.apache.abdera2.common.misc.ExceptionHelper;
 
 import com.google.common.base.Equivalence;
 import com.google.common.base.Function;
 import com.google.common.base.Predicate;
 
+import static org.apache.abdera2.common.misc.Comparisons.*;
+import static org.apache.abdera2.common.text.CharUtils.not_empty;
+
 /**
  * Utilities for working with MIME Media Types
  */
@@ -39,7 +43,10 @@ public final class MimeTypeHelper {
 
     private MimeTypeHelper() {}
   
-    private static final MimeType WILDCARD = createWildcard();
+    public static final MimeType WILDCARD = createWildcard();
+    public static final MimeType ATOM = unmodifiableMimeType(Constants.ATOM_MEDIA_TYPE);
+    public static final MimeType ENTRY = unmodifiableMimeType(Constants.ENTRY_MEDIA_TYPE);
+    public static final MimeType FEED = unmodifiableMimeType(Constants.FEED_MEDIA_TYPE);
 
     public static String getCharset(String mediatype) {
         try {
@@ -59,11 +66,7 @@ public final class MimeTypeHelper {
     }
 
     private static MimeType createWildcard() {
-        try {
-            return new MimeType("*/*");
-        } catch (Exception e) {
-            return null; // Won't happen
-        }
+      return unmodifiableMimeType("*/*");
     }
 
     public static Predicate<String> isMatch(final String a) {
@@ -94,16 +97,11 @@ public final class MimeTypeHelper {
      * Returns true if media type a matches media type b
      */
     public static boolean isMatch(String a, String b) {
-        if ((a == null || a.length() == 0) && (b == null || b.length() == 0))
-            return true;
-        boolean answer = false;
-        try {
-            MimeType mta = new MimeType(a.toLowerCase());
-            MimeType mtb = new MimeType(b.toLowerCase());
-            return isMatch(mta, mtb);
-        } catch (Exception e) {
-        }
-        return answer;
+        if (bothAreEmpty(a, b)) return true;
+        if (onlyOneIsNull(a, b)) return false;
+        return isMatch(
+          unmodifiableMimeType(a.toLowerCase()), 
+          unmodifiableMimeType(b.toLowerCase()));
     }
 
     public static boolean isMatch(MimeType a, MimeType b) {
@@ -114,48 +112,34 @@ public final class MimeTypeHelper {
      * Returns true if media type a matches media type b
      */
     public static boolean isMatch(MimeType a, MimeType b, boolean includeparams) {
-        try {
-            if (a == null || b == null)
-                return true;
-            if (a.match(b)) {
-                if (includeparams) {
-                    MimeTypeParameterList aparams = a.getParameters();
-                    MimeTypeParameterList bparams = b.getParameters();
-                    if (aparams.isEmpty() && bparams.isEmpty())
-                        return true;
-                    if (aparams.isEmpty() && !bparams.isEmpty())
-                        return false;
-                    if (!aparams.isEmpty() && bparams.isEmpty())
-                        return false;
-                    boolean answer = true;
-                    for (Enumeration<?> e = aparams.getNames(); e.hasMoreElements();) {
-                        String aname = (String)e.nextElement();
-                        String avalue = aparams.get(aname);
-                        String bvalue = bparams.get(aname);
-                        if (avalue.equals(bvalue))
-                            answer = true;
-                        else {
-                            answer = false;
-                            break;
-                        }
-                    }
-                    return answer;
-                } else
-                    return true;
-            }
-            if (a.equals(WILDCARD))
-                return true;
-            if (a.getPrimaryType().equals("*")) {
-                MimeType c = new MimeType(b.getPrimaryType(), a.getSubType());
-                return isMatch(c, b);
-            }
-            if (b.getPrimaryType().equals("*")) {
-                MimeType c = new MimeType(a.getPrimaryType(), b.getSubType());
-                return isMatch(a, c);
-            }
-        } catch (Exception e) {
-        }
-        return false;
+      if (bothAreNull(a,b))
+          return true;
+      if (a.match(b))
+        if (includeparams) {
+          MimeTypeParameterList aparams = a.getParameters();
+          MimeTypeParameterList bparams = b.getParameters();
+          if (bothAreTrue(aparams.isEmpty(),bparams.isEmpty()))
+              return true;
+          if (onlyOneIsTrue(aparams.isEmpty(),bparams.isEmpty()))
+              return false;
+          for (Enumeration<?> e = aparams.getNames(); e.hasMoreElements();) {
+            String aname = (String)e.nextElement();
+            String avalue = aparams.get(aname);
+            String bvalue = bparams.get(aname);
+            if (!avalue.equals(bvalue))
+              return false;
+          }
+          return true;
+        } else
+            return true;
+      if (a.equals(WILDCARD))
+          return true;
+      if (a.getPrimaryType().equals("*"))
+        return isMatch(unmodifiableMimeType(b.getPrimaryType() + "/" + a.getSubType()), b);
+      if (b.getPrimaryType().equals("*"))
+        return isMatch(a, unmodifiableMimeType(a.getPrimaryType() + "/" + b.getSubType()));
+
+      return false;
     }
 
     private static boolean isMatchType(String actual, String expected) {
@@ -240,9 +224,9 @@ public final class MimeTypeHelper {
     public static boolean isEntry(String a) {
         try {
             MimeType mta = new MimeType(a.toLowerCase());
-            MimeType mtb = new MimeType(Constants.ATOM_MEDIA_TYPE);
-            MimeType mtc = new MimeType(Constants.ENTRY_MEDIA_TYPE);
-            return isMatch(mta, mtc) || (isMatch(mta, mtb) && isMatchType(mta.getParameter("type"), "entry"));
+            return isMatch(mta, ENTRY) || 
+                  (isMatch(mta, ATOM) && 
+                   isMatchType(mta.getParameter("type"), "entry"));
         } catch (Exception e) {
         }
         return false;
@@ -254,9 +238,9 @@ public final class MimeTypeHelper {
     public static boolean isFeed(String a) {
         try {
             MimeType mta = new MimeType(a.toLowerCase());
-            MimeType mtb = new MimeType(Constants.ATOM_MEDIA_TYPE);
-            MimeType mtc = new MimeType(Constants.FEED_MEDIA_TYPE);
-            return isMatch(mta, mtc) || (isMatch(mta, mtb) && isMatchType(mta.getParameter("type"), "feed"));
+            return isMatch(mta, FEED) || 
+                  (isMatch(mta, ATOM) && 
+                   isMatchType(mta.getParameter("type"), "feed"));
         } catch (Exception e) {
         }
         return false;
@@ -271,8 +255,10 @@ public final class MimeTypeHelper {
             try {
                 MimeType mta = new MimeType(a);
                 answer =
-                    (("application".equalsIgnoreCase(mta.getPrimaryType()) || "text".equalsIgnoreCase(mta
-                        .getPrimaryType())) && mta.getSubType().equals("xml") || mta.getSubType().endsWith("+xml"));
+                    (("application".equalsIgnoreCase(mta.getPrimaryType()) ||
+                      "text".equalsIgnoreCase(mta.getPrimaryType())) && 
+                      mta.getSubType().equals("xml") || 
+                      mta.getSubType().endsWith("+xml"));
             } catch (Exception e) {
             }
         }
@@ -405,8 +391,56 @@ public final class MimeTypeHelper {
     public static final Function<String,MimeType> parser = 
       new Function<String,MimeType>() {
         public MimeType apply(String input) {
-          return input != null ? MimeTypeHelper.create(input) : null;
+          return input != null ? unmodifiableMimeType(input) : null;
         }
       
     };
+    
+  public static MimeType unmodifiableMimeType(String mimeType) {
+    try {
+      return new UnmodifiableMimeType(mimeType);
+    } catch (javax.activation.MimeTypeParseException t) {
+      throw ExceptionHelper.propogate(t);
+    }
+  }
+
+  public static MimeType unmodifiableMimeType(MimeType mimeType) {
+    try {
+      return mimeType instanceof UnmodifiableMimeType ?
+        mimeType :
+        new UnmodifiableMimeType(mimeType.toString());
+    } catch (javax.activation.MimeTypeParseException t) {
+      throw ExceptionHelper.propogate(t);
+    }
+  }
+  
+    
+  public static class UnmodifiableMimeType extends MimeType {
+    public UnmodifiableMimeType() {
+      super();
+    }
+    public UnmodifiableMimeType(String primary, String sub)
+        throws javax.activation.MimeTypeParseException {
+      super(primary, sub);
+    }
+    public UnmodifiableMimeType(String rawdata)
+        throws javax.activation.MimeTypeParseException {
+      super(rawdata);
+    }
+    public void setPrimaryType(String primary)
+        throws javax.activation.MimeTypeParseException {
+      throw new UnsupportedOperationException();
+    }
+    public void setSubType(String sub)
+        throws javax.activation.MimeTypeParseException {
+      throw new UnsupportedOperationException();
+    }
+    public void setParameter(String name, String value) {
+      throw new UnsupportedOperationException();
+    }
+    public void removeParameter(String name) {
+      throw new UnsupportedOperationException();
+    }
+    
+  }
 }

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/Chain.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/Chain.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/Chain.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/Chain.java Mon Nov  7 21:31:52 2011
@@ -116,4 +116,5 @@ public final class Chain<T,R> 
         return out != null ? out.apply(output) : output;
       }
     }
+
 }

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/Comparisons.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/Comparisons.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/Comparisons.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/Comparisons.java Mon Nov  7 21:31:52 2011
@@ -1,5 +1,7 @@
 package org.apache.abdera2.common.misc;
 
+import org.apache.abdera2.common.text.CharUtils;
+
 import com.google.common.base.Equivalence;
 import com.google.common.base.Predicate;
 import static com.google.common.base.Preconditions.*;
@@ -50,6 +52,18 @@ public class Comparisons {
     return onlySecondIsNull().apply(t1,t2);
   }
   
+  public static boolean bothAreTrue(boolean t1, boolean t2) {
+    return t1 && t2;
+  }
+  
+  public static boolean onlyOneIsTrue(boolean t1, boolean t2) {
+    return t1 |= t2;
+  }
+  
+  public static boolean bothAreEmpty(String t1, String t2) {
+    return !CharUtils.not_empty(t1) && !CharUtils.not_empty(t2);
+  }
+  
   public static <T>boolean onlyOneIsNull(T t1, T t2) {
     return onlyOneIsNull().apply(t1,t2);
   }

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/MapRed.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/MapRed.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/MapRed.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/MapRed.java Mon Nov  7 21:31:52 2011
@@ -100,7 +100,7 @@ public final class MapRed {
     private final List<Pair<K,V>> list = 
       new ArrayList<Pair<K,V>>();
     public PairBuilder<K,V> pair(K k, V v) {
-      list.add(MapRed.<K,V>pair(k,v));
+      list.add(Pair.<K,V>of(k,v));
       return this;
     }
     public Iterable<Pair<K, V>> get() {
@@ -114,29 +114,10 @@ public final class MapRed {
   public static <K,V>Iterable<Pair<K,V>> pairs(Map<K,V> map) {
     List<Pair<K,V>> list = new ArrayList<Pair<K,V>>();
     for (Map.Entry<K,V> entry : map.entrySet())
-      list.add(pair(entry.getKey(),entry.getValue()));
+      list.add(Pair.of(entry.getKey(),entry.getValue()));
     return list;
   }
   
-  public static <K,V>Pair<K,V> pair(K k, V v) {
-    return new Pair<K,V>(k,v);
-  }
-  
-  public static class Pair<K,V> {
-    private K key;
-    private V val;
-    public Pair(K key, V val) {
-      this.key = key;
-      this.val = val;
-    }
-    public K key() {
-      return key;
-    }
-    public V val() {
-      return val;
-    }
-  }
-  
   public static interface Reducer<K2,V2,K3,V3> {
     void reduce(
       K2 key, 
@@ -261,9 +242,9 @@ public final class MapRed {
         SimpleCollector<K2,V2> context = new SimpleCollector<K2,V2>(nulls);
         List<Pair<K2, Iterable<V2>>> list = new ArrayList<Pair<K2, Iterable<V2>>>();
         for (Pair<K1, V1> entry : input)
-          mapper.map(entry.key(), entry.val(), context);
+          mapper.map(entry.first(), entry.second(), context);
         for (Map.Entry<K2, Iterable<V2>> entry : context.collected())
-          list.add(pair(entry.getKey(), entry.getValue()));
+          list.add(Pair.of(entry.getKey(), entry.getValue()));
         return list;
       }      
     };
@@ -278,9 +259,9 @@ public final class MapRed {
         SimpleCollector<K2,V2> context = new SimpleCollector<K2,V2>(nulls,comparator);
         List<Pair<K2, Iterable<V2>>> list = new ArrayList<Pair<K2, Iterable<V2>>>();
         for (Pair<K1, V1> entry : input)
-          mapper.map(entry.key(), entry.val(), context);
+          mapper.map(entry.first(), entry.second(), context);
         for (Map.Entry<K2, Iterable<V2>> entry : context.collected())
-          list.add(pair(entry.getKey(), entry.getValue()));
+          list.add(Pair.of(entry.getKey(), entry.getValue()));
         return list;
       }      
     };
@@ -306,9 +287,9 @@ public final class MapRed {
         SimpleCollector<K2,V2> context = new SimpleCollector<K2,V2>(nulls, comparator);
         List<Pair<K2, Iterable<V2>>> list = new ArrayList<Pair<K2, Iterable<V2>>>();
         for (Pair<K1, Iterable<V1>> entry : input)
-          reducer.reduce(entry.key(), entry.val().iterator(), context);
+          reducer.reduce(entry.first(), entry.second().iterator(), context);
         for (Map.Entry<K2, Iterable<V2>> entry : context.collected())
-          list.add(pair(entry.getKey(), entry.getValue()));
+          list.add(Pair.of(entry.getKey(), entry.getValue()));
         return list;
       }      
     };
@@ -322,9 +303,9 @@ public final class MapRed {
         SimpleCollector<K2,V2> context = new SimpleCollector<K2,V2>(nulls);
         List<Pair<K2, Iterable<V2>>> list = new ArrayList<Pair<K2, Iterable<V2>>>();
         for (Pair<K1, Iterable<V1>> entry : input)
-          reducer.reduce(entry.key(), entry.val().iterator(), context);
+          reducer.reduce(entry.first(), entry.second().iterator(), context);
         for (Map.Entry<K2, Iterable<V2>> entry : context.collected())
-          list.add(pair(entry.getKey(), entry.getValue()));
+          list.add(Pair.of(entry.getKey(), entry.getValue()));
         return list;
       }      
     };

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/MoreFunctions.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/MoreFunctions.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/MoreFunctions.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/MoreFunctions.java Mon Nov  7 21:31:52 2011
@@ -21,7 +21,60 @@ import com.google.common.collect.Iterabl
 import com.google.common.util.concurrent.ListenableFutureTask;
 
 public class MoreFunctions {
-
+  
+  private static int _hash(Object obj ) {
+    if (obj != null) {
+      Class<?> type = obj.getClass();
+      if (type.isArray()) {
+        if (type.equals(long[].class))
+          return Arrays.hashCode((long[])obj);
+        else if (type.equals(int[].class))
+          return Arrays.hashCode((int[])obj);
+        else if (type.equals(short[].class))
+          return Arrays.hashCode((short[])obj);
+        else if (type.equals(byte[].class))
+          return Arrays.hashCode((byte[])obj);
+        else if (type.equals(boolean[].class))
+          return Arrays.hashCode((boolean[])obj);
+        else if (type.equals(char[].class))
+          return Arrays.hashCode((char[])obj);
+        else if (type.equals(double[].class))
+          return Arrays.hashCode((double[])obj);
+        else if (type.equals(float[].class))
+          return Arrays.hashCode((float[])obj);
+        else return Arrays.hashCode((Object[])obj);
+      } else {
+        if (obj instanceof Iterable) {
+          return genHashCode(obj.hashCode(), Iterables.toArray((Iterable)obj, Object.class));
+        } else {
+          if (obj instanceof Long) {
+            long f = (Long)obj;
+            return (int)(f ^ (f >>> 32));
+          } else if (obj instanceof Double) {
+              long f = Double.doubleToLongBits((Double)obj);
+              return (int)(f ^ (f >>> 32));
+            } else if (obj instanceof Float) {
+              return Float.floatToIntBits((Float)obj);
+            } else if (obj instanceof Boolean) {
+              return (Boolean)obj ? 1231 : 1237;
+            } else if (obj instanceof Integer) {
+              return (Integer)obj;
+            } else return obj.hashCode();
+          }
+        }
+      }
+    return 0;
+  }
+  
+  public static int genHashCode(int sup, Object... fields) {
+    final int prime = 31;
+    int result = sup;
+    for (Object field : fields)
+      result = prime * result + 
+        (field != null ? _hash(field) : 0);
+    return result;
+  }
+  
   public static <T>T createInstance(Class<T> _class, Object... args) {
     return MoreFunctions.<T>createInstance(_class).apply(args);
   }

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/Pair.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/Pair.java?rev=1198949&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/Pair.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/Pair.java Mon Nov  7 21:31:52 2011
@@ -0,0 +1,53 @@
+package org.apache.abdera2.common.misc;
+
+public class Pair<K,V> {
+
+  private final K k;
+  private final V v;
+  
+  public Pair(K k, V v) {
+    this.k = k;
+    this.v = v;
+  }
+  
+  public K first() {
+    return k;
+  }
+  
+  public V second() {
+    return v;
+  }
+
+  public static <K,V>Pair<K,V> of(K k, V v) {
+    return new Pair<K,V>(k,v);
+  }
+  
+  @Override
+  public int hashCode() {
+    return MoreFunctions.genHashCode(1, k,v);
+  }
+
+  @SuppressWarnings({ "unchecked", "rawtypes" })
+  @Override
+  public boolean equals(Object obj) {
+    if (this == obj)
+      return true;
+    if (obj == null)
+      return false;
+    if (getClass() != obj.getClass())
+      return false;
+    Pair<K,V> other = (Pair) obj;
+    if (k == null) {
+      if (other.k != null)
+        return false;
+    } else if (!k.equals(other.k))
+      return false;
+    if (v == null) {
+      if (other.v != null)
+        return false;
+    } else if (!v.equals(other.v))
+      return false;
+    return true;
+  }
+  
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/Pair.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractCollectionAdapter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractCollectionAdapter.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractCollectionAdapter.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractCollectionAdapter.java Mon Nov  7 21:31:52 2011
@@ -25,6 +25,7 @@ import org.apache.abdera2.common.text.Ur
 import org.apache.abdera2.common.date.DateTimes;
 import org.apache.abdera2.common.http.EntityTag;
 import org.apache.abdera2.common.misc.ExceptionHelper;
+import org.apache.abdera2.common.misc.MoreFunctions;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.joda.time.DateTime;
@@ -59,11 +60,7 @@ public abstract class AbstractCollection
         this.method = method.toUpperCase();
       }
       public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ((method == null) ? 0 : method.hashCode());
-        result = prime * result + ((type == null) ? 0 : type.hashCode());
-        return result;
+        return MoreFunctions.genHashCode(1, method,type);
       }
       public boolean equals(Object obj) {
         if (this == obj)

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractProvider.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractProvider.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractProvider.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractProvider.java Mon Nov  7 21:31:52 2011
@@ -18,7 +18,6 @@
 package org.apache.abdera2.common.protocol;
 
 import java.util.Collection;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.LinkedHashSet;
 import java.util.Map;
@@ -33,6 +32,9 @@ import org.apache.commons.logging.LogFac
 
 import com.google.common.base.Function;
 import com.google.common.base.Predicate;
+import static java.util.Collections.unmodifiableMap;
+import static com.google.common.collect.Iterables.*;
+import static org.apache.abdera2.common.protocol.ProviderHelper.*;
 
 /**
  * Base Provider implementation that provides the core implementation details for all Providers. This class provides the
@@ -87,7 +89,7 @@ public abstract class AbstractProvider
     public ResponseContext apply(RequestContext request) {
       Target target = request.getTarget();
       if (Target.NOT_FOUND.apply(target))
-          return ProviderHelper.notfound(request);
+          return notfound(request);
       TargetType type = target.getType();
       log.debug(String.format(
         "Processing [%s] request for Target [%s] of Type [%s]",
@@ -98,13 +100,13 @@ public abstract class AbstractProvider
         getWorkspaceManager()
           .getCollectionAdapter(request);
       if (adapter == null && type != TargetType.TYPE_SERVICE)
-        return ProviderHelper.notfound(request);
+        return notfound(request);
       RequestProcessor processor = 
-        this.requestProcessors
+        requestProcessors
           .get(type)
           .apply(adapter);
       if (processor == null)
-          return ProviderHelper.notfound(request);
+        return notfound(request);
       Chain<RequestContext,ResponseContext> chain = 
         Chain.<RequestContext,ResponseContext>make()
         .to(processor)
@@ -118,30 +120,29 @@ public abstract class AbstractProvider
       }
       return response != null ? 
         response : 
-        ProviderHelper.badrequest(request);
+        badrequest(request);
     }
 
     /**
      * Subclass to customize the kind of error response to return
      */
     protected ResponseContext createErrorResponse(RequestContext request, Throwable e) {
-        return ProviderHelper.servererror(request, e);
+      return servererror(request, e);
     }
 
     protected abstract WorkspaceManager getWorkspaceManager();
 
     public void setFilters(Collection<Task<RequestContext,ResponseContext>> filters) {
-        this.filters = new LinkedHashSet<Task<RequestContext,ResponseContext>>(filters);
+      this.filters = new LinkedHashSet<Task<RequestContext,ResponseContext>>(filters);
     }
 
     public Iterable<Task<RequestContext,ResponseContext>> getFilters(RequestContext request) {
-        return filters;
+      return unmodifiableIterable(filters);
     }
 
     public void addFilter(Task<RequestContext,ResponseContext>... filters) {
-        for (Task<RequestContext,ResponseContext> filter : filters) {
-            this.filters.add(filter);
-        }
+      for (Task<RequestContext,ResponseContext> filter : filters)
+        this.filters.add(filter);
     }
 
     public void setRequestProcessors(
@@ -151,8 +152,8 @@ public abstract class AbstractProvider
           CollectionAdapter,
           ? extends RequestProcessor>> 
             requestProcessors) {
-        this.requestProcessors.clear();
-        this.requestProcessors.putAll(requestProcessors);
+        requestProcessors.clear();
+        requestProcessors.putAll(requestProcessors);
     }
 
     public void addRequestProcessor(
@@ -160,7 +161,7 @@ public abstract class AbstractProvider
       Class<? extends RequestProcessor> _class, 
       Predicate<RequestContext> predicate,
       WorkspaceManager workspaceManager) {
-        this.requestProcessors.put(
+        requestProcessors.put(
           type, 
           RequestProcessor.forClass(
             _class,
@@ -172,7 +173,7 @@ public abstract class AbstractProvider
         TargetType type, 
         Class<? extends RequestProcessor> _class,
         WorkspaceManager workspaceManager) {
-          this.requestProcessors.put(
+          requestProcessors.put(
             type, 
             RequestProcessor.forClass(
               _class,
@@ -186,11 +187,11 @@ public abstract class AbstractProvider
           CollectionAdapter,
           ? extends RequestProcessor>> 
             requestProcessors) {
-        this.requestProcessors.putAll(requestProcessors);
+        requestProcessors.putAll(requestProcessors);
     }
 
     public Map<TargetType, Function<CollectionAdapter,? extends RequestProcessor>> getRequestProcessors() {
-        return Collections.unmodifiableMap(this.requestProcessors);
+        return unmodifiableMap(this.requestProcessors);
     }
     
 }

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractResponseContext.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractResponseContext.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractResponseContext.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractResponseContext.java Mon Nov  7 21:31:52 2011
@@ -213,7 +213,7 @@ public abstract class AbstractResponseCo
     public <T extends ResponseContext>T setContentType(String type, String charset) {
         if (type == null)
             return (T)removeHeader("Content-Type");
-        MimeType mimeType = MimeTypeHelper.create(type);
+        MimeType mimeType = MimeTypeHelper.unmodifiableMimeType(type);
         if (charset != null)
             mimeType.setParameter("charset", charset);
         return (T)setHeader("Content-Type", mimeType.toString());

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/BasicCollectionInfo.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/BasicCollectionInfo.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/BasicCollectionInfo.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/BasicCollectionInfo.java Mon Nov  7 21:31:52 2011
@@ -21,6 +21,8 @@ import java.io.Serializable;
 import java.util.LinkedHashSet;
 import java.util.Set;
 
+import org.apache.abdera2.common.misc.MoreFunctions;
+
 import com.google.common.base.Supplier;
 
 public class BasicCollectionInfo 
@@ -79,12 +81,7 @@ public class BasicCollectionInfo 
 
     @Override
     public int hashCode() {
-      final int prime = 31;
-      int result = 1;
-      result = prime * result + ((accepts == null) ? 0 : accepts.hashCode());
-      result = prime * result + ((href == null) ? 0 : href.hashCode());
-      result = prime * result + ((title == null) ? 0 : title.hashCode());
-      return result;
+      return MoreFunctions.genHashCode(1, accepts,href,title);
     }
 
     @Override

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/BasicWorkspaceInfo.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/BasicWorkspaceInfo.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/BasicWorkspaceInfo.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/BasicWorkspaceInfo.java Mon Nov  7 21:31:52 2011
@@ -21,6 +21,8 @@ import java.io.Serializable;
 import java.util.LinkedHashSet;
 import java.util.Set;
 
+import org.apache.abdera2.common.misc.MoreFunctions;
+
 import com.google.common.base.Supplier;
 import com.google.common.collect.Iterables;
 
@@ -79,11 +81,7 @@ public class BasicWorkspaceInfo
     }
 
     public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ((collections == null) ? 0 : collections.hashCode());
-        result = prime * result + ((title == null) ? 0 : title.hashCode());
-        return result;
+      return MoreFunctions.genHashCode(1, collections,title);
     }
 
     public boolean equals(Object obj) {

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/ProtocolException.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/ProtocolException.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/ProtocolException.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/ProtocolException.java Mon Nov  7 21:31:52 2011
@@ -17,6 +17,8 @@
  */
 package org.apache.abdera2.common.protocol;
 
+import org.apache.abdera2.common.misc.MoreFunctions;
+
 public class ProtocolException 
   extends RuntimeException {
 
@@ -30,10 +32,7 @@ public class ProtocolException 
 
     @Override
     public int hashCode() {
-      final int prime = 31;
-      int result = 1;
-      result = prime * result + code;
-      return result;
+      return MoreFunctions.genHashCode(1,code);
     }
 
     @Override

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/RegexTargetResolver.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/RegexTargetResolver.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/RegexTargetResolver.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/RegexTargetResolver.java Mon Nov  7 21:31:52 2011
@@ -24,6 +24,9 @@ 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 com.google.common.base.Function;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.LinkedHashMultimap;
@@ -112,11 +115,7 @@ public class RegexTargetResolver<R exten
     }
 
     public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ((fields == null) ? 0 : fields.hashCode());
-        result = prime * result + ((patterns == null) ? 0 : patterns.hashCode());
-        return result;
+      return MoreFunctions.genHashCode(1, fields,patterns);
     }
 
     @SuppressWarnings("unchecked")
@@ -185,15 +184,9 @@ public class RegexTargetResolver<R exten
 
         @Override
         public int hashCode() {
-            final int PRIME = 31;
-            int result = 1;
-            String m = matcher.group(0);
-            String p = matcher.pattern().pattern();
-            result = PRIME * result + super.hashCode();
-            result = PRIME * result + ((m == null) ? 0 : m.hashCode());
-            result = PRIME * result + ((p == null) ? 0 : p.hashCode());
-            result = PRIME * result + ((type == null) ? 0 : type.hashCode());
-            return result;
+          String m = matcher.group(0);
+          String p = matcher.pattern().pattern();
+          return MoreFunctions.genHashCode(1, m,p,type);
         }
 
         @Override

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/SimpleSubjectResolver.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/SimpleSubjectResolver.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/SimpleSubjectResolver.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/SimpleSubjectResolver.java Mon Nov  7 21:31:52 2011
@@ -22,6 +22,8 @@ import java.security.Principal;
 
 import javax.security.auth.Subject;
 
+import org.apache.abdera2.common.misc.MoreFunctions;
+
 import com.google.common.base.Function;
 
 /**
@@ -68,10 +70,7 @@ public class SimpleSubjectResolver 
 
         @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
@@ -112,10 +111,7 @@ public class SimpleSubjectResolver 
         }
 
         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);
         }
     }
 }

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/SimpleTarget.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/SimpleTarget.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/SimpleTarget.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/SimpleTarget.java Mon Nov  7 21:31:52 2011
@@ -19,6 +19,8 @@ package org.apache.abdera2.common.protoc
 
 import java.util.Iterator;
 
+import org.apache.abdera2.common.misc.MoreFunctions;
+
 
 
 @SuppressWarnings("unchecked")
@@ -67,11 +69,7 @@ public class SimpleTarget
 
     @Override
     public int hashCode() {
-        final int PRIME = 31;
-        int result = 1;
-        result = PRIME * result + ((context == null) ? 0 : context.hashCode());
-        result = PRIME * result + ((type == null) ? 0 : type.hashCode());
-        return result;
+      return MoreFunctions.genHashCode(1, context, type);
     }
 
     @Override

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/TargetFunctionResolver.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/TargetFunctionResolver.java?rev=1198949&r1=1198948&r2=1198949&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/TargetFunctionResolver.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/TargetFunctionResolver.java Mon Nov  7 21:31:52 2011
@@ -11,6 +11,8 @@ import java.util.regex.Pattern;
 
 import org.apache.abdera2.common.iri.IRI;
 import org.apache.abdera2.common.misc.ExceptionHelper;
+import org.apache.abdera2.common.misc.MoreFunctions;
+
 import com.google.common.base.Function;
 import com.google.common.base.Predicate;
 import com.google.common.base.Supplier;
@@ -61,10 +63,7 @@ public class TargetFunctionResolver<R ex
 
   @Override
   public int hashCode() {
-    final int prime = 31;
-    int result = 1;
-    result = prime * result + ((functions == null) ? 0 : functions.hashCode());
-    return result;
+    return MoreFunctions.genHashCode(1, functions);
   }
 
   @Override



Mime
View raw message