From 49b878b1b0f2e52bbd5282c22ac32a68e1e8736c Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Tue, 8 Mar 2011 08:18:07 +0000 Subject: Change ATOM and RSS feed representations to use name value pairs instead of just strings, to allow support for all ATOM and RSS attributes and avoid confusion with non-feed string results. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1079292 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/tuscany/IterableUtil.java | 30 ++++++++++++++++++++++ sca-cpp/trunk/modules/java/test/ServerImpl.java | 16 +++++++----- 2 files changed, 40 insertions(+), 6 deletions(-) (limited to 'sca-cpp/trunk/modules/java') diff --git a/sca-cpp/trunk/modules/java/org/apache/tuscany/IterableUtil.java b/sca-cpp/trunk/modules/java/org/apache/tuscany/IterableUtil.java index 6d559f370a..2366d79af6 100644 --- a/sca-cpp/trunk/modules/java/org/apache/tuscany/IterableUtil.java +++ b/sca-cpp/trunk/modules/java/org/apache/tuscany/IterableUtil.java @@ -116,6 +116,13 @@ public class IterableUtil { return cdr(cdr(l)); } + /** + * Return the cdr of the cdr of the cdr of a list. + */ + public static Iterable cdddr(final Object l) { + return cdr(cdr(cdr(l))); + } + /** * Return the car of the cdr of the cdr of a list. */ @@ -124,6 +131,24 @@ public class IterableUtil { return (T)car(cddr(l)); } + /** + * Return the car of the cdr of the cdr of the cdr of a list. + */ + @SuppressWarnings("unchecked") + public static T cadddr(final Object l) { + return (T)car(cdddr(l)); + } + + /** + * Appends a list and another list. + */ + @SuppressWarnings("unchecked") + public static Iterable append(final Object a, final Object b) { + if (isNil(a)) + return (Iterable)b; + return cons(car(a), append(cdr(a), b)); + } + /** * Return the first pair matching a key from a list of key value pairs. */ @@ -352,6 +377,11 @@ public class IterableUtil { assert car(al) == Integer.valueOf(1); assert cadr(al) == Integer.valueOf(2); assert caddr(al) == Integer.valueOf(3); + + final Iterable a = list(0, 1, 2); + final Iterable b = list(3, 4); + final Iterable ab = append(a, b); + assert ab.toString().equals("[0, 1, 2, 3, 4]"); return true; } } diff --git a/sca-cpp/trunk/modules/java/test/ServerImpl.java b/sca-cpp/trunk/modules/java/test/ServerImpl.java index 9de68fdb75..ee25cf7bf8 100644 --- a/sca-cpp/trunk/modules/java/test/ServerImpl.java +++ b/sca-cpp/trunk/modules/java/test/ServerImpl.java @@ -29,12 +29,16 @@ public class ServerImpl { public Iterable get(final Iterable id) { if (isNil(id)) - return list("Sample Feed", "123456789", - list("Item", "111", list(list("'name", "Apple"), list("'currencyCode", "USD"), list("'currencySymbol", "$"), list("'price", 2.99))), - list("Item", "222", list(list("'name", "Orange"), list("'currencyCode", "USD"), list("'currencySymbol", "$"), list("'price", 3.55))), - list("Item", "333", list(list("'name", "Pear"), list("'currencyCode", "USD"), list("'currencySymbol", "$"), list("'price", 1.55)))); - final Iterable entry = list(list("'name", "Apple"), list("'currencyCode", "USD"), list("'currencySymbol", "$"), list("'price", 2.99)); - return list("Item", car(id), entry); + return list(list("'feed", list("'title", "Sample Feed"), list("'id", "123456789"), list("'entry", list( + list(list("'title", "Item"), list("'id", "111"), + list("'content", list("'item", list("'name", "Apple"), list("'currencyCode", "USD"), list("'currencySymbol", "$"), list("'price", 2.99)))), + list(list("'title", "Item"), list("'id", "222"), + list("'content", list("'item", list("'name", "Orange"), list("'currencyCode", "USD"), list("'currencySymbol", "$"), list("'price", 3.55)))), + list(list("'title", "Item"), list("'id", "333"), + list("'content", list("'item", list("'name", "Pear"), list("'currencyCode", "USD"), list("'currencySymbol", "$"), list("'price", 1.55)))))))); + + final Iterable content = list("'content", list("'item", list("'name", "Apple"), list("'currencyCode", "USD"), list("'currencySymbol", "$"), list("'price", 2.99))); + return list(list("'entry", list("'title", "Item"), list("'id", car(id)), content)); } public Iterable post(final Iterable collection, final Iterable item) { -- cgit v1.2.3