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
This commit is contained in:
parent
2189f061be
commit
1099bc9633
9 changed files with 217 additions and 0 deletions
6
collaboration/GSoC-2011-Eranda/twitapp/.classpath
Normal file
6
collaboration/GSoC-2011-Eranda/twitapp/.classpath
Normal file
|
@ -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>
|
17
collaboration/GSoC-2011-Eranda/twitapp/.project
Normal file
17
collaboration/GSoC-2011-Eranda/twitapp/.project
Normal file
|
@ -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>
|
|
@ -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
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue