abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r1186541 [2/8] - in /abdera/abdera2: ./ .settings/ activities/ activities/.settings/ activities/src/main/java/org/apache/abdera2/activities/client/ activities/src/main/java/org/apache/abdera2/activities/extra/ activities/src/main/java/org/a...
Date Wed, 19 Oct 2011 22:33:52 GMT
Modified: abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/AbderaSession.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/AbderaSession.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/AbderaSession.java (original)
+++ abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/AbderaSession.java Wed Oct 19 22:33:04 2011
@@ -168,7 +168,7 @@ public class AbderaSession extends Sessi
                 if (d.getEntityTag() != null)
                     options.setIfMatch(d.getEntityTag());
                 else if (d.getLastModified() != null)
-                    options.setIfUnmodifiedSince(d.getLastModified());
+                    options.setIfUnmodifiedSince(d.getLastModified().toDate());
             }
         }
         return (T)wrap(execute("PUT", uri, new AbderaEntity(base), options));

Modified: abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/ClientResponseImpl.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/ClientResponseImpl.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/ClientResponseImpl.java (original)
+++ abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/ClientResponseImpl.java Wed Oct 19 22:33:04 2011
@@ -195,7 +195,7 @@ class ClientResponseImpl 
 
   public CacheControl getCacheControl() {
     String cc = getHeader("Cache-Control");
-    return cc != null ? new CacheControl(cc) : null;
+    return cc != null ? CacheControl.parse(cc) : null;
   }
 
   @SuppressWarnings("unchecked")

Modified: abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/RequestHelper.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/RequestHelper.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/RequestHelper.java (original)
+++ abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/RequestHelper.java Wed Oct 19 22:33:04 2011
@@ -47,8 +47,10 @@ import org.apache.http.client.params.Cli
 import org.apache.http.params.CoreProtocolPNames;
 import org.apache.http.params.HttpParams;
 
