Biblioteca Java - Blame information for rev 18
Subversion Repositories:
(root)/Frameworks and Technologies/Neo4J Samples/Neo4JTutorial/src/main/java/com/linkscreens/graphsin/network/Test.java
Rev | Author | Line No. | Line |
---|---|---|---|
18 | mihai | 1 | package com.linkscreens.graphsin.network; |
2 | |||
3 | import java.util.ArrayList; | ||
4 | import java.util.Iterator; | ||
5 | |||
6 | import org.neo4j.helpers.collection.IteratorUtil; | ||
7 | |||
8 | import com.linkscreens.graphsin.model.*; | ||
9 | import com.linkscreens.graphsin.repository.SocNet; | ||
10 | |||
11 | |||
12 | public class Test { | ||
13 | public static void main(String[] args) throws Exception { | ||
14 | SocialNetworkServiceImpl net = new SocialNetworkServiceImpl("d://temp//_socnet4"); | ||
15 | SocialNetworkTestUtils utils = new SocialNetworkTestUtils(); | ||
16 | utils.populate(net); | ||
17 | |||
18 | for(int i=0;i<1;i++){ | ||
19 | T t = new T(net,utils); | ||
20 | t.start(); | ||
21 | } | ||
22 | } | ||
23 | } | ||
24 | |||
25 | class T extends Thread{ | ||
26 | |||
27 | SocialNetworkService net; | ||
28 | SocialNetworkTestUtils utils; | ||
29 | |||
30 | T(SocialNetworkService n,SocialNetworkTestUtils u){net = n;utils = u;} | ||
31 | |||
32 | public void run(){ | ||
33 | long t = System.currentTimeMillis(); | ||
34 | String p = utils.getRandomPersonWithFriends(); | ||
35 | |||
36 | /*ArrayList list = net.getAllPersons(); | ||
37 | |||
38 | System.out.println(">>>>Get all persons in "+(t - System.currentTimeMillis())); | ||
39 | t = System.currentTimeMillis(); | ||
40 | String reco = net.getFriendRecommandation(p); | ||
41 | System.out.println("Recommandation for person :"+p+" is "+reco); | ||
42 | System.out.println(this.getName()+">>>>Get friend recommandation in "+(t - System.currentTimeMillis())); | ||
43 | |||
44 | t = System.currentTimeMillis(); | ||
45 | System.out.println("Friends of :"+reco); | ||
46 | list = net.getFriendsOf(reco); | ||
47 | //net.displayCollection(list); | ||
48 | System.out.println(this.getName()+">>>>Get friends of in"+(t - System.currentTimeMillis())); | ||
49 | */ | ||
50 | t = System.currentTimeMillis(); | ||
51 | p = utils.getRandomPersonWithFriends(); | ||
52 | System.out.println(this.getName()+"Status updates for "+p+" :"); | ||
53 | |||
54 | ArrayList<StatusUpdate> sups = null; | ||
55 | try { | ||
56 | sups = net.retrieveFriendsStatusUpdates(p); | ||
57 | } catch (Exception e) { | ||
58 | // TODO Auto-generated catch block | ||
59 | e.printStackTrace(); | ||
60 | } | ||
61 | System.out.println(this.getName()+">>>>Get status updates in "+(t - System.currentTimeMillis())); | ||
62 | //net.displayCollection(sups); | ||
63 | |||
64 | |||
65 | |||
66 | String name = utils.getRandomPersonWithFriends(); | ||
67 | System.out.println("List of media albums for user "+name); | ||
68 | ArrayList<Album> albums = net.retreivePersonMediaAlbums(name); | ||
69 | displayCollection(albums); | ||
70 | |||
71 | //show comments on all media items in each person albums | ||
72 | System.out.println("Show comments on all media items in each person albums."); | ||
73 | for(Album album:albums){ | ||
74 | ArrayList<MediaItem> items = net.getMediaItems(album.getId()); | ||
75 | System.out.println("Media items of album:"+album.getId()+" are:"); | ||
76 | displayCollection(items); | ||
77 | for(MediaItem itemid:items){ | ||
78 | System.out.println("Comments of media item "+itemid+" are:"); | ||
79 | displayCollection( | ||
80 | net.getMediaItemComments(itemid.getId()) | ||
81 | ); | ||
82 | |||
83 | } | ||
84 | } | ||
85 | |||
86 | } | ||
87 | |||
88 | private <T> ArrayList<T> fromIterableToArrayList( Iterator<T> iterable ) | ||
89 | { | ||
90 | ArrayList<T> collection = new ArrayList<>(); | ||
91 | IteratorUtil.addToCollection( iterable, collection ); | ||
92 | return collection; | ||
93 | } | ||
94 | |||
95 | public void displayCollection(ArrayList list){ | ||
96 | for (Iterator iterator = list.iterator(); iterator.hasNext();) { | ||
97 | System.out.println(iterator.next().toString()); | ||
98 | } | ||
99 | } | ||
100 | } | ||
101 | |||
102 |