diff options
9 files changed, 217 insertions, 0 deletions
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 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
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 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>twitapp</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
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<User> getFollowers(){
+ ArrayList<User> users = user.getFollowers();
+ return users.iterator();
+ }
+
+ public Iterator<Twit> getTwits(){
+ ArrayList<Twit> twits = user.getTwits();
+ return twits.iterator();
+ }
+
+ public Iterator<Twit> getFollowerTwits(String followeId){
+ ArrayList<Twit> 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<User> followers = new ArrayList<User>();
+ private ArrayList<Twit> twits = new ArrayList<Twit>();
+
+ public User(String name){
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setFollower(User follower){
+ followers.add(follower);
+ }
+
+ public ArrayList<User> getFollowers(){
+ return followers;
+ }
+
+ public void setTwit(Twit twit){
+ twits.add(twit);
+ }
+
+ public ArrayList<Twit> getTwits(){
+ return twits;
+ }
+
+ public ArrayList<Twit> getTwits(Date date){
+ Iterator<Twit> t = twits.iterator();
+ ArrayList<Twit> newer = new ArrayList<Twit>();
+ 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<String, User> {
+
+ /**
+ *
+ */
+ 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<Twit> twits = manager2.getFollowerTwits("eranda");
+ while(twits.hasNext()){
+ System.out.println(twits.next().toString());
+ }
+
+ }
+
+}
|