abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r1205178 - in /abdera/abdera2: activities/src/main/java/org/apache/abdera2/activities/extra/Extra.java common/src/main/java/org/apache/abdera2/common/selector/Selectors.java
Date Tue, 22 Nov 2011 21:18:56 GMT
Author: jmsnell
Date: Tue Nov 22 21:18:56 2011
New Revision: 1205178

URL: http://svn.apache.org/viewvc?rev=1205178&view=rev
Log:
Minor api updates...

Modified:
    abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/extra/Extra.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/Selectors.java

Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/extra/Extra.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/extra/Extra.java?rev=1205178&r1=1205177&r2=1205178&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/extra/Extra.java
(original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/extra/Extra.java
Tue Nov 22 21:18:56 2011
@@ -755,9 +755,9 @@ public final class Extra {
    * the downstreamDuplicates and upstreamDuplicates properties
    * into account when determining equivalence.
    */
-  private static Equivalence<ASObject> identity() {
-    return new Equivalence<ASObject>() {
-      protected boolean doEquivalent(ASObject a, ASObject b) {
+  public static <X extends ASObject>Equivalence<X> identity() {
+    return new Equivalence<X>() {
+      protected boolean doEquivalent(X a, X b) {
         Selector<Map.Entry<String,Object>> filter = 
           ASBase.withFields("id","alias","objectType");
         Map<String,Object> map1 = Maps.transformEntries(a.toMap(filter),lower_val);
@@ -778,9 +778,9 @@ public final class Extra {
     };
   }
   
-  private static Equivalence<ASObject> identityWithDuplicates() {
-    return new Equivalence<ASObject>() {
-      protected boolean doEquivalent(ASObject a, ASObject b) {
+  public static <X extends ASObject>Equivalence<X> identityWithDuplicates() {
+    return new Equivalence<X>() {
+      protected boolean doEquivalent(X a, X b) {
         if (IDENTITY_EQUIVALENCE.equivalent(a, b)) 
           return true;
         Iterable<String> aids = a.getKnownIds();
@@ -801,22 +801,30 @@ public final class Extra {
   }
   
   public static final Comparator<ASObject> UPDATED_COMPARATOR = 
-    new UpdatedComparator();
+    new UpdatedComparator<ASObject>();
   public static final Comparator<ASObject> PUBLISHED_COMPARATOR = 
-    new PublishedComparator();
+    new PublishedComparator<ASObject>();
   
-  static class UpdatedComparator 
-    extends DateTimes.DateTimeComparator<ASObject> {
-      public int compare(ASObject a1, ASObject a2) {
+  public static <X extends ASObject>Comparator<X> updatedComparator() {
+    return new UpdatedComparator<X>();
+  }
+  
+  public static <X extends ASObject>Comparator<X> publishedComparator() {
+    return new PublishedComparator<X>();
+  }
+  
+  static class UpdatedComparator<X extends ASObject>
+    extends DateTimes.DateTimeComparator<X> {
+      public int compare(X a1, X a2) {
         DateTime d1 = a1.getUpdated();
         DateTime d2 = a2.getUpdated();
         return innerCompare(d1,d2);
       }
   }
   
-  static class PublishedComparator 
-    extends DateTimes.DateTimeComparator<ASObject> {
-      public int compare(ASObject a1, ASObject a2) {
+  static class PublishedComparator<X extends ASObject>
+    extends DateTimes.DateTimeComparator<X> {
+      public int compare(X a1, X a2) {
         return innerCompare(
           a1.getPublished(), 
           a2.getPublished());

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/Selectors.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/Selectors.java?rev=1205178&r1=1205177&r2=1205178&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/Selectors.java
(original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/Selectors.java
Tue Nov 22 21:18:56 2011
@@ -19,6 +19,7 @@ package org.apache.abdera2.common.select
 
 import java.util.concurrent.atomic.AtomicInteger;
 
+import com.google.common.base.Equivalence;
 import com.google.common.base.Function;
 import com.google.common.base.Predicate;
 import com.google.common.base.Predicates;
@@ -141,6 +142,15 @@ public final class Selectors {
   }
   
   /**
+   * Returns a Selector<X> for the given Equivalence
+   */
+  public static <X>Selector<X> equivalentTo(
+    final Equivalence<X> equivalence,
+    final X item) {
+      return forPredicate(equivalence.equivalentTo(item));
+  }
+  
+  /**
    * Returns a Selector<X> that wraps the specified Predicate<X>
    */
   public static <X>Selector<X> forPredicate(



Mime
View raw message