abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r1209600 - in /abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities: MapRedExample.java MiscellaneousExamples.java ReadingListExample.java VersionControlExample.java
Date Fri, 02 Dec 2011 17:40:44 GMT
Author: jmsnell
Date: Fri Dec  2 17:40:44 2011
New Revision: 1209600

URL: http://svn.apache.org/viewvc?rev=1209600&view=rev
Log:
Cleaning up some of the examples

Modified:
    abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/MapRedExample.java
    abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/MiscellaneousExamples.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/VersionControlExample.java

Modified: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/MapRedExample.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/MapRedExample.java?rev=1209600&r1=1209599&r2=1209600&view=diff
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/MapRedExample.java
(original)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/MapRedExample.java
Fri Dec  2 17:40:44 2011
@@ -86,7 +86,9 @@ public class MapRedExample {
         Iterable<Pair<Integer,Iterable<String>>>>futureFunction(f3,exec);
   
   public static void main(String... args) throws Exception {
-    // Read the Atom Feed
+    // Read an Atom Feed... this part isn't required.. the mapred stuff
+    // works on any activity stream source, this just gives us some 
+    // interesting input material
     Abdera abdera = Abdera.getInstance();
     URL url = new URL("http://planet.intertwingly.net/atom.xml");
     Parser parser = abdera.getParser();
@@ -97,19 +99,26 @@ public class MapRedExample {
     ByteArrayOutputStream out = new ByteArrayOutputStream();
     feed.writeTo("activity", out);
     
-    // Converted it to an Activity Stream
+    // Convert it to an Activity Stream
     String r = new String(out.toByteArray(),"UTF-8");
     Collection<Activity> col = IO.get().readCollection(new StringReader(r));
     
-    // Prepare the input data
+    // Prepare the input data.. here's where the interesting bit starts...
+    // this first step indexes the collection of activities into a Iterable 
+    // of Pair objects. A Pair object is essentially a tuple with two elements,
+    // called first() and second(). The first() is used as the key in the 
+    // Map function, while second() is used as the value. In this particular
+    // case, we're using a null key on the input...
     PairBuilder<Void,Activity> gen = 
       Pair.<Void,Activity>make()
-        .index(MoreFunctions.<Activity,Void>alwaysNull(), col.getItems());
+        .index(MoreFunctions.<Activity>alwaysVoid(), col.getItems());
         
     // The Function ff is asynchronous... we apply it, then call get on
-    // the returned Future to wait the result. The mapreduce operation
+    // the returned Future to wait for the result. The mapreduce operation
     // occurs in a different thread and sets the value of the Future 
-    // when it is complete
+    // when it is complete... once it does, we iterate through the collection
+    // of Pairs it kicks out.. which in this case, is a listing of actors 
+    // in the stream sorted by number of activities each.
     for (Pair<Integer,Iterable<String>> entry : ff.apply(gen).get())
       System.out.println(
         entry.first() + "=" + entry.second());

Modified: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/MiscellaneousExamples.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/MiscellaneousExamples.java?rev=1209600&r1=1209599&r2=1209600&view=diff
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/MiscellaneousExamples.java
(original)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/MiscellaneousExamples.java
Fri Dec  2 17:40:44 2011
@@ -56,7 +56,7 @@ public class MiscellaneousExamples {
     // All of the Activity objects are immutable thread-safe instances,
     // which means editing the data in an object is a bit more difficult 
     // that just calling a setter...
-    // support we want to add a property to one of the activities
+    // suppose we want to add a property to one of the activities
     // we created above... we can do so by using the activity as a template
     // for creating a new Activity object
     
@@ -81,7 +81,7 @@ public class MiscellaneousExamples {
     // the Google+ API specifies a "nextPageToken" property
     // within the root collection object that is used to
     // construct the URL for the next page in a paged 
-    // collection of stream documents. Using Misc.ASContext,
+    // collection of stream documents. Using ASContext,
     // it's a simple matter to pull that out and construct
     // the url for the next page.
     
@@ -97,7 +97,6 @@ public class MiscellaneousExamples {
       template.expand(
         new ASContext(collection)));
     
-    
   }
   
 }

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=1209600&r1=1209599&r2=1209600&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
Fri Dec  2 17:40:44 2011
@@ -2,7 +2,7 @@ package org.apache.abdera2.examples.acti
 
 import org.apache.abdera2.activities.model.Activity;
 import org.apache.abdera2.activities.model.Activity.ActivityBuilder;
-import org.apache.abdera2.activities.model.Collection.CollectionBuilder;
+import org.apache.abdera2.activities.model.Collection;
 import org.apache.abdera2.activities.model.IO;
 
 import static org.apache.abdera2.activities.model.Verb.SAVE;
@@ -12,7 +12,6 @@ import static org.apache.abdera2.activit
 import static org.apache.abdera2.activities.model.Activity.makeActivity;
 import static org.apache.abdera2.activities.model.objects.BookObject.makeBook;
 import static org.apache.abdera2.activities.model.objects.PersonObject.makePerson;
-import static org.apache.abdera2.activities.model.Collection.makeCollection;
 
 /**
  * Example that shows a simple practical use of an activity stream
@@ -28,41 +27,32 @@ public class ReadingListExample {
     // Building an activity stream for a reading list
     IO io = IO.get();
     
-    ActivityBuilder gen = 
+    ActivityBuilder a = 
       makeActivity()
-        .actor(
-          makePerson()
-            .displayName("James")
-            .get());
-
-    CollectionBuilder<Activity> builder = 
-      makeCollection();
+        .actor(makePerson("James"));
+ 
+    Collection.<Activity>makeCollection()
     
     // Add a book we want to read
-    builder.item(
-      gen.template()
-         .set("verb", SAVE)
-         .set("object", 
-           makeBook()
-             .displayName("The Cat in the Hat")
-             .get())
-         .set("format", EBOOK())
-         .get());
+    .item(
+      a.template()
+       .set("verb", SAVE)
+       .set("object", 
+         makeBook()
+           .displayName("The Cat in the Hat"))
+       .set("format", EBOOK))
     
     // Add a book we just finished
-    builder.item(
-      gen.template()
-         .set("verb", CONSUME)
-         .set("object", 
-           makeBook()
-             .displayName("Meditations on the Method")
-             .author(
-               makePerson("Rene Descartes").get())
-             .get())
-         .set("format", HARDCOVER())
-         .get());
+    .item(
+      a.template()
+       .set("verb", CONSUME)
+       .set("object", 
+         makeBook()
+           .displayName("Meditations on the Method")
+           .author(makePerson("Rene Descartes")))
+       .set("format", HARDCOVER))
     
-    builder.get().writeTo(io,System.out);
+    .get().writeTo(io,System.out);
     
   }
   

Modified: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/VersionControlExample.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/VersionControlExample.java?rev=1209600&r1=1209599&r2=1209600&view=diff
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/VersionControlExample.java
(original)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/VersionControlExample.java
Fri Dec  2 17:40:44 2011
@@ -39,7 +39,8 @@ public class VersionControlExample {
     // first, indicate that we created a document
     FileObject file = 
       makeFile()
-        .id("http://example.org/presentation.ppt")
+        .id("urn:example:file/presentation")
+        .fileUrl("http://example.org/presentation.ppt")
         .displayName("presentation.ppt")
         .get();
     
@@ -103,8 +104,8 @@ public class VersionControlExample {
     {
       "verb":"post",
       "object": {
-
-        "id":"http://example.org/presentation.ppt",
+        "id":"urn:example:file/presentation",
+        "fileUrl":"http://example.org/presentation.ppt",
         "displayName":"presentation.ppt",
         "objectType":"file"},
       "actor":{
@@ -117,7 +118,8 @@ public class VersionControlExample {
       "verb":"post",
       "object":{
         "of":{
-          "id":"http://example.org/presentation.ppt",
+          "id":"urn:example:file/presentation",
+          "fileUrl":"http://example.org/presentation.ppt",
           "displayName":"presentation.ppt",
           "objectType":"file"},
         "objectType":"version",
@@ -131,7 +133,8 @@ public class VersionControlExample {
       "verb":"reject",
       "object":{
         "of":{
-          "id":"http://example.org/presentation.ppt",
+          "id":"urn:example:file/presentation",
+          "fileUrl":"http://example.org/presentation.ppt",
           "displayName":"presentation.ppt",
           "objectType":"file"},
         "objectType":"version",
@@ -144,12 +147,14 @@ public class VersionControlExample {
       "verb":"post",
       "object":{
         "of":{
-          "id":"http://example.org/presentation.ppt",
+          "id":"urn:example:file/presentation",
+          "fileUrl":"http://example.org/presentation.ppt",
           "displayName":"presentation.ppt",
           "objectType":"file"},
         "previousVersion":{
           "of":{
-            "id":"http://example.org/presentation.ppt",
+            "id":"urn:example:file/presentation",
+            "fileUrl":"http://example.org/presentation.ppt",
             "displayName":"presentation.ppt",
             "objectType":"file"},
           "objectType":"version",
@@ -164,12 +169,14 @@ public class VersionControlExample {
       "verb":"approve",
       "object":{
         "of":{
-          "id":"http://example.org/presentation.ppt",
+          "id":"urn:example:file/presentation",
+          "fileUrl":"http://example.org/presentation.ppt",
           "displayName":"presentation.ppt",
           "objectType":"file"},
         "previousVersion":{
           "of":{
-            "id":"http://example.org/presentation.ppt", 
+            "id":"urn:example:file/presentation",
+            "fileUrl":"http://example.org/presentation.ppt", 
             "displayName":"presentation.ppt",
             "objectType":"file"},
           "objectType":"version",



Mime
View raw message