abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r1201524 - in /abdera/abdera2: common/src/main/java/org/apache/abdera2/common/selector/ common/src/main/java/org/apache/abdera2/common/templates/ common/src/main/java/org/apache/abdera2/common/text/ examples/src/main/java/org/apache/abdera2...
Date Sun, 13 Nov 2011 21:53:14 GMT
Author: jmsnell
Date: Sun Nov 13 21:53:14 2011
New Revision: 1201524

URL: http://svn.apache.org/viewvc?rev=1201524&view=rev
Log: (empty)

Modified:
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/AbstractSelector.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/Selector.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/Selectors.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/templates/Expression.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/templates/MultiContext.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/text/CharUtils.java
    abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/ReadingListExample.java
    abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/RepliesAndTargetingExample.java

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/AbstractSelector.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/AbstractSelector.java?rev=1201524&r1=1201523&r2=1201524&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/AbstractSelector.java
(original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/AbstractSelector.java
Sun Nov 13 21:53:14 2011
@@ -20,6 +20,8 @@ package org.apache.abdera2.common.select
 import com.google.common.base.Function;
 import com.google.common.base.Predicate;
 import com.google.common.collect.Constraint;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
 
 @SuppressWarnings("unchecked")
 public abstract class AbstractSelector<X> 
@@ -29,6 +31,54 @@ public abstract class AbstractSelector<X
     return select(item);
   }
   
