From 1099bc9633be66080426a8683b702c3739318fcb Mon Sep 17 00:00:00 2001 From: antelder Date: Tue, 17 May 2011 13:21:30 +0000 Subject: TUSCANY-3522: Commit the twitapp program Eranda Sooriyabandara has attached as part of the GSoC project Develop a 'NoSQL' Datastore component for Apache Cassandra, CouchDB, Hadoop/Hbase git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1104231 13f79535-47bb-0310-9956-ffa450edef68 --- collaboration/GSoC-2011-Eranda/twitapp/.classpath | 6 +++ collaboration/GSoC-2011-Eranda/twitapp/.project | 17 ++++++++ .../twitapp/.settings/org.eclipse.jdt.core.prefs | 12 ++++++ .../src/main/java/twitapp/services/AppManager.java | 39 +++++++++++++++++ .../src/main/java/twitapp/services/Twit.java | 23 ++++++++++ .../src/main/java/twitapp/services/User.java | 49 ++++++++++++++++++++++ .../src/main/java/twitapp/services/UserBase.java | 21 ++++++++++ .../main/java/twitapp/services/UserManager.java | 18 ++++++++ .../src/main/java/twitapp/test/TwitAppTest.java | 32 ++++++++++++++ 9 files changed, 217 insertions(+) create mode 100644 collaboration/GSoC-2011-Eranda/twitapp/.classpath create mode 100644 collaboration/GSoC-2011-Eranda/twitapp/.project create mode 100644 collaboration/GSoC-2011-Eranda/twitapp/.settings/org.eclipse.jdt.core.prefs create mode 100644 collaboration/GSoC-2011-Eranda/twitapp/src/main/java/twitapp/services/AppManager.java create mode 100644 collaboration/GSoC-2011-Eranda/twitapp/src/main/java/twitapp/services/Twit.java create mode 100644 collaboration/GSoC-2011-Eranda/twitapp/src/main/java/twitapp/services/User.java create mode 100644 collaboration/GSoC-2011-Eranda/twitapp/src/main/java/twitapp/services/UserBase.java create mode 100644 collaboration/GSoC-2011-Eranda/twitapp/src/main/java/twitapp/services/UserManager.java create mode 100644 collaboration/GSoC-2011-Eranda/twitapp/src/main/java/twitapp/test/TwitAppTest.java (limited to 'collaboration') diff --git a/collaboration/GSoC-2011-Eranda/twitapp/.classpath b/collaboration/GSoC-2011-Eranda/twitapp/.classpath new file mode 100644 index 0000000000..07ca123c63 --- /dev/null +++ b/collaboration/GSoC-2011-Eranda/twitapp/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/collaboration/GSoC-2011-Eranda/twitapp/.project b/collaboration/GSoC-2011-Eranda/twitapp/.project new file mode 100644 index 0000000000..e93020151b --- /dev/null +++ b/collaboration/GSoC-2011-Eranda/twitapp/.project @@ -0,0 +1,17 @@ + + + twitapp + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/collaboration/GSoC-2011-Eranda/twitapp/.settings/org.eclipse.jdt.core.prefs b/collaboration/GSoC-2011-Eranda/twitapp/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..1095552bb6 --- /dev/null +++ b/collaboration/GSoC-2011-Eranda/twitapp/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +#Fri May 13 10:53:56 IST 2011 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/collaboration/GSoC-2011-Eranda/twitapp/src/main/java/twitapp/services/AppManager.java b/collaboration/GSoC-2011-Eranda/twitapp/src/main/java/twitapp/services/AppManager.java new file mode 100644 index 0000000000..0ce20feeba --- /dev/null +++ b/collaboration/GSoC-2011-Eranda/twitapp/src/main/java/twitapp/services/AppManager.java @@ -0,0 +1,39 @@ +package main.java.twitapp.services; + +import java.util.ArrayList; +import java.util.Iterator; + +public class AppManager { + + private User user; + private UserBase userBase; + + public AppManager(String userId){ + userBase = UserBase.getInstance(); + user = userBase.get(userId); + } + + public void twit(String twit){ + user.setTwit(new Twit(twit)); + } + + public void follow(String followId){ + user.setFollower(userBase.get(followId)); + } + + public Iterator getFollowers(){ + ArrayList users = user.getFollowers(); + return users.iterator(); + } + + public Iterator getTwits(){ + ArrayList twits = user.getTwits(); + return twits.iterator(); + } + + public Iterator getFollowerTwits(String followeId){ + ArrayList followerTwits= userBase.get(followeId).getTwits(); + return followerTwits.iterator(); + } + +} diff --git a/collaboration/GSoC-2011-Eranda/twitapp/src/main/java/twitapp/services/Twit.java b/collaboration/GSoC-2011-Eranda/twitapp/src/main/java/twitapp/services/Twit.java new file mode 100644 index 0000000000..ec842d65e5 --- /dev/null +++ b/collaboration/GSoC-2011-Eranda/twitapp/src/main/java/twitapp/services/Twit.java @@ -0,0 +1,23 @@ +package main.java.twitapp.services; + +import java.util.Date; + +public class Twit { + + private String twit; + private final Date timestamp; + + public Twit(String twit){ + this.twit = twit; + timestamp = new Date(); + } + + public String toString(){ + return twit; + } + + public Date getTimestamp(){ + return timestamp; + } + +} diff --git a/collaboration/GSoC-2011-Eranda/twitapp/src/main/java/twitapp/services/User.java b/collaboration/GSoC-2011-Eranda/twitapp/src/main/java/twitapp/services/User.java new file mode 100644 index 0000000000..cd113db443 --- /dev/null +++ b/collaboration/GSoC-2011-Eranda/twitapp/src/main/java/twitapp/services/User.java @@ -0,0 +1,49 @@ +package main.java.twitapp.services; + +import java.util.ArrayList; +import java.util.Date; +import java.util.Iterator; + +public class User { + + private String name; + private ArrayList followers = new ArrayList(); + private ArrayList twits = new ArrayList(); + + public User(String name){ + this.name = name; + } + + public String getName() { + return name; + } + + public void setFollower(User follower){ + followers.add(follower); + } + + public ArrayList getFollowers(){ + return followers; + } + + public void setTwit(Twit twit){ + twits.add(twit); + } + + public ArrayList getTwits(){ + return twits; + } + + public ArrayList getTwits(Date date){ + Iterator t = twits.iterator(); + ArrayList newer = new ArrayList(); + Twit tt; + while((tt = t.next())!=null){ + if(tt.getTimestamp().after(date)){ + newer.add(tt); + } + } + return newer; + } + +} diff --git a/collaboration/GSoC-2011-Eranda/twitapp/src/main/java/twitapp/services/UserBase.java b/collaboration/GSoC-2011-Eranda/twitapp/src/main/java/twitapp/services/UserBase.java new file mode 100644 index 0000000000..046f0701f8 --- /dev/null +++ b/collaboration/GSoC-2011-Eranda/twitapp/src/main/java/twitapp/services/UserBase.java @@ -0,0 +1,21 @@ +package main.java.twitapp.services; + +import java.util.HashMap; + +public class UserBase extends HashMap { + + /** + * + */ + private static final long serialVersionUID = 1L; + private static UserBase userBase = new UserBase(); + + private UserBase(){ + } + + public static UserBase getInstance(){ + return userBase; + } + + +} diff --git a/collaboration/GSoC-2011-Eranda/twitapp/src/main/java/twitapp/services/UserManager.java b/collaboration/GSoC-2011-Eranda/twitapp/src/main/java/twitapp/services/UserManager.java new file mode 100644 index 0000000000..cfae0353bd --- /dev/null +++ b/collaboration/GSoC-2011-Eranda/twitapp/src/main/java/twitapp/services/UserManager.java @@ -0,0 +1,18 @@ +package main.java.twitapp.services; + +public class UserManager { + + UserBase userBase; + + public UserManager(){ + userBase = UserBase.getInstance(); + } + + public void addUser(String userId,String name){ + userBase.put(userId, new User(name)); + } + + public void removeUser(String userId){ + userBase.remove(userId); + } +} diff --git a/collaboration/GSoC-2011-Eranda/twitapp/src/main/java/twitapp/test/TwitAppTest.java b/collaboration/GSoC-2011-Eranda/twitapp/src/main/java/twitapp/test/TwitAppTest.java new file mode 100644 index 0000000000..f9d6baec8b --- /dev/null +++ b/collaboration/GSoC-2011-Eranda/twitapp/src/main/java/twitapp/test/TwitAppTest.java @@ -0,0 +1,32 @@ +package main.java.twitapp.test; + +import java.util.Iterator; + +import main.java.twitapp.services.AppManager; +import main.java.twitapp.services.Twit; +import main.java.twitapp.services.UserManager; + +public class TwitAppTest { + + /** + * @param args + */ + public static void main(String[] args) { + UserManager userManager = new UserManager(); + userManager.addUser("eranda", "Eranda Sooriyabandara"); + userManager.addUser("ishara", "Ishara Karunarathne"); + + AppManager manager1 = new AppManager("eranda"); + manager1.twit("Won the world cup 2011"); + + AppManager manager2 = new AppManager("ishara"); + manager2.follow("eranda"); + + Iterator twits = manager2.getFollowerTwits("eranda"); + while(twits.hasNext()){ + System.out.println(twits.next().toString()); + } + + } + +} -- cgit v1.2.3