-public class RequestHelper {
+public final class RequestHelper {
 
+    private RequestHelper() {}
+  
     public static HttpUriRequest createRequest(
       String method, 
       String uri, 

Modified: abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/RequestOptions.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/RequestOptions.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/RequestOptions.java (original)
+++ abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/RequestOptions.java Wed Oct 19 22:33:04 2011
@@ -476,7 +476,7 @@ public class RequestOptions extends Abst
      * Sets the value of the HTTP Cache-Control header
      */
     public RequestOptions setCacheControl(String cc) {
-        this.cacheControl = new CacheControl(cc);
+        this.cacheControl = CacheControl.parse(cc);
         return this;
     }
     

Modified: abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/Session.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/Session.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/Session.java (original)
+++ abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/Session.java Wed Oct 19 22:33:04 2011
@@ -72,7 +72,7 @@ public class Session {
     protected <T extends ClientResponse>T wrap(ClientResponse resp) {
       return (T)resp;
     }
-        
+    
     /**
      * Sends an HTTP GET request to the specified URI.
      * 

Added: abdera/abdera2/common/.classpath
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/.classpath?rev=1186541&view=auto
==============================================================================
--- abdera/abdera2/common/.classpath (added)
+++ abdera/abdera2/common/.classpath Wed Oct 19 22:33:04 2011
@@ -0,0 +1,12 @@
+<classpath>
+  <classpathentry kind="src" path="src/main/java" including="**/*.java"/>
+  <classpathentry kind="src" path="src/main/resources" excluding="**/*.java"/>
+  <classpathentry kind="src" path="target/maven-shared-archive-resources" excluding="**/*.java"/>
+  <classpathentry kind="output" path="target/classes"/>
+  <classpathentry kind="var" path="M2_REPO/commons-codec/commons-codec/1.5/commons-codec-1.5.jar"/>
+  <classpathentry kind="var" path="M2_REPO/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/geronimo/specs/geronimo-activation_1.1_spec/1.1/geronimo-activation_1.1_spec-1.1.jar"/>
+  <classpathentry kind="var" path="M2_REPO/com/ibm/icu/icu4j/4.8.1.1/icu4j-4.8.1.1.jar"/>
+  <classpathentry kind="var" path="M2_REPO/javax/javaee-web-api/6.0/javaee-web-api-6.0.jar"/>
+  <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+</classpath>
\ No newline at end of file

Propchange: abdera/abdera2/common/.classpath
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/.project
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/.project?rev=1186541&view=auto
==============================================================================
--- abdera/abdera2/common/.project (added)
+++ abdera/abdera2/common/.project Wed Oct 19 22:33:04 2011
@@ -0,0 +1,13 @@
+<projectDescription>
+  <name>abdera2-common</name>
+  <comment>Abdera2 Common Code Library. NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment>
+  <projects/>
+  <buildSpec>
+    <buildCommand>
+      <name>org.eclipse.jdt.core.javabuilder</name>
+    </buildCommand>
+  </buildSpec>
+  <natures>
+    <nature>org.eclipse.jdt.core.javanature</nature>
+  </natures>
+</projectDescription>
\ No newline at end of file

Propchange: abdera/abdera2/common/.project
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/.settings/org.eclipse.jdt.core.prefs
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/.settings/org.eclipse.jdt.core.prefs?rev=1186541&view=auto
==============================================================================
--- abdera/abdera2/common/.settings/org.eclipse.jdt.core.prefs (added)
+++ abdera/abdera2/common/.settings/org.eclipse.jdt.core.prefs Wed Oct 19 22:33:04 2011
@@ -0,0 +1,5 @@
+#Thu Sep 29 16:38:16 PDT 2011
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.source=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6

Propchange: abdera/abdera2/common/.settings/org.eclipse.jdt.core.prefs
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: abdera/abdera2/common/pom.xml
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/pom.xml?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/pom.xml (original)
+++ abdera/abdera2/common/pom.xml Wed Oct 19 22:33:04 2011
@@ -77,5 +77,10 @@
       <artifactId>icu4j</artifactId>
     </dependency>
 
+    <dependency>
+        <groupId>com.google.guava</groupId>
+        <artifactId>guava</artifactId>
+    </dependency>
+
   </dependencies>
 </project>

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/Discover.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/Discover.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/Discover.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/Discover.java Wed Oct 19 22:33:04 2011
@@ -29,10 +29,11 @@ import java.util.LinkedHashSet;
 import java.util.Set;
 
 import org.apache.abdera2.common.anno.AnnoUtil;
-import org.apache.abdera2.common.misc.MultiIterator;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import com.google.common.collect.Iterators;
+
 @SuppressWarnings("unchecked")
 public final class Discover {
 
@@ -174,7 +175,7 @@ public final class Discover {
                         new DefaultLoaderIterator<T>(loader, e.nextElement().openStream(), classesonly, args);
                     list.add(i);
                 }
-                return new MultiIterator<T>(list);
+                return Iterators.concat(list.iterator());
             } catch (Throwable t) {
                 throw new RuntimeException(t);
             }

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=1186541&r1=1186540&r2=1186541&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 Wed Oct 19 22:33:04 2011
@@ -24,8 +24,10 @@ import java.util.Set;
 import javax.xml.namespace.QName;
 
 
-public class AnnoUtil {
+public final class AnnoUtil {
 
+  private AnnoUtil() {}
+  
   /**
    * Retrieves the value of the Name attribute from the specified 
    * item. If the item is an instance object, the name is pulled from it's

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/date/DateTimes.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/date/DateTimes.java?rev=1186541&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/date/DateTimes.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/date/DateTimes.java Wed Oct 19 22:33:04 2011
@@ -0,0 +1,463 @@
+package org.apache.abdera2.common.date;
+
+import java.util.Calendar;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.TimeZone;
+
+import org.apache.abdera2.common.selector.Selector;
+import org.joda.time.format.DateTimeFormatter;
+import org.joda.time.format.ISODateTimeFormat;
+import org.joda.time.DateTime;
+import org.joda.time.DateTimeZone;
+import org.joda.time.Duration;
+import org.joda.time.Interval;
+
+import com.google.common.base.Equivalence;
+import com.google.common.base.Predicate;
+import com.google.common.base.Supplier;
+import com.google.common.collect.Range;
+import com.google.common.collect.Ranges;
+
+public final class DateTimes {
+
+  private DateTimes() {}
+  
+  private static final DateTimeFormatter DTF =
+    ISODateTimeFormat.dateTime();
+  
+  public static String formatNow() {
+    return DateTime.now().toString(DTF);
+  }
+  
+  public static String format(String dateTime) {
+    return DTF.print(new DateTime(dateTime));
+  }
+  
+  public static String format(DateTime dateTime) {
+    return DTF.print(dateTime);
+  }
+  
+  public static String format(Date date) {
+    return DTF.print(new DateTime(date));
+  }
+  
+  public static String format(Calendar cal) {
+    return DTF.print(new DateTime(cal));
+  }
+  
+  public static String format(long ms) {
+    return DTF.print(ms);
+  }
+  
+  public static Date parse(String t) {
+    return DateTime.parse(t).toDate();
+  }
+  
+  public static DateTime toUTC(DateTime dt) {
+    return dt.toDateTime(DateTimeZone.UTC);
+  }
+  
+  public static DateTime toTimeZone(DateTime dt, TimeZone tz) {
+    return dt.toDateTime(DateTimeZone.forTimeZone(tz));
+  }
+  
+  public static DateTime toTimeZone(DateTime dt, String id) {
+    return dt.toDateTime(DateTimeZone.forID(id));
+  }
+  
+  public DateTimeBuilder makeDateTime() {
+    return new DateTimeBuilder();
+  }
+  
+  public static class DateTimeBuilder implements Supplier<DateTime> {
+    private int year, month, day, hour, minute, second, millis;
+    private DateTimeZone dtz;
+    public DateTimeBuilder() {}
+    public DateTimeBuilder year(int year) {
+      this.year = year;
+      return this;
+    }
+    public DateTimeBuilder month(int month) {
+      this.month = month;
+      return this;
+    }
+    public DateTimeBuilder day(int day) {
+      this.day = day;
+      return this;
+    }
+    public DateTimeBuilder hour(int hour) {
+      this.hour = hour;
+      return this;
+    }
+    public DateTimeBuilder minute(int minute) {
+      this.minute = minute;
+      return this;
+    }
+    public DateTimeBuilder second(int second) {
+      this.second = second;
+      return this;
+    }
+    public DateTimeBuilder millisecond(int ms) {
+      this.millis = ms;
+      return this;
+    }
+    public DateTimeBuilder timezone(TimeZone tz) {
+      this.dtz = DateTimeZone.forTimeZone(tz);
+      return this;
+    }
+    public DateTimeBuilder timezone(String id) {
+      this.dtz = DateTimeZone.forID(id);
+      return this;
+    }
+    public DateTimeBuilder timezone(int offsetHours) {
+      this.dtz = DateTimeZone.forOffsetHours(offsetHours);
+      return this;
+    }
+    public DateTimeBuilder timezone(int offsetHours, int offsetMinutes) {
+      this.dtz = DateTimeZone.forOffsetHoursMinutes(offsetHours, offsetMinutes);
+      return this;
+    }
+    public DateTime get() {
+      return new DateTime(year,month,day,hour,minute,second,millis,dtz);
+    }
+  }
+  
+  public static abstract class DateTimeComparator<X> implements Comparator<X> {
+    public int innerCompare(DateTime d1, DateTime d2) {
+      if (d1 != null && d2 == null) return 1;
+      if (d1 == null && d2 != null) return -1;
+      if (d1 == null && d2 == null) return 0;
+      return d1.compareTo(d2);
+    }
+  }
+
+  public static Selector<DateTime> selectorForRange(Range<DateTime> range) {
+    return Selector.Utils.forPredicate(range);
+  }
+  
+  public static Range<DateTime> all() {
+    return Ranges.<DateTime>all();
+  }
+  
+  public static Range<DateTime> atOrAfterNow() {
+    return atOrAfter(DateTime.now());
+  }
+  
+  public static Range<DateTime> atOrAfter(DateTime dateTime) {
+    return Ranges.<DateTime>atLeast(dateTime);
+  }
+  
+  public static Range<DateTime> atOrBefore(DateTime dateTime) {
+    return Ranges.<DateTime>atMost(dateTime);
+  }
+  
+  public static Range<DateTime> atOrBetween(DateTime low, DateTime high) {
+    return Ranges.<DateTime>closed(low,high);
+  }
+  
+  public static Range<DateTime> atOrBetween(DateTime low, Duration duration) {
+    return atOrBetween(low,low.plus(duration));
+  }
+  
+  public static Range<DateTime> atOrBetween(Duration duration, DateTime high) {
+    return atOrBetween(high.minus(duration),high);
+  }
+  
+  public static Range<DateTime> atOrBetween(Interval interval) {
+    return atOrBetween(interval.getStart(),interval.getEnd());
+  }
+  
+  public static Range<DateTime> atBetweenOrBefore(DateTime low, DateTime high) {
+    return Ranges.<DateTime>closedOpen(low,high);
+  }
+  
+  public static Range<DateTime> atBetweenOrBefore(DateTime low, Duration duration) {
+    return atBetweenOrBefore(low,low.plus(duration));
+  }
+  
+  public static Range<DateTime> atBetweenOrBefore(Duration duration, DateTime high) {
+    return atBetweenOrBefore(high.minus(duration),high);
+  }
+  
+  public static Range<DateTime> atBetweenOrBefore(Interval interval) {
+    return atBetweenOrBefore(interval.getStart(),interval.getEnd());
+  }
+  
+  public static Range<DateTime> afterNow() {
+    return after(DateTime.now());
+  }
+  
+  public static Range<DateTime> after(DateTime dateTime) {
+    return Ranges.<DateTime>greaterThan(dateTime);
+  }
+  
+  public static Range<DateTime> beforeNow() {
+    return before(DateTime.now());
+  }
+  
+  public static Range<DateTime> before(DateTime dateTime) {
+    return Ranges.<DateTime>lessThan(dateTime);
+  }
+  
+  public static Range<DateTime> between(DateTime low, DateTime high) {
+    return Ranges.<DateTime>open(low,high);
+  }
+  
+  public static Range<DateTime> between(DateTime low, Duration duration) {
+    return between(low,low.plus(duration));
+  }
+  
+  public static Range<DateTime> between(Duration duration, DateTime high) {
+    return between(high.minus(duration), high);
+  }
+  
+  public static Range<DateTime> between(Interval interval) {
+    return between(interval.getStart(),interval.getEnd());
+  }
+  
+  public static Range<DateTime> afterBetweenOrAt(DateTime low, DateTime high) {
+    return Ranges.<DateTime>openClosed(low,high);
+  }
+  
+  public static Range<DateTime> afterBetweenOrAt(DateTime low, Duration duration) {
+    return afterBetweenOrAt(low,low.plus(duration));
+  }
+  
+  public static Range<DateTime> afterBetweenOrAt(Duration duration, DateTime high) {
+    return afterBetweenOrAt(high.minus(duration), high);
+  }
+  
+  public static Range<DateTime> exactlyNow() {
+    return exactly(DateTime.now());
+  }
+  
+  public static Range<DateTime> exactly(DateTime dateTime) {
+    return Ranges.<DateTime>singleton(dateTime);
+  }
+  
+  public static Range<DateTime> exactlyBefore(DateTime date, Duration duration) {
+    return exactly(date.minus(duration));
+  }
+  
+  public static Range<DateTime> exactlyAfter(DateTime date, Duration duration) {
+    return exactly(date.plus(duration));
+  }
+  
+  public static Range<DateTime> exactlyBeforeNow(Duration duration) {
+    return exactlyBefore(DateTime.now(),duration);
+  }
+  
+  public static Range<DateTime> exactlyAfterNow(Duration duration) {
+    return exactlyAfter(DateTime.now(),duration);
+  }
+  
+  public static final boolean equivalent(DateTime d1, DateTime d2) {
+    return Equivalence.equivalent(d1, d2);
+  }
+  
+  public static final boolean equivalent(DateTime d1, Date date) {
+    return equivalent(d1, new DateTime(date));
+  }
+  
+  public static final boolean equivalent(DateTime d1, Calendar cal) {
+    return equivalent(d1, new DateTime(cal));
+  }
+  
+  public static final boolean equivalent(DateTime d1, long time) {
+    return equivalent(d1, new DateTime(time));
+  }
+  
+  public static final boolean equivalent(DateTime d1, String obj) {
+    return equivalent(d1, new DateTime(obj));
+  }
+  
+  public static final boolean equivalent(Date d1, Date date) {
+    return equivalent(new DateTime(d1), new DateTime(date));
+  }
+  
+  public static final boolean equivalent(Date d1, Calendar cal) {
+    return equivalent(new DateTime(d1), new DateTime(cal));
+  }
+  
+  public static final boolean equivalent(Date d1, long time) {
+    return equivalent(new DateTime(d1), new DateTime(time));
+  }
+  
+  public static final boolean equivalent(Date d1, String obj) {
+    return equivalent(new DateTime(d1), new DateTime(obj));
+  }
+  
+  public static final boolean equivalent(Calendar c1, Calendar c2) {
+    return equivalent(new DateTime(c1),new DateTime(c2));
+  }
+  
+  public static final boolean equivalent(Calendar c1, long time) {
+    return equivalent(new DateTime(c1), new DateTime(time));
+  }
+  
+  public static final boolean equivalent(Calendar c1, String c2) {
+    return equivalent(new DateTime(c1), new DateTime(c2));
+  }
+  
+  public static final boolean equivalent(long c1, long c2) {
+    return equivalent(new DateTime(c1), new DateTime(c2));
+  }
+  
+  public static final boolean equivalent(long c1, String c2) {
+    return equivalent(new DateTime(c1), new DateTime(c2));
+  }
+  
+  public static final boolean equivalent(String c1, String c2) {
+    return equivalent(new DateTime(c1), new DateTime(c2));
+  }
+  
+  public static Predicate<DateTime> equivalentTo(Date date) {
+    return equivalentTo(new DateTime(date));
+  }
+  
+  public static Predicate<DateTime> equivalentTo(Calendar cal) {
+    return equivalentTo(new DateTime(cal));
+  }
+  
+  public static Predicate<DateTime> equivalentTo(long time) {
+    return equivalentTo(new DateTime(time));
+  }
+  
+  public static Predicate<DateTime> equivalentTo(String dt) {
+    return equivalentTo(new DateTime(dt));
+  }
+  
+  public static Predicate<DateTime> equivalentTo(DateTime dateTime) {
+    return Equivalence.equivalentTo(dateTime);
+  }
+  
+  public static final Equivalence<DateTime> Equivalence = equivalence();
+  
+  private static Equivalence<DateTime> equivalence() {
+    return new Equivalence<DateTime>() {
+      protected boolean doEquivalent(DateTime a, DateTime b) {
+        return a.compareTo(b) == 0;
+      }
+      protected int doHash(DateTime t) {
+        return toUTC(t).hashCode();
+      }
+    };
+  }
+  
+  public static Selector<DateTime> selectorForAll() {
+    return selectorForRange(all());
+  }
+  
+  public static Selector<DateTime> selectorForAtOrAfterNow() {
+    return selectorForRange(atOrAfterNow());
+  }
+  
+  public static Selector<DateTime> selectorForAtOrAfter(DateTime dateTime) {
+    return selectorForRange(atOrAfter(dateTime));
+  }
+  
+  public static Selector<DateTime> selectorForAtOrBefore(DateTime dateTime) {
+    return selectorForRange(atOrBefore(dateTime));
+  }
+  
+  public static Selector<DateTime> selectorForAtOrBetween(DateTime low, DateTime high) {
+    return selectorForRange(atOrBetween(low,high));
+  }
+  
+  public static Selector<DateTime> selectorForAtOrBetween(DateTime low, Duration duration) {
+    return selectorForRange(atOrBetween(low,low.plus(duration)));
+  }
+  
+  public static Selector<DateTime> selectorForAtOrBetween(Duration duration, DateTime high) {
+    return selectorForRange(atOrBetween(high.minus(duration),high));
+  }
+  
+  public static Selector<DateTime> selectorForAtOrBetween(Interval interval) {
+    return selectorForRange(atOrBetween(interval.getStart(),interval.getEnd()));
+  }
+  
+  public static Selector<DateTime> selectorForAtBetweenOrBefore(DateTime low, DateTime high) {
+    return selectorForRange(atBetweenOrBefore(low,high));
+  }
+  
+  public static Selector<DateTime> selectorForAtBetweenOrBefore(DateTime low, Duration duration) {
+    return selectorForRange(atBetweenOrBefore(low,duration));
+  }
+  
+  public static Selector<DateTime> selectorForAtBetweenOrBefore(Duration duration, DateTime high) {
+    return selectorForRange(atBetweenOrBefore(duration,high));
+  }
+  
+  public static Selector<DateTime> selectorForAtBetweenOrBefore(Interval interval) {
+    return selectorForRange(atBetweenOrBefore(interval));
+  }
+  
+  public static Selector<DateTime> selectorForAfterNow() {
+    return selectorForRange(afterNow());
+  }
+  
+  public static Selector<DateTime> selectorForAfter(DateTime dateTime) {
+    return selectorForRange(after(dateTime));
+  }
+  
+  public static Selector<DateTime> selectorForBeforeNow() {
+    return selectorForRange(beforeNow());
+  }
+  
+  public static Selector<DateTime> selectorForBefore(DateTime dateTime) {
+    return selectorForRange(before(dateTime));
+  }
+  
+  public static Selector<DateTime> selectorForBetween(DateTime low, DateTime high) {
+    return selectorForRange(between(low,high));
+  }
+  
+  public static Selector<DateTime> selectorForBetween(DateTime low, Duration duration) {
+    return selectorForRange(between(low,duration));
+  }
+  
+  public static Selector<DateTime> selectorForBetween(Duration duration, DateTime high) {
+    return selectorForRange(between(duration,high));
+  }
+  
+  public static Selector<DateTime> selectorForBetween(Interval interval) {
+    return selectorForRange(between(interval));
+  }
+  
+  public static Selector<DateTime> selectorForAfterBetweenOrAt(DateTime low, DateTime high) {
+    return selectorForRange(afterBetweenOrAt(low,high));
+  }
+  
+  public static Selector<DateTime> selectorForAfterBetweenOrAt(DateTime low, Duration duration) {
+    return selectorForRange(afterBetweenOrAt(low,duration));
+  }
+  
+  public static Selector<DateTime> selectorForAfterBetweenOrAt(Duration duration, DateTime high) {
+    return selectorForRange(afterBetweenOrAt(duration,high));
+  }
+  
+  public static Selector<DateTime> selectorForExactlyNow() {
+    return selectorForRange(exactlyNow());
+  }
+  
+  public static Selector<DateTime> selectorForExactly(DateTime dateTime) {
+    return selectorForRange(exactly(dateTime));
+  }
+  
+  public static Selector<DateTime> selectorForExactlyBefore(DateTime date, Duration duration) {
+    return selectorForRange(exactlyBefore(date,duration));
+  }
+  
+  public static Selector<DateTime> selectorForExactlyAfter(DateTime date, Duration duration) {
+    return selectorForRange(exactlyAfter(date,duration));
+  }
+  
+  public static Selector<DateTime> selectorForExactlyBeforeNow(Duration duration) {
+    return selectorForRange(exactlyBeforeNow(duration));
+  }
+  
+  public static Selector<DateTime> selectorForExactlyAfterNow(Duration duration) {
+    return selectorForRange(exactlyAfterNow(duration));
+  }
+}

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

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Box.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Box.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Box.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Box.java Wed Oct 19 22:33:04 2011
@@ -17,71 +17,90 @@
  */
 package org.apache.abdera2.common.geo;
 
+import java.util.Iterator;
+
+import static com.google.common.base.Preconditions.*;
 public class Box extends Multiple {
 
     private static final String TWO_COORDINATES = "A box must have two coordinates";
     private static final long serialVersionUID = 3994252648307511152L;
 
-    public Box() {
-        super();
-    }
-
-    public Box(Multiple multiple) {
-        super(multiple);
-        if (this.coordinates.size() != 2)
-            throw new IllegalArgumentException(TWO_COORDINATES);
-    }
-
-    public Box(Point lowerCorner, Point upperCorner) {
-        super(lowerCorner, upperCorner);
-    }
-
-    public Box(Coordinate lowerCorner, Coordinate upperCorner) {
-        super(lowerCorner,upperCorner);
-    }
-
-    public Box(Coordinates coordinates) {
-        super(coordinates);
-        if (this.coordinates.size() != 2)
-            throw new IllegalArgumentException(TWO_COORDINATES);
-    }
-
-    public Box(String value) {
-        super(value);
-        if (this.coordinates.size() != 2)
-            throw new IllegalArgumentException(TWO_COORDINATES);
-    }
-
-    public Box(Multiple... multiples) {
-        super(multiples);
-        if (this.coordinates.size() != 2)
-            throw new IllegalArgumentException(TWO_COORDINATES);
-    }
-
-    public Box(Point... points) {
-        super(points);
-        if (this.coordinates.size() != 2)
-            throw new IllegalArgumentException(TWO_COORDINATES);
-    }
-
-    public Box(double... values) {
-        super(values);
-        if (this.coordinates.size() != 2)
-            throw new IllegalArgumentException(TWO_COORDINATES);
-    }
-
-    @Override
-    public void setCoordinates(Coordinates coordinates) {
-        super.setCoordinates(coordinates);
-        if (this.coordinates.size() > 2)
-            throw new IllegalArgumentException(TWO_COORDINATES);
+    public static Box at(Iterable<Coordinate> coordinates) {
+      Iterator<Coordinate> i = coordinates.iterator();
+      return make().add(i.next()).add(i.next()).get();
+    }
+    
+    public static Box at(Coordinate lowerCorner, Coordinate upperCorner) {
+      return make().add(lowerCorner).add(upperCorner).get();
+    }
+    
+    public static Box at(String lowerCorner, String upperCorner) {
+      return make().add(lowerCorner).add(upperCorner).get();
+    }
+    
+    public static Box at(IsoPosition lowerCorner, IsoPosition upperCorner) {
+      return make().add(lowerCorner).add(upperCorner).get();
+    }
+    
+    public static Box at(double lowerCornerLat, double lowerCornerLong, double upperCornerLat, double upperCornerLong) {
+      return make().add(lowerCornerLat,lowerCornerLong).add(upperCornerLat,upperCornerLong).get();
+    }
+    
+    
+    public static Builder make(Iterable<Coordinate> coordinates) {
+      Iterator<Coordinate> i = coordinates.iterator();
+      return make().add(i.next()).add(i.next());
+    }
+    
+    public static Builder make(Coordinate lowerCorner, Coordinate upperCorner) {
+      return make().add(lowerCorner).add(upperCorner);
+    }
+    
+    public static Builder make(String lowerCorner, String upperCorner) {
+      return make().add(lowerCorner).add(upperCorner);
+    }
+    
+    public static Builder make(IsoPosition lowerCorner, IsoPosition upperCorner) {
+      return make().add(lowerCorner).add(upperCorner);
+    }
+    
+    public static Builder make(double lowerCornerLat, double lowerCornerLong, double upperCornerLat, double upperCornerLong) {
+      return make().add(lowerCornerLat,lowerCornerLong).add(upperCornerLat,upperCornerLong);
+    }
+    
+    
+    public static Builder make() {
+      return new Builder();
+    }
+    
+    public static class Builder 
+      extends Multiple.Builder<Box> {
+      
+      public Builder() {
+        noDuplicates()
+        .maximumCoordinates(2);
+      }
+      
+      public Box get() {
+        return new Box(this);
+      }
+    }
+ 
+    private final transient Coordinate lower, upper;
+    
+    public Box(Builder builder) {
+      super(builder);
+      checkArgument(size() == 2, TWO_COORDINATES);
+      Iterator<Coordinate> i = iterator();
+      this.lower = i.next();
+      this.upper = i.next();
     }
 
     public Coordinate getUpperCorner() {
-        return coordinates.size() > 1 ? coordinates.get(1) : null;
+        return upper;
     }
 
     public Coordinate getLowerCorner() {
-        return coordinates.size() > 0 ? coordinates.get(0) : null;
+        return lower;
     }
 }

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=1186541&r1=1186540&r2=1186541&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 Wed Oct 19 22:33:04 2011
@@ -18,56 +18,61 @@
 package org.apache.abdera2.common.geo;
 
 import java.io.Serializable;
+import static com.google.common.base.Preconditions.*;
 
-public class Coordinate implements Serializable, Cloneable, Comparable<Coordinate> {
+public class Coordinate 
+  implements Serializable, 
+             Cloneable, 
+             Comparable<Coordinate> {
 
+    public static Coordinate at(double latitude, double longitude) {      
+      return new Coordinate(latitude,longitude);
+    }
+    
+    public static Coordinate at(String position) {
+      return new Coordinate(position);
+    }
+    
+    public static Coordinate at(IsoPosition position) {
+      return new Coordinate(position);
+    }
+  
     private static final long serialVersionUID = -916272885213668761L;
 
-    private double latitude = 0.0f;
-    private double longitude = 0.0f;
-
-    public Coordinate() {
-    }
+    private final double latitude;
+    private final double longitude;
     
     public Coordinate(IsoPosition pos) {
       this(pos.getLatitude(),pos.getLongitude());
     }
 
     public Coordinate(double latitude, double longitude) {
-        setLatitude(latitude);
-        setLongitude(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");
+      this.latitude = latitude;
+      this.longitude = longitude;
     }
 
     public Coordinate(String value) {
-        Coordinate c = parse(value);
-        setLatitude(c.latitude);
-        setLongitude(c.longitude);
+      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");
     }
 
     public double getLatitude() {
         return latitude;
     }
 
-    public void setLatitude(double latitude) {
-        if (Double.compare(longitude, 90.0d) > 0)
-            throw new IllegalArgumentException("Latitude > 90.0 degrees");
-        if (Double.compare(longitude, -90.0d) < 0)
-            throw new IllegalArgumentException("Latitude < 90.0 degrees");
-        this.latitude = latitude;
-    }
-
     public double getLongitude() {
         return longitude;
     }
 
-    public void setLongitude(double longitude) {
-        if (Double.compare(longitude, 180.0d) > 0)
-            throw new IllegalArgumentException("Longitude > 180.0 degrees");
-        if (Double.compare(longitude, -180.0d) < 0)
-            throw new IllegalArgumentException("Longitude < 180.0 degrees");
-        this.longitude = longitude;
-    }
-
     public String toString() {
         return Double.toString(latitude) + " " + Double.toString(longitude);
     }

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/IsoPosition.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/IsoPosition.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/IsoPosition.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/IsoPosition.java Wed Oct 19 22:33:04 2011
@@ -27,6 +27,19 @@ import java.util.regex.Pattern;
 public final class IsoPosition 
   implements Serializable {
 
+  public static IsoPosition at(Coordinate coordinate) {
+    return new IsoPosition(coordinate.getLatitude(),coordinate.getLongitude());
+  }
+  
+  public static IsoPosition at(Point point) {
+    return new IsoPosition(
+      point.getCoordinate().getLatitude(),
+      point.getCoordinate().getLongitude(),
+      point.getElevation()
+    );
+  }
+ 
+ 
   private static final long serialVersionUID = -2330958817323976941L;
   private final Double alt, d_lat, d_lon;
   

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Line.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Line.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Line.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Line.java Wed Oct 19 22:33:04 2011
@@ -18,59 +18,83 @@
 package org.apache.abdera2.common.geo;
 
 public class Line extends Multiple {
+  
+  private static final long serialVersionUID = 2852975001208906285L;
 
-    private static final long serialVersionUID = 2852975001208906285L;
-
-    public Line() {
-    }
-
-    public Line(Multiple multiple) {
-        super(multiple);
-        verify();
-    }
-
-    public Line(Point point) {
-        super(point);
-        verify();
-    }
-
-    public Line(Coordinate... coordinates) {
-        super(coordinates);
-        verify();
-    }
-
-    public Line(Coordinates coordinates) {
-        super(coordinates);
-        verify();
-    }
-
-    public Line(String value) {
-        super(value);
-        verify();
-    }
-
-    public Line(Multiple... multiples) {
-        super(multiples);
-        verify();
-    }
-
-    public Line(Point... points) {
-        super(points);
-        verify();
+  public static Line with(Iterable<Coordinate> coordinates) {
+    Builder builder = make();
+    for (Coordinate c : coordinates)
+      builder.add(c);
+    return builder.get();    
+  }
+  
+  public static Line with(Coordinate... coordinates) {
+    Builder builder = make();
+    for (Coordinate c : coordinates)
+      builder.add(c);
+    return builder.get();
+  }
+  
+  public static Line with(String... positions) {
+    Builder builder = make();
+    for (String p : positions)
+      builder.add(p);
+    return builder.get();
+  }
+  
+  public static Line with(IsoPosition... positions) {
+    Builder builder = make();
+    for (IsoPosition p : positions)
+      builder.add(p);
+    return builder.get();
+  }
+  
+  
+  public static Builder make(Iterable<Coordinate> coordinates) {
+    Builder builder = make();
+    for (Coordinate c : coordinates)
+      builder.add(c);
+    return builder;    
+  }
+  
+  public static Builder make(Coordinate... coordinates) {
+    Builder builder = make();
+    for (Coordinate c : coordinates)
+      builder.add(c);
+    return builder;
+  }
+  
+  public static Builder make(String... positions) {
+    Builder builder = make();
+    for (String p : positions)
+      builder.add(p);
+    return builder;
+  }
+  
+  public static Builder make(IsoPosition... positions) {
+    Builder builder = make();
+    for (IsoPosition p : positions)
+      builder.add(p);
+    return builder;
+  }
+  
+    public static Builder make() {
+      return new Builder();
+    }
+  
+    public static class Builder extends Multiple.Builder<Line> {
+      
+      public Builder() {
+        noDuplicates();
+      }
+      
+      public Line get() {
+        return new Line(this);
+      }
+    }
+ 
+    public Line(Builder builder) {
+      super(builder);
     }
 
-    public Line(double... values) {
-        super(values);
-        verify();
-    }
-
-    @Override
-    public void setCoordinates(Coordinates coordinates) {
-        super.setCoordinates(coordinates);
-        verify();
-    }
-
-    public void verify() {
-        super.verify179Rule();
-    }
 }

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=1186541&r1=1186540&r2=1186541&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 Wed Oct 19 22:33:04 2011
@@ -17,67 +17,81 @@
  */
 package org.apache.abdera2.common.geo;
 
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Iterator;
-
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import static com.google.common.base.Preconditions.*;
+@SuppressWarnings("unchecked")
 public abstract class Multiple extends Position implements Iterable<Coordinate> {
+  
+  public static abstract class Builder<X extends Multiple> extends Position.Builder<X> {
 
+    protected Collection<Coordinate> coordinates = 
+      new ArrayList<Coordinate>();
+    protected int maxpoints = -1;
+    
+    public <P extends Builder<X>>P noDuplicates() {
+      this.coordinates = new LinkedHashSet<Coordinate>(coordinates);
+      return (P)this;
+    }
+    
+    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);
+      return (P)this;
+    }
+    
+    public <P extends Builder<X>>P add(Coordinate coordinate) {
+      checkState(maxpoints < 0 || coordinates.size()+1 <= maxpoints, "Maximum coordinates exceeded", 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);
+      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);
+      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);
+      this.coordinates.add(Coordinate.at(position));
+      return (P)this;
+    }
+    
+  }
+  
   private static final long serialVersionUID = -401256381030284678L;
-    protected Coordinates coordinates;
-
-    public Multiple() {
-    }
-
-    public Multiple(Multiple... multiples) {
-        this.coordinates = new Coordinates();
-        for (Multiple m : multiples)
-            coordinates.add(m.getCoordinates());
-    }
-
-    public Multiple(Multiple multiple) {
-        this(multiple.getCoordinates().clone());
-    }
-
-    public Multiple(Point point) {
-        this(point.getCoordinate().clone());
-    }
-
-    public Multiple(Point... points) {
-        this.coordinates = new Coordinates();
-        for (Point p : points)
-            coordinates.add(p.getCoordinate());
-    }
-
-    public Multiple(Coordinates coordinates) {
-        this.coordinates = coordinates;
-    }
+  protected final Collection<Coordinate> coordinates;
 
-    public Multiple(Coordinate... coordinates) {
-        this.coordinates = new Coordinates(coordinates);
-    }
-
-    public Multiple(String value) {
-        this.coordinates = new Coordinates(value);
-    }
-
-    public Multiple(double... values) {
-        this.coordinates = new Coordinates();
-        for (int n = 0; n < values.length; n = n + 2) {
-            Coordinate c = new Coordinate(values[n], values[n + 1]);
-            this.coordinates.add(c);
-        }
-    }
-
-    public Coordinates getCoordinates() {
-        return coordinates;
-    }
-
-    public void setCoordinates(Coordinates coordinates) {
-        this.coordinates = coordinates;
+    protected Multiple(Builder<?> builder) {
+      super(builder);
+      this.coordinates = 
+        builder.coordinates instanceof Set ?
+          ImmutableSet.<Coordinate>copyOf(builder.coordinates) :
+        ImmutableList.<Coordinate>copyOf(builder.coordinates);
     }
 
     public Iterator<Coordinate> iterator() {
         return coordinates.iterator();
     }
+    
+    public int size() {
+      return coordinates.size();
+    }
 
     @Override
     public int hashCode() {
@@ -105,22 +119,36 @@ public abstract class Multiple extends P
     }
 
     public int compareTo(Position o) {
-        if (o == null || !this.getClass().isInstance(o) || equals(o))
-            return 0;
-        return coordinates.compareTo(((Multiple)o).coordinates);
+        throw new UnsupportedOperationException();
     }
 
-    protected void verify179Rule() {
-        for (Coordinate c1 : getCoordinates()) {
-            for (Coordinate c2 : getCoordinates()) {
-                check179(c1.getLatitude(), c2.getLatitude());
-                check179(c1.getLongitude(), c2.getLongitude());
+    public static Iterable<Coordinate> parseIso(String value) {
+      List<Coordinate> list = new ArrayList<Coordinate>();
+      try {
+          String[] points = value.trim().split("\\s+");
+          for (int n = 0; n < points.length; n = n + 2) {
+              IsoPosition pos = IsoPosition.parse(points[n]);
+              list.add(new Coordinate(pos));
+          }
+          return list;
+      } catch (Throwable t) {
+          throw new RuntimeException("Error parsing coordinate pairs", t);
+      }      
+    }
+    
+    public static Iterable<Coordinate> parse(String value) {
+      List<Coordinate> list = new ArrayList<Coordinate>();
+        try {
+            String[] points = value.trim().split("\\s+");
+            for (int n = 0; n < points.length; n = n + 2) {
+                double lat = Double.parseDouble(points[n]);
+                double lon = Double.parseDouble(points[n + 1]);
+                Coordinate c = new Coordinate(lat, lon);
+                list.add(c);
             }
+            return list;
+        } catch (Throwable t) {
+            throw new RuntimeException("Error parsing coordinate pairs", t);
         }
     }
-
-    private void check179(double d1, double d2) {
-        if (Math.abs(Math.max(d1, d2)) - Math.abs(Math.min(d1, d2)) > 179)
-            throw new RuntimeException("Values are greater than 179 degrees");
-    }
 }

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=1186541&r1=1186540&r2=1186541&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 Wed Oct 19 22:33:04 2011
@@ -19,52 +19,92 @@ package org.apache.abdera2.common.geo;
 
 public class Point extends Position {
 
-    private static final long serialVersionUID = 7540202474168797239L;
-
-    private Coordinate coordinate;
-
-    public Point() {}
-
-    public Point(Point point) {
-        this.coordinate = point.getCoordinate().clone();
+    public static Point at(Coordinate coordinate) {
+      return make().at(coordinate).get();
     }
-
-    public Point(Coordinate coordinate) {
-        this.coordinate = coordinate;
+    
+    public static Point at(IsoPosition position) {
+      return make().at(position).get();
     }
-
-    public Point(double latitude, double longitude) {
-        this.coordinate = new Coordinate(latitude, longitude);
+    
+    public static Point at(String position) {
+      return make().at(position).get();
     }
-
-    public Point(String value) {
-        this.coordinate = new Coordinate(value);
+    
+    public static Point at(double latitude, double longitude) {
+      return make().at(latitude,longitude).get();
     }
-
-    public Point(IsoPosition pos) {
-        this.coordinate = new Coordinate(pos);
+    
+    public static Builder make(Coordinate coordinate) {
+      return make().at(coordinate);
     }
     
-    public Coordinate getCoordinate() {
-        return coordinate;
+    public static Builder make(IsoPosition position) {
+      return make().at(position);
     }
-
-    public void setCoordinate(IsoPosition pos) {
-      this.coordinate = new Coordinate(pos);
+    
+    public static Builder make(String position) {
+      return make().at(position);
     }
     
-    public void setCoordinate(Coordinate coordinate) {
+    public static Builder make(double latitude, double longitude) {
+      return make().at(latitude,longitude);
+    }
+  
+    public static Builder make() {
+      return new Builder();
+    }
+  
+    public static class Builder extends Position.Builder<Point> {
+
+      private Coordinate coordinate;
+      
+      public Builder at(Coordinate coordinate) {
         this.coordinate = coordinate;
+        return this;
+      }
+      
+      public Builder at(double latitude, double longitude) {
+        this.coordinate = Coordinate.at(latitude, longitude);
+        return this;
+      }
+      
+      public Builder at(String position) {
+        this.coordinate = Coordinate.at(position);
+        return this;
+      }
+      
+      public Builder at(IsoPosition position) {
+        this.coordinate = Coordinate.at(position);
+        return this;
+      }
+      
+      public Point get() {
+        return new Point(this);
+      }
+      
     }
+  
+    private static final long serialVersionUID = 7540202474168797239L;
 
-    public void setCoordinate(double latitude, double longitude) {
-        this.coordinate = new Coordinate(latitude, longitude);
-    }
+    private final Coordinate coordinate;
 
-    public void setCoordinate(String value) {
-        this.coordinate = new Coordinate(value);
+    private Point(Builder builder) {
+      super(builder);
+      this.coordinate = builder.coordinate;
     }
 
+    public Coordinate getCoordinate() {
+        return coordinate;
+    }
+    
+    public IsoPosition asIsoPosition() {
+      return new IsoPosition(
+        coordinate.getLatitude(),
+        coordinate.getLongitude(),
+        elevation);
+    }
+    
     @Override
     public int hashCode() {
         final int PRIME = 31;

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Polygon.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Polygon.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Polygon.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Polygon.java Wed Oct 19 22:33:04 2011
@@ -21,57 +21,74 @@ public class Polygon extends Multiple {
 
     private static final long serialVersionUID = 5387230171535985909L;
 
-    public Polygon() {
-        super();
-    }
-
-    public Polygon(Multiple multiple) {
-        super(multiple);
-        verify();
-    }
-
-    public Polygon(Point point) {
-        super(point);
-        verify();
-    }
-
-    public Polygon(Coordinate... coordinates) {
-        super(coordinates);
-        verify();
-    }
-
-    public Polygon(Coordinates coordinates) {
-        super(coordinates);
-        verify();
-    }
-
-    public Polygon(String value) {
-        super(value);
-        verify();
-    }
-
-    public Polygon(Multiple... multiples) {
-        super(multiples);
-        verify();
-    }
-
-    public Polygon(Point... points) {
-        super(points);
-        verify();
-    }
-
-    public Polygon(double... values) {
-        super(values);
-        verify();
-    }
-
-    @Override
-    public void setCoordinates(Coordinates coordinates) {
-        super.setCoordinates(coordinates);
-        verify();
-    }
-
-    public void verify() {
-        super.verify179Rule();
+    public static Polygon with(Iterable<Coordinate> coordinates) {
+      Builder builder = make();
+      for (Coordinate c : coordinates)
+        builder.add(c);
+      return builder.get();    
+    }
+    
+    public static Polygon with(Coordinate... coordinates) {
+      Builder builder = make();
+      for (Coordinate c : coordinates)
+        builder.add(c);
+      return builder.get();
+    }
+    
+    public static Polygon with(String... positions) {
+      Builder builder = make();
+      for (String p : positions)
+        builder.add(p);
+      return builder.get();
+    }
+    
+    public static Polygon with(IsoPosition... positions) {
+      Builder builder = make();
+      for (IsoPosition p : positions)
+        builder.add(p);
+      return builder.get();
+    }
+    
+    
+    public static Builder make(Iterable<Coordinate> coordinates) {
+      Builder builder = make();
+      for (Coordinate c : coordinates)
+        builder.add(c);
+      return builder;    
+    }
+    
+    public static Builder make(Coordinate... coordinates) {
+      Builder builder = make();
+      for (Coordinate c : coordinates)
+        builder.add(c);
+      return builder;
+    }
+    
+    public static Builder make(String... positions) {
+      Builder builder = make();
+      for (String p : positions)
+        builder.add(p);
+      return builder;
+    }
+    
+    public static Builder make(IsoPosition... positions) {
+      Builder builder = make();
+      for (IsoPosition p : positions)
+        builder.add(p);
+      return builder;
+    }
+    
+    public static Builder make() {
+      return new Builder();
+    }
+    
+    public static class Builder extends Multiple.Builder<Polygon> {
+      public Polygon get() {
+        return new Polygon(this);
+      }
+    }
+ 
+    public Polygon(Builder builder) {
+      super(builder);
     }
 }

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=1186541&r1=1186540&r2=1186541&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 Wed Oct 19 22:33:04 2011
@@ -19,58 +19,87 @@ package org.apache.abdera2.common.geo;
 
 import java.io.Serializable;
 
-public abstract class Position implements Serializable, Cloneable, Comparable<Position> {
+import com.google.common.base.Supplier;
 
-  private static final long serialVersionUID = 2024463162259330581L;
+public abstract class Position 
+  implements Serializable, 
+             Cloneable, 
+             Comparable<Position> {
+  
+    @SuppressWarnings("unchecked")
+    public static abstract class Builder<P extends Position> implements Supplier<P> {
+
+      protected String featureTypeTag;
+      protected String relationshipTag;
+      protected Double elevation;
+      protected Double floor;
+      protected Double radius;
+      
+      public <X extends Builder<P>>X featureType(String tag) {
+        this.featureTypeTag = tag;
+        return (X)this;
+      }
+      
+      public <X extends Builder<P>>X relationship(String tag) {
+        this.relationshipTag = tag;
+        return (X)this;
+      }
+      
+      public <X extends Builder<P>>X elevation(double elevation) {
+        this.elevation = elevation;
+        return (X)this;
+      }
+      
+      public <X extends Builder<P>>X floor(double floor) {
+        this.floor = floor;
+        return (X)this;
+      }
+      
+      public <X extends Builder<P>>X radius(double radius) {
+        this.radius = radius;
+        return (X)this;
+      }
+      
+    }
+  
+    private static final long serialVersionUID = 2024463162259330581L;
     public static final String DEFAULT_FEATURE_TYPE_TAG = "location";
     public static final String DEFAULT_RELATIONSHIP_TAG = "is-located-at";
 
-    protected String featureTypeTag;
-    protected String relationshipTag;
-    protected Double elevation;
-    protected Double floor;
-    protected Double radius;
-
+    protected final String featureTypeTag;
+    protected final String relationshipTag;
+    protected final Double elevation;
+    protected final Double floor;
+    protected final Double radius;
+
+    protected Position(Builder<?> builder) {
+      this.featureTypeTag = builder.featureTypeTag;
+      this.relationshipTag = builder.relationshipTag;
+      this.elevation = builder.elevation;
+      this.floor = builder.floor;
+      this.radius = builder.radius;
+    }
+    
     public Double getElevation() {
         return elevation;
     }
 
-    public void setElevation(Double elevation) {
-        this.elevation = elevation;
-    }
-
     public String getFeatureTypeTag() {
         return featureTypeTag;
     }
 
-    public void setFeatureTypeTag(String featureTypeTag) {
-        this.featureTypeTag = featureTypeTag;
-    }
-
     public Double getFloor() {
         return floor;
     }
 
-    public void setFloor(Double floor) {
-        this.floor = floor;
-    }
-
     public Double getRadius() {
         return radius;
     }
 
-    public void setRadius(Double radius) {
-        this.radius = radius;
-    }
-
     public String getRelationshipTag() {
         return relationshipTag;
     }
 
-    public void setRelationshipTag(String relationshipTag) {
-        this.relationshipTag = relationshipTag;
-    }
-
     @Override
     public int hashCode() {
         final int PRIME = 31;

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=1186541&r1=1186540&r2=1186541&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 Wed Oct 19 22:33:04 2011
@@ -16,7 +16,7 @@
  * directory of this distribution.
  */
 package org.apache.abdera2.common.http;
-
+import static com.google.common.base.Preconditions.*;
 import java.io.ByteArrayOutputStream;
 import java.io.Serializable;
 import java.util.ArrayList;
@@ -30,14 +30,16 @@ import java.util.Set;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import org.apache.abdera2.common.text.CharUtils.Profile;
 import org.apache.abdera2.common.text.Codec;
 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.isToken;
 import static org.apache.abdera2.common.text.CharUtils.quoted;
 import org.apache.commons.codec.binary.Base64;
 import org.apache.commons.codec.binary.StringUtils;
 
+import com.google.common.base.Supplier;
+
 /**
  * Implementation of the HTTP Challenge/Credentials Construct. This is helpful when 
  * using custom authentication mechanisms with an HTTP Request. It provides
@@ -64,28 +66,33 @@ public class Authentication implements I
   private final static Set<String> ALWAYS = 
     new HashSet<String>();
   static {
-      ALWAYS.add("domain");
-      ALWAYS.add("nonce");
-      ALWAYS.add("opaque");
-      ALWAYS.add("qop");
-      ALWAYS.add("realm");
+      alwaysQuote(
+        "domain",
+        "nonce",
+        "opaque",
+        "qop",
+        "realm");
   }
   
-  public static void alwaysQuote(String name) {
-    if (name == null)
-      throw new IllegalArgumentException();
-    ALWAYS.add(name);
+  public static synchronized void alwaysQuote(String... names) {
+    checkNotNull(names);
+    checkArgument(names.length > 0);
+    for (String name : names)
+      ALWAYS.add(name);
   }
   
   public static Iterable<Authentication> parse(String challenge) {
+    checkNotNull(challenge);
     List<Authentication> challenges = new ArrayList<Authentication>();
     Matcher matcher = pattern.matcher(challenge);
     while (matcher.find()) {
       String scheme = matcher.group(1);
       String params = matcher.group(2);
       String b64token = matcher.group(3); 
-      Authentication chal = 
-        new Authentication(scheme,b64token);
+      Authentication.Builder auth = 
+        make()
+          .scheme(scheme)
+          .b64token(b64token);
       if (params != null) {
         Matcher mparams = param.matcher(params);
         while(mparams.find()) {
@@ -94,13 +101,60 @@ public class Authentication implements I
           String name = ps[0];
           if (name.charAt(name.length()-1)=='*')
             name = name.substring(0,name.length()-1);
-          chal.add(name, Codec.decode(unquote(ps[1])));
+          auth.param(name, Codec.decode(unquote(ps[1])));
         }
       }
-      challenges.add(chal);
+      challenges.add(auth.get());
     }
     return challenges;
   }
+
+  public static class Builder 
+    implements Supplier<Authentication> {
+    private String scheme;
+    private String b64token;
+    private Map<String,String> params = 
+      new HashMap<String,String>();
+    private Set<String> quoted = 
+      new HashSet<String>();
+    
+    public Authentication get() {
+      checkNotNull(scheme);
+      return new Authentication(this);
+    }
+   
+    public Builder param(String name, String val) {
+      params.put(name, val);
+      return this;
+    }
+    
+    public Builder quotedParam(String name, String val) {
+      param(name,val);
+      quoted.add(name);
+      return this;
+    }
+    
+    public Builder isQuoted(String name) {
+      quoted.add(name);
+      return this;
+    }
+    
+    public Builder scheme(String scheme) {
+      checkNotNull(scheme);
+      this.scheme = scheme.toLowerCase();
+      return this;
+    }
+    
+    public Builder b64token(String token) {
+      this.b64token = token;
+      return this;
+    }
+   
+  }
+  
+  public static Builder make() {
+    return new Builder();
+  }
   
   private final String scheme;
   private final String b64token;
@@ -114,14 +168,16 @@ public class Authentication implements I
   }
   
   public Authentication(String scheme, String b64token) {
-    if (scheme == null)
-      throw new IllegalArgumentException();
+    checkNotNull(scheme);
     this.scheme = scheme.toLowerCase(Locale.US);
     this.b64token = b64token;
   }
   
-  private void add(String name, String value) {
-    params.put(name,value);
+  private Authentication(Builder builder) {
+    this.scheme = builder.scheme;
+    this.b64token = builder.b64token;
+    this.params.putAll(builder.params);
+    this.quoted.addAll(builder.quoted);
   }
   
   public String getScheme() {
@@ -140,22 +196,6 @@ public class Authentication implements I
     return name != null ? ALWAYS.contains(name) : false;
   }
   
-  public void setParam(String name, String val) {
-    if (val == null)
-      params.remove(name);
-    else
-      params.put(name, val);
-  }
-  
-  public void setQuotedParam(String name, String val) {
-    setParam(name,val);
-    quoted.add(name);
-  }
-  
-  public void setQuotedParam(String name) {
-    quoted.add(name);
-  }
-  
   public boolean hasParam(String name) {
     return params.containsKey(name);
   }
@@ -183,7 +223,7 @@ public class Authentication implements I
         String val = getParam(param);
         buf.append(param);
         boolean always = is_always_quoted(param) || isquoted(param);
-        if (!isToken(val) && !always) {
+        if (Profile.TOKEN.check(val) && !always) {
           buf.append('*')
              .append('=')
              .append(Codec.encode(val,Codec.STAR));

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=1186541&r1=1186540&r2=1186541&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 Wed Oct 19 22:33:04 2011
@@ -19,11 +19,178 @@ 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.Map;
 
+import com.google.common.base.Supplier;
+import com.google.common.collect.Iterables;
+
 public final class CacheControl implements Serializable {
 
+  public static Builder make() {
+    return new Builder();
+  }
+  
+  public static Builder make(CacheControl template) {
+    return new Builder(template);
+  }
+  
+  public static class Builder implements Supplier<CacheControl> {
+
+    protected int flags = 0;
+    protected 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>();
+    
+    public Builder() {
+      defaults();
+    }
+    
+    public Builder(CacheControl cc) {
+      from(cc);
+    }
+    
+    public Builder from(CacheControl cc) {
+      this.flags = cc.flags;
+      this.nocache_headers = cc.nocache_headers;
+      this.private_headers = cc.private_headers;
+      this.max_age = cc.max_age;
+      this.max_stale = cc.max_stale;
+      this.min_fresh = cc.min_fresh;
+      this.smax_age = cc.smax_age;
+      this.staleiferror = cc.staleiferror;
+      this.stalewhilerevalidate = cc.stalewhilerevalidate;
+      this.exts.putAll(cc.exts);
+      return this;
+    }
+    
+    public Builder defaults() {
+      return 
+         noCache(false)
+        .noStore(false)
+        .noTransform(false)
+        .onlyIfCached(false)
+        .maxAge(-1)
+        .maxStale(-1)
+        .minFresh(-1)
+        .staleIfError(-1)
+        .staleWhileRevalidate(-1)
+        .mustRevalidate(false)
+        .isPrivate(false)
+        .isPublic(false)
+        .maxAge(-1);
+    }
+    
+    public CacheControl get() {
+      return new CacheControl(this);
+    }
+    
+    public Builder extensions(Map<String,Object> exts) {
+      this.exts.putAll(exts);
+      return this;
+    }
+    
+    public Builder extension(String name, Object value) {
+      exts.put(name,value);
+      return this;
+    }
+    
+    public Builder staleIfError(long delta) {
+      this.staleiferror = Math.max(-1,delta);
+      return this;
+    }
+    
+    public Builder staleWhileRevalidate(long delta) {
+      this.stalewhilerevalidate = Math.max(-1,delta);
+      return this;
+    }
+    
+    public Builder maxAge(long max_age) {
+      this.max_age = Math.max(-1,max_age);
+      return this;
+    }
+
+    public Builder mustRevalidate(boolean val) {
+      toggle(val,REVALIDATE);
+      return this;
+    }
+
+    public Builder proxyRevalidate(boolean val) {
+      toggle(val,PROXYREVALIDATE);
+      return this;
+    }
+
+    public Builder noCache(boolean val) {
+      toggle(val,NOCACHE);
+      return this;
+    }
+
+    public Builder noStore(boolean val) {
+      toggle(val,NOSTORE);
+      return this;
+    }
+
+    public Builder noTransform(boolean val) {
+      toggle(val,NOTRANSFORM);
+      return this;
+    }
+    
+    public Builder isPublic(boolean val) {
+      toggle(val,PUBLIC);
+      return this;
+    }
+
+    public Builder isPrivate(boolean val) {
+      toggle(val,PRIVATE);
+      return this;
+    }
+
+    public Builder privateHeaders(String... headers) {
+      this.private_headers = headers;
+      return this;
+    }
+
+    public Builder noCacheHeaders(String... headers) {
+      this.nocache_headers = headers;
+      return this;
+    }
+
+    public Builder maxStale(long max_stale) {
+      this.max_stale = max_stale;
+      return this;
+    }
+
+    public Builder minFresh(long min_fresh) {
+      this.min_fresh = min_fresh;
+      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;
+    }
+  
+  }
+  
+  public static CacheControl parse(String cc) {
+    return CacheControlUtil.parseCacheControl(cc, make()).get();
+  }
+  
   private static final long serialVersionUID = 3554586802963893228L;
   public final static int NOCACHE = 1,
                           NOSTORE = 2,
@@ -33,68 +200,42 @@ public final class CacheControl implemen
                           REVALIDATE = 32,
                           PROXYREVALIDATE = 64,
                           ONLYIFCACHED = 128;
-  protected int flags = 0;
-  protected String[] nocache_headers = null,
-                     private_headers = null;
-  protected long max_age = -1,
-                 max_stale = -1,
-                 min_fresh = -1,
-                 smax_age = -1,
-                 staleiferror = -1,
-                 stalewhilerevalidate = -1;
+  protected final int flags;
+  protected final 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>();
   
-  public CacheControl() {}
-  
-  public CacheControl(String cc) {
-    CacheControlUtil.parseCacheControl(cc, this);
-  }
-  
-  public CacheControl setExtensions(Map<String,Object> exts) {
-    this.exts.putAll(exts);
-    return this;
-  }
-  
-  public CacheControl setExtension(String name, Object value) {
-    exts.put(name,value);
-    return this;
+  private CacheControl(Builder builder) {
+    this.flags = builder.flags;
+    this.nocache_headers = builder.nocache_headers;
+    this.private_headers = builder.private_headers;
+    this.max_age = builder.max_age;
+    this.max_stale = builder.max_stale;
+    this.min_fresh = builder.min_fresh;
+    this.smax_age = builder.smax_age;
+    this.staleiferror = builder.staleiferror;
+    this.stalewhilerevalidate = builder.stalewhilerevalidate;
+    this.exts.putAll(builder.exts);
   }
   
   public Object getExtension(String name) {
     return exts.get(name);
   }
   
-  public String[] listExtensions() {
-    return exts.keySet().toArray(new String[exts.size()]);
+  public Iterable<String> listExtensions() {
+    return Iterables.unmodifiableIterable(exts.keySet());
   }
   
   protected boolean check(int flag) {
     return (flags & flag) == flag;
   }
-
-  protected void toggle(boolean val, int flag) {
-      if (val)
-          flags |= flag;
-      else
-          flags &= ~flag;
-  }
-  
-  public void setDefaults() {
-    setNoCache(false);
-    setNoStore(false);
-    setNoTransform(false);
-    setOnlyIfCached(false);
-    setMaxAge(-1);
-    setMaxStale(-1);
-    setMinFresh(-1);
-    setStaleIfError(-1);
-    setStaleWhileRevalidate(-1);
-    setMustRevalidate(false);
-    setPrivate(false);
-    setPublic(false);
-    setMaxAge(-1);
-  }
   
   public boolean isNoCache() {
     return check(NOCACHE);
@@ -112,12 +253,12 @@ public final class CacheControl implemen
       return max_age;
   }
   
-  public String[] getNoCacheHeaders() {
-    return isNoCache() ? nocache_headers : null;
+  public Iterable<String> getNoCacheHeaders() {
+    return isNoCache() ? Arrays.asList(nocache_headers) : Collections.<String>emptySet();
   }
 
-  public String[] getPrivateHeaders() {
-    return isPrivate() ? private_headers : null;
+  public Iterable<String> getPrivateHeaders() {
+    return isPrivate() ? Arrays.asList(private_headers) : Collections.<String>emptySet();
   }
 
   public long getSMaxAge() {
@@ -147,67 +288,7 @@ public final class CacheControl implemen
   public long getStaleWhileRevalidate() {
     return stalewhilerevalidate;
   }
-  
-  public CacheControl setStaleIfError(long delta) {
-    this.staleiferror = Math.max(-1,delta);
-    return this;
-  }
-  
-  public CacheControl setStaleWhileRevalidate(long delta) {
-    this.stalewhilerevalidate = Math.max(-1,delta);
-    return this;
-  }
-  
-  public CacheControl setMaxAge(long max_age) {
-    this.max_age = Math.max(-1,max_age);
-    return this;
-  }
-
-  public CacheControl setMustRevalidate(boolean val) {
-    toggle(val,REVALIDATE);
-    return this;
-  }
-
-  public CacheControl setProxyRevalidate(boolean val) {
-    toggle(val,PROXYREVALIDATE);
-    return this;
-  }
-
-  public CacheControl setNoCache(boolean val) {
-    toggle(val,NOCACHE);
-    return this;
-  }
-
-  public CacheControl setNoStore(boolean val) {
-    toggle(val,NOSTORE);
-    return this;
-  }
-
-  public CacheControl setNoTransform(boolean val) {
-    toggle(val,NOTRANSFORM);
-    return this;
-  }
-  
-  public CacheControl setPublic(boolean val) {
-    toggle(val,PUBLIC);
-    return this;
-  }
-
-  public CacheControl setPrivate(boolean val) {
-    toggle(val,PRIVATE);
-    return this;
-  }
-
-  public CacheControl setPrivateHeaders(String... headers) {
-    this.private_headers = headers;
-    return this;
-  }
-
-  public CacheControl setNoCacheHeaders(String... headers) {
-    this.nocache_headers = headers;
-    return this;
-  }
-  
+    
   public boolean isOnlyIfCached() {
     return check(ONLYIFCACHED);
   }
@@ -220,21 +301,6 @@ public final class CacheControl implemen
     return min_fresh;
   }
   
-  public CacheControl setMaxStale(long max_stale) {
-    this.max_stale = max_stale;
-    return this;
-  }
-
-  public CacheControl setMinFresh(long min_fresh) {
-    this.min_fresh = min_fresh;
-    return this;
-  }
-  
-  public CacheControl setOnlyIfCached(boolean val) {
-    toggle(val,ONLYIFCACHED);
-    return this;
-  }
-  
   public String toString() {
     return CacheControlUtil.buildCacheControl(this);
   }
@@ -287,33 +353,31 @@ public final class CacheControl implemen
   }
   
   public static CacheControl NOCACHE() {
-    CacheControl cc = new CacheControl();
-    cc.setNoCache(true);
-    return cc;
+    return make().noCache(true).get();
+  }
+  
+  public static CacheControl NONNOCACHE() {
+    return make().noCache(false).get();
   }
   
   public static CacheControl NOSTORE() {
-    CacheControl cc = new CacheControl();
-    cc.setNoStore(true);
-    return cc;
+    return make().noStore(true).get();
+  }
+  
+  public static CacheControl NONNOSTORE() {
+    return make().noStore(false).get();
   }
   
   public static CacheControl MAXAGE(long age) {
-    CacheControl cc = new CacheControl();
-    cc.setMaxAge(age);
-    return cc;
+    return make().maxAge(age).get();
   }
   
   public static CacheControl PUBLIC() {
-    CacheControl cc = new CacheControl();
-    cc.setPublic(true);
-    return cc;
+    return make().isPublic(true).get();
   }
   
   public static CacheControl PRIVATE() {
-    CacheControl cc = new CacheControl();
-    cc.setPrivate(true);
-    return cc;
+    return make().isPrivate(true).get();
   }
   
 }

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=1186541&r1=1186540&r2=1186541&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 Wed Oct 19 22:33:04 2011
@@ -25,11 +25,16 @@ import java.util.regex.Pattern;
 
 import org.apache.abdera2.common.text.CharUtils;
 
+import com.google.common.base.Joiner;
+import com.google.common.collect.Iterables;
+
 /**
  * Provides parsing and properly handling of the HTTP Cache-Control header.
  */
-public class CacheControlUtil {
+public final class CacheControlUtil {
 
+    private CacheControlUtil() {}
+  
     private static long value(String val) {
         return (val != null) ? Long.parseLong(val) : -1;
     }
@@ -40,6 +45,8 @@ public class CacheControlUtil {
         buf.append(value);
     }
 
+    private static final Joiner joiner = Joiner.on(',').skipNulls();
+    
     /**
      * Construct the Cache-Control header from info in the request object
      */
@@ -47,13 +54,10 @@ public class CacheControlUtil {
         StringBuilder buf = new StringBuilder();
         if (cacheControl.isPrivate()) {
             append(buf, "private");
-            String[] headers = cacheControl.getPrivateHeaders();
-            if (headers != null && headers.length > 0) {
+            Iterable<String> headers = cacheControl.getPrivateHeaders();
+            if (!Iterables.isEmpty(headers)) {
               buf.append("=\"");
-              for (int n = 0; n < headers.length; n++) {
-                if (n > 0) buf.append(",");
-                buf.append(headers[n]);
-              }
+              joiner.appendTo(buf, headers);
               buf.append("\"");
             }
         }
@@ -61,13 +65,10 @@ public class CacheControlUtil {
             append(buf, "public");
         if (cacheControl.isNoCache()) {
             append(buf, "no-cache");
-            String[] headers = cacheControl.getNoCacheHeaders();
-            if (headers != null && headers.length > 0) {
+            Iterable<String> headers = cacheControl.getNoCacheHeaders();
+            if (!Iterables.isEmpty(headers)) {
               buf.append("=\"");
-              for (int n = 0; n < headers.length; n++) {
-                if (n > 0) buf.append(",");
-                buf.append(headers[n]);
-              }
+              joiner.appendTo(buf,headers);
               buf.append("\"");
             }   
         }
@@ -112,13 +113,14 @@ public class CacheControlUtil {
     /**
      * Parse the Cache-Control header
      */
-    public static void parseCacheControl(String cc, CacheControl cacheControl) {
-        if (cc == null) return;
-        cacheControl.setDefaults();
+    public static CacheControl.Builder parseCacheControl(String cc, CacheControl.Builder builder) {
+        if (cc == null) return builder;
+        builder.defaults();
         CacheControlParser parser = new CacheControlParser(cc);
         for (Directive directive : parser)
-          directive.set(cacheControl, parser);
-        cacheControl.setExtensions(parser.getExtensions());
+          directive.set(builder, parser);
+        builder.extensions(parser.getExtensions());
+        return builder;
     }
 
     /**
@@ -149,48 +151,48 @@ public class CacheControlUtil {
             return UNKNOWN;
         }
         
-        public void set(CacheControl cacheControl, CacheControlParser parser) {
+        public void set(CacheControl.Builder builder, CacheControlParser parser) {
           switch (this) {
           case NOCACHE:
-              cacheControl.setNoCache(true);
-              cacheControl.setNoCacheHeaders(parser.getValues(this));
+              builder.noCache(true);
+              builder.noCacheHeaders(parser.getValues(this));
               break;
           case NOSTORE:
-              cacheControl.setNoStore(true);
+              builder.noStore(true);
               break;
           case NOTRANSFORM:
-              cacheControl.setNoTransform(true);
+              builder.noTransform(true);
               break;
           case ONLYIFCACHED:
-              cacheControl.setOnlyIfCached(true);
+              builder.onlyIfCached(true);
               break;
           case MAXAGE:
-              cacheControl.setMaxAge(value(parser.getValue(this)));
+              builder.maxAge(value(parser.getValue(this)));
               break;
           case MAXSTALE:
-              cacheControl.setMaxStale(value(parser.getValue(this)));
+              builder.maxStale(value(parser.getValue(this)));
               break;
           case MINFRESH:
-              cacheControl.setMinFresh(value(parser.getValue(this)));
+              builder.minFresh(value(parser.getValue(this)));
               break;
           case STALEIFERROR:
-              cacheControl.setStaleIfError(value(parser.getValue(this)));
+              builder.staleIfError(value(parser.getValue(this)));
               break;
           case MUSTREVALIDATE:
-              cacheControl.setMustRevalidate(true);
+              builder.mustRevalidate(true);
               break;
           case PROXYREVALIDATE:
-              cacheControl.setProxyRevalidate(true);
+              builder.proxyRevalidate(true);
               break;
           case PUBLIC:
-              cacheControl.setPublic(true);
+              builder.isPublic(true);
               break;
           case PRIVATE:
-              cacheControl.setPrivate(true);
-              cacheControl.setPrivateHeaders(parser.getValues(this));
+              builder.isPrivate(true);
+              builder.privateHeaders(parser.getValues(this));
             break;
           case STALEWHILEREVALIDATE:
-            cacheControl.setStaleWhileRevalidate(value(parser.getValue(this)));
+            builder.staleWhileRevalidate(value(parser.getValue(this)));
             break;
           }
         }

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=1186541&r1=1186540&r2=1186541&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 Wed Oct 19 22:33:04 2011
@@ -17,6 +17,8 @@ import static org.apache.abdera2.common.
 import org.apache.abdera2.common.text.Codec;
 import org.apache.abdera2.common.text.CharUtils.Profile;
 
+import com.google.common.base.Supplier;
+
 /**
  * Implementation of the Prefer HTTP Header, e.g.
  * 
@@ -55,6 +57,45 @@ public class Preference implements Seria
   public static final Preference PREF_RETURN_CONTENT =
     new Preference(RETURN_CONTENT);
   
+  public static Builder make() {
+    return new Builder();
+  }
+  
+  public static class Builder implements Supplier<Preference> {
+
+    private String token;
+    private String value;
+    private final Map<String,String> params = 
+      new HashMap<String,String>();
+    
+    public Preference get() {
+      return new Preference(this);
+    }
+    
+    public Builder token(String token) {
+      this.token = token;
+      return this;
+    }
+    
+    public Builder value(String value) {
+      this.value = value;
+      return this;
+    }
+    
+    public Builder param(String key, String val) {
+      if (key == null || reserved(key)) 
+        throw new IllegalArgumentException();
+      this.params.put(key,val);
+      return this;
+    }
+    
+    public Builder params(Map<String,String> params) {
+      this.params.putAll(params);
+      return this;
+    }
+    
+  }
+  
   /**
    * The "return-status" token indicates that the client prefers that the
    * server include an entity describing the status of the request in the
@@ -69,12 +110,18 @@ public class Preference implements Seria
   private final Map<String,String> params = 
     new HashMap<String,String>();
   
+  private Preference(Builder builder) {
+    this.token = builder.token;
+    this.value = builder.value;
+    this.params.putAll(builder.params);
+  }
+  
   public Preference(String token) {
     this(token,null);
   }
   
   public Preference(String token, String value) {
-    CharUtils.verify(token, Profile.TOKEN);
+    Profile.TOKEN.verify(token);
     this.token = token.toLowerCase();
     this.value = value;
   }
@@ -96,16 +143,6 @@ public class Preference implements Seria
     return reserved.contains(name);
   }
   
-  public void addParam(String name, String value) {
-    if (name == null || reserved(name)) 
-      throw new IllegalArgumentException();
-    if (value == null && params.containsKey(name))
-      params.remove(name);
-    else {
-      params.put(name, value);
-    }
-  }
-  
   public boolean matches(String token) {
     if (token == null) return false;
     return this.token.equalsIgnoreCase(token.toLowerCase());
@@ -214,17 +251,17 @@ public class Preference implements Seria
           tokenval = Codec.decode(CharUtils.unquote(ps[1]));
       }
       
-      Preference preference = new Preference(token,tokenval);
-      prefs.add(preference);
-      
+      Preference.Builder maker = 
+        Preference.make().token(token).value(tokenval);   
       if (params != null) {
         Matcher mparams = param.matcher(params);
         while(mparams.find()) {
           String p = mparams.group(1);
           String[] ps = p.split("\\s*=\\s*", 2);
-          preference.addParam(ps[0], Codec.decode(CharUtils.unquote(ps[1])));
+          maker.param(ps[0], Codec.decode(CharUtils.unquote(ps[1])));
         }
       }
+      prefs.add(maker.get());
     }
     return prefs;
   }



Mime
View raw message