+  public boolean all(Iterable<X> items) {
+    if (items == null) return false;
+    return Iterables.all(items, this);
+  }
+  
+  public boolean any(Iterable<X> items) {
+    if (items == null) return false;
+    return Iterables.any(items, this);
+  }
+  
+  public boolean none(Iterable<X> items) {
+    if (items == null) return false;
+    return Iterables.all(items, this.negate());
+  }
+  
+  public Iterable<X> filter(Iterable<X> items) {
+    if (items == null) return ImmutableSet.<X>of();
+    return Iterables.filter(items, this);
+  }
+  
+  public Iterable<X> filterOut(Iterable<X> items) {
+    if (items == null) return ImmutableSet.of();
+    return Iterables.<X>filter(items, this.negate());
+  }
+  
+  public X choose(Iterable<X> items) {
+    if (items == null) return null;
+    return Iterables.find(items, this);
+  }
+  
+  public X chooseNot(Iterable<X> items) {
+    if (items == null) return null;
+    return Iterables.find(items, this.negate());
+  }
+  
+  public X test(X item) {
+    return apply(item) ? item : null;
+  }
+  
+  public X test(X item, X otherwise) {
+    return apply(item) ? item : otherwise;
+  }
+  
+  public <Y>Y test(X item, Function<X,Y> transform) {
+    return apply(item) ? transform.apply(item) : null;
+  }
+ 
+ 
   public X checkElement(X element) {
     if (apply(element))
       return element;

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/Selector.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/Selector.java?rev=1201524&r1=1201523&r2=1201524&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/Selector.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/Selector.java Sun
Nov 13 21:53:14 2011
@@ -31,14 +31,55 @@ public interface Selector<X>
     /** Returns true the item is to be selected **/
     boolean select(Object item);
 
-    public Function<X,Boolean> asFunction();
-    public Predicate<X> asPredicate();
-    public Constraint<X> asConstraint();
+    /** Returns true if all the items in the set match **/
+    boolean all(Iterable<X> items);
+    
+    /** Returns true if any the items in the set match **/
+    boolean any(Iterable<X> items);
+    
+    /** Returns true if none the items in the set match **/
+    boolean none(Iterable<X> items);
+    
+    /**
+     * Returns an immutable iterable containing only the items 
+     * from the given iterable for which the selector applies
+     */
+    Iterable<X> filter(Iterable<X> items);
+    
+    /**
+     * Returns an immutable iterable containing only the items
+     * from the given iterable for which the selector does not apply
+     */
+    Iterable<X> filterOut(Iterable<X> items);
+    
+    /**
+     * Returns the first item in the set that matches the selector
+     */
+    X choose(Iterable<X> items);
+    
+    /**
+     * Returns the first item in the set that matches the selector
+     */
+    X chooseNot(Iterable<X> items);
+    
+    /** Returns the object if the Selector applies, or return null if it doesn't **/
+    X test(X item);
+    
+    /** Returns the result of transform.apply(item) if the Selector applies to the input
**/
+    <Y>Y test(X item, Function<X,Y> transform);
+    
+    /** Returns the object if the Selector applies, or return the other X if it doesn't **/
+    X test(X item, X otherwise);
+    
+    Function<X,Boolean> asFunction();
+    Predicate<X> asPredicate();
+    Constraint<X> asConstraint();
+    
     
     /**
      * Returns a Selector that matches this selector up to a specific number of times
      */
-    public Selector<X> limit(int limit);
+    Selector<X> limit(int limit);
     
     /**
      * Returns a Selector<Y> A using this Selector B and Funtion<Y,X> C such
that
@@ -46,27 +87,27 @@ public interface Selector<X>
      * B(X),
      * A(Y) = B(C(Y))
      */
-    public <Y>Selector<Y> compose(Function<Y,X> transform);
+    <Y>Selector<Y> compose(Function<Y,X> transform);
     /**
      * Returns a Selector that selects the opposite of this selector
      */
-    public Selector<X> negate();
+    Selector<X> negate();
     /**
      * Returns a Selector that is the union of this and the specified selector
      */
-    public Selector<X> and(Selector<X> selector);
+    Selector<X> and(Selector<X> selector);
     /**
      * Returns a Selector that matches either this or the specified selector
      */
-    public Selector<X> or(Selector<X> selector);
+    Selector<X> or(Selector<X> selector);
     /**
      * Returns a Selector that matches this, but not the specified selector
      */
-    public Selector<X> andNot(Selector<X> selector);
+    Selector<X> andNot(Selector<X> selector);
     /**
      * Returns a Selector that matches this or the inverse of the specified selector
      */
-    public Selector<X> orNot(Selector<X> selector);
+    Selector<X> orNot(Selector<X> selector);
     
     public static class ConstraintSelector<X>
       extends AbstractSelector<X> {

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=1201524&r1=1201523&r2=1201524&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
Sun Nov 13 21:53:14 2011
@@ -29,6 +29,14 @@ public final class Selectors {
   
   private Selectors() {}
   
+  public static <X>Selector<X> notNull() {
+    return forPredicate(Predicates.<X>notNull());
+  }
+  
+  public static <X>Selector<X> isNull() {
+    return forPredicate(Predicates.<X>isNull());
+  }
+  
   public static <X>Selector<X> alwaysTrue() {
     return forPredicate(Predicates.<X>alwaysTrue());
   }

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/templates/Expression.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/templates/Expression.java?rev=1201524&r1=1201523&r2=1201524&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/templates/Expression.java
(original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/templates/Expression.java
Sun Nov 13 21:53:14 2011
@@ -18,9 +18,7 @@
 package org.apache.abdera2.common.templates;
 
 import java.io.Serializable;
-import java.util.ArrayList;
 import java.util.Iterator;
-import java.util.List;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -30,7 +28,7 @@ import org.apache.abdera2.common.templat
 import org.apache.abdera2.common.templates.Expression;
 import org.apache.abdera2.common.templates.Operation;
 
-import com.google.common.collect.Iterables;
+import com.google.common.collect.ImmutableList;
 
 import static com.google.common.base.Preconditions.*;
 import static org.apache.abdera2.common.misc.MorePreconditions.*;
@@ -41,7 +39,7 @@ public final class Expression 
   private static final long serialVersionUID = 1457650843240079628L;
   private static final Pattern EXPRESSION = Pattern.compile("([\\+\\#\\.\\/\\;\\?\\&\\=\\,\\!\\@\\|\\$\\(\\)])?(.*){1}");
   private static final Pattern VARSPEC = Pattern.compile("([^(?:\\:\\d+)\\*\\^]+)([(?:\\:\\d+)\\*\\^]+)?");
-  private static final Pattern LENGTH = Pattern.compile("\\:(\\d+)");
+  static final Pattern LENGTH = Pattern.compile("\\:(\\d+)");
   
   private final String EXP;
   private final Operation op;
@@ -103,7 +101,7 @@ public final class Expression 
   }
 
   private Pair<Operation,Iterable<VarSpec>> parse() {
-    List<VarSpec> varspecs = new ArrayList<VarSpec>();
+    ImmutableList.Builder<VarSpec> varspecs = ImmutableList.builder();
     Operation op = null;
     Matcher mt = EXPRESSION.matcher(EXP);
     if (checkArgument(mt.find(),"Invalid Expression")) {
@@ -120,7 +118,7 @@ public final class Expression 
               vt.group(2)));
       }
     }
-    return Pair.of(op,Iterables.unmodifiableIterable(varspecs));
+    return Pair.<Operation,Iterable<VarSpec>>of(op,varspecs.build());
   }
   
   

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/templates/MultiContext.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/templates/MultiContext.java?rev=1201524&r1=1201523&r2=1201524&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/templates/MultiContext.java
(original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/templates/MultiContext.java
Sun Nov 13 21:53:14 2011
@@ -19,7 +19,6 @@ package org.apache.abdera2.common.templa
 
 import java.util.HashSet;
 import java.util.Iterator;
-import java.util.LinkedHashSet;
 import java.util.Map;
 import java.util.Set;
 
@@ -37,9 +36,9 @@ public final class MultiContext 
   
   public static final class Builder implements Supplier<Context> {
 
-    private final Set<Context> contexts = 
-      new LinkedHashSet<Context>();
-    private boolean isiri;
+    final ImmutableSet.Builder<Context> contexts = 
+      ImmutableSet.builder();
+    boolean isiri;
     
     public Builder iri() {
       this.isiri = false;
@@ -76,7 +75,7 @@ public final class MultiContext 
   
   MultiContext(Builder builder) {
     super(builder.isiri);
-    this.contexts = ImmutableSet.copyOf(builder.contexts);
+    this.contexts = builder.contexts.build();
   } 
   public boolean contains(String var) {
     for (Context context : contexts)

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/text/CharUtils.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/text/CharUtils.java?rev=1201524&r1=1201523&r2=1201524&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/text/CharUtils.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/text/CharUtils.java Sun
Nov 13 21:53:14 2011
@@ -209,4 +209,5 @@ public final class CharUtils {
   }
   
   public static final Joiner joiner = Joiner.on(',').skipNulls();
+
 }

Modified: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/ReadingListExample.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/ReadingListExample.java?rev=1201524&r1=1201523&r2=1201524&view=diff
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/ReadingListExample.java
(original)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/ReadingListExample.java
Sun Nov 13 21:53:14 2011
@@ -57,9 +57,7 @@ public class ReadingListExample {
            makeBook()
              .displayName("Meditations on the Method")
              .author(
-               makePerson()
-                 .displayName("Rene Descartes")
-                 .get())
+               makePerson("Rene Descartes").get())
              .get())
          .set("format", HARDCOVER())
          .get());

Modified: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/RepliesAndTargetingExample.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/RepliesAndTargetingExample.java?rev=1201524&r1=1201523&r2=1201524&view=diff
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/RepliesAndTargetingExample.java
(original)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/RepliesAndTargetingExample.java
Sun Nov 13 21:53:14 2011
@@ -1,5 +1,6 @@
 package org.apache.abdera2.examples.activities;
 
+import static org.apache.abdera2.activities.extra.Extra.*;
 import org.apache.abdera2.activities.model.Activity;
 import static org.apache.abdera2.activities.model.objects.NoteObject.makeNote;
 import static org.apache.abdera2.activities.model.objects.PersonObject.makePerson;
@@ -24,6 +25,9 @@ public class RepliesAndTargetingExample 
     
     activity.writeTo(System.out);
     
+    System.out.println(isToMe().apply(activity));
+    System.out.println(isTo(makePerson().displayName("bob").get()).apply(activity));
+    
     /**
      * {"to":[
      *   {"displayName":"bob",



Mime
View raw message