Biblioteca Java - Rev 18
Subversion Repositories:
(root)/Frameworks and Technologies/Neo4J Samples/Neo4JTutorial/src/main/java/com/linkscreens/graphsin/network/Test.java @ 24
package com.linkscreens.graphsin.network;
import java.util.ArrayList;
import java.util.Iterator;
import org.neo4j.helpers.collection.IteratorUtil;
import com.linkscreens.graphsin.model.*;
import com.linkscreens.graphsin.repository.SocNet;
public class Test {
public static void main(String[] args) throws Exception {
SocialNetworkServiceImpl net = new SocialNetworkServiceImpl("d://temp//_socnet4");
SocialNetworkTestUtils utils = new SocialNetworkTestUtils();
utils.populate(net);
for(int i=0;i<1;i++){
T t = new T(net,utils);
t.start();
}
}
}
class T extends Thread{
SocialNetworkService net;
SocialNetworkTestUtils utils;
T(SocialNetworkService n,SocialNetworkTestUtils u){net = n;utils = u;}
public void run(){
long t = System.currentTimeMillis();
String p = utils.getRandomPersonWithFriends();
/*ArrayList list = net.getAllPersons();
System.out.println(">>>>Get all persons in "+(t - System.currentTimeMillis()));
t = System.currentTimeMillis();
String reco = net.getFriendRecommandation(p);
System.out.println("Recommandation for person :"+p+" is "+reco);
System.out.println(this.getName()+">>>>Get friend recommandation in "+(t - System.currentTimeMillis()));
t = System.currentTimeMillis();
System.out.println("Friends of :"+reco);
list = net.getFriendsOf(reco);
//net.displayCollection(list);
System.out.println(this.getName()+">>>>Get friends of in"+(t - System.currentTimeMillis()));
*/
t = System.currentTimeMillis();
p = utils.getRandomPersonWithFriends();
System.out.println(this.getName()+"Status updates for "+p+" :");
ArrayList<StatusUpdate> sups = null;
try {
sups = net.retrieveFriendsStatusUpdates(p);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(this.getName()+">>>>Get status updates in "+(t - System.currentTimeMillis()));
//net.displayCollection(sups);
String name = utils.getRandomPersonWithFriends();
System.out.println("List of media albums for user "+name);
ArrayList<Album> albums = net.retreivePersonMediaAlbums(name);
displayCollection(albums);
//show comments on all media items in each person albums
System.out.println("Show comments on all media items in each person albums.");
for(Album album:albums){
ArrayList<MediaItem> items = net.getMediaItems(album.getId());
System.out.println("Media items of album:"+album.getId()+" are:");
displayCollection(items);
for(MediaItem itemid:items){
System.out.println("Comments of media item "+itemid+" are:");
displayCollection(
net.getMediaItemComments(itemid.getId())
);
}
}
}
private <T> ArrayList<T> fromIterableToArrayList( Iterator<T> iterable )
{
ArrayList<T> collection = new ArrayList<>();
IteratorUtil.addToCollection( iterable, collection );
return collection;
}
public void displayCollection(ArrayList list){
for (Iterator iterator = list.iterator(); iterator.hasNext();) {
System.out.println(iterator.next().toString());
}
}
}
import java.util.ArrayList;
import java.util.Iterator;
import org.neo4j.helpers.collection.IteratorUtil;
import com.linkscreens.graphsin.model.*;
import com.linkscreens.graphsin.repository.SocNet;
public class Test {
public static void main(String[] args) throws Exception {
SocialNetworkServiceImpl net = new SocialNetworkServiceImpl("d://temp//_socnet4");
SocialNetworkTestUtils utils = new SocialNetworkTestUtils();
utils.populate(net);
for(int i=0;i<1;i++){
T t = new T(net,utils);
t.start();
}
}
}
class T extends Thread{
SocialNetworkService net;
SocialNetworkTestUtils utils;
T(SocialNetworkService n,SocialNetworkTestUtils u){net = n;utils = u;}
public void run(){
long t = System.currentTimeMillis();
String p = utils.getRandomPersonWithFriends();
/*ArrayList list = net.getAllPersons();
System.out.println(">>>>Get all persons in "+(t - System.currentTimeMillis()));
t = System.currentTimeMillis();
String reco = net.getFriendRecommandation(p);
System.out.println("Recommandation for person :"+p+" is "+reco);
System.out.println(this.getName()+">>>>Get friend recommandation in "+(t - System.currentTimeMillis()));
t = System.currentTimeMillis();
System.out.println("Friends of :"+reco);
list = net.getFriendsOf(reco);
//net.displayCollection(list);
System.out.println(this.getName()+">>>>Get friends of in"+(t - System.currentTimeMillis()));
*/
t = System.currentTimeMillis();
p = utils.getRandomPersonWithFriends();
System.out.println(this.getName()+"Status updates for "+p+" :");
ArrayList<StatusUpdate> sups = null;
try {
sups = net.retrieveFriendsStatusUpdates(p);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(this.getName()+">>>>Get status updates in "+(t - System.currentTimeMillis()));
//net.displayCollection(sups);
String name = utils.getRandomPersonWithFriends();
System.out.println("List of media albums for user "+name);
ArrayList<Album> albums = net.retreivePersonMediaAlbums(name);
displayCollection(albums);
//show comments on all media items in each person albums
System.out.println("Show comments on all media items in each person albums.");
for(Album album:albums){
ArrayList<MediaItem> items = net.getMediaItems(album.getId());
System.out.println("Media items of album:"+album.getId()+" are:");
displayCollection(items);
for(MediaItem itemid:items){
System.out.println("Comments of media item "+itemid+" are:");
displayCollection(
net.getMediaItemComments(itemid.getId())
);
}
}
}
private <T> ArrayList<T> fromIterableToArrayList( Iterator<T> iterable )
{
ArrayList<T> collection = new ArrayList<>();
IteratorUtil.addToCollection( iterable, collection );
return collection;
}
public void displayCollection(ArrayList list){
for (Iterator iterator = list.iterator(); iterator.hasNext();) {
System.out.println(iterator.next().toString());
}
}
}