Mercurial > hg > Members > nobuyasu > Consensus
annotate app/models/UserModel.java @ 45:0e8b6eda0a0e
commit
author | one |
---|---|
date | Thu, 04 Oct 2012 06:54:33 +0900 |
parents | f78442777849 |
children | c76b3b60eb18 |
rev | line source |
---|---|
7 | 1 package models; |
2 | |
20 | 3 import java.util.ArrayList; |
22 | 4 import java.util.HashMap; |
23 | 5 import java.util.HashSet; |
17 | 6 |
7 | 7 import com.tinkerpop.blueprints.Vertex; |
18 | 8 import com.tinkerpop.gremlin.java.GremlinPipeline; |
7 | 9 |
10 public class UserModel extends NodeModel { | |
8 | 11 |
7 | 12 |
13 public UserModel(Vertex vertex) { | |
14 super(vertex); | |
15 } | |
16 | |
18 | 17 private Object[] getEdgeInUser(String labels) { |
18 GremlinPipeline<Vertex,Vertex> pipe = new GremlinPipeline<Vertex,Vertex>(); | |
19 pipe.start(this.vertex).in(labels); | |
20 | 20 ArrayList<Object> array = new ArrayList<Object>(); |
21 for (Vertex v : pipe) { | |
22 array.add(v.getId()); | |
18 | 23 } |
20 | 24 if (array.size() == 0) return null; |
25 return array.toArray(); | |
9 | 26 } |
27 | |
18 | 28 public Object[] getUserRequests() { |
29 return getEdgeInUser(L_REQUEST); | |
30 } | |
31 | |
32 public Object[] getUserClaims() { | |
21 | 33 return getEdgeInUser(L_AUTHOR); |
10 | 34 } |
17 | 35 |
23 | 36 public HashSet<Object> getClaimsAndRequests() { |
24
81d1d7c7bcde
create getConsensus action. but this action can not test because there is no createMention action.
one
parents:
23
diff
changeset
|
37 Object[] requests = getUserRequests(); |
23 | 38 Object[] claims = getUserClaims(); |
24
81d1d7c7bcde
create getConsensus action. but this action can not test because there is no createMention action.
one
parents:
23
diff
changeset
|
39 return makeSet(requests, claims); |
81d1d7c7bcde
create getConsensus action. but this action can not test because there is no createMention action.
one
parents:
23
diff
changeset
|
40 } |
81d1d7c7bcde
create getConsensus action. but this action can not test because there is no createMention action.
one
parents:
23
diff
changeset
|
41 |
81d1d7c7bcde
create getConsensus action. but this action can not test because there is no createMention action.
one
parents:
23
diff
changeset
|
42 private HashSet<Object> makeSet(Object[] obj1, Object[] obj2) { |
23 | 43 HashSet<Object> set = new HashSet<Object>(); |
24
81d1d7c7bcde
create getConsensus action. but this action can not test because there is no createMention action.
one
parents:
23
diff
changeset
|
44 if (obj1 != null) |
81d1d7c7bcde
create getConsensus action. but this action can not test because there is no createMention action.
one
parents:
23
diff
changeset
|
45 for (Object o : obj1) set.add(o); |
81d1d7c7bcde
create getConsensus action. but this action can not test because there is no createMention action.
one
parents:
23
diff
changeset
|
46 if (obj2 != null) |
81d1d7c7bcde
create getConsensus action. but this action can not test because there is no createMention action.
one
parents:
23
diff
changeset
|
47 for (Object o : obj2) set.add(o); |
23 | 48 if (set.size() == 0) return null; |
49 return set; | |
24
81d1d7c7bcde
create getConsensus action. but this action can not test because there is no createMention action.
one
parents:
23
diff
changeset
|
50 } |
36 | 51 |
25 | 52 public HashMap<Object,Object[]> getUserInfo() { |
53 TPGraph tpGraph = TPGraph.getInstance(); | |
24
81d1d7c7bcde
create getConsensus action. but this action can not test because there is no createMention action.
one
parents:
23
diff
changeset
|
54 Object[] requests = getUserRequests(); |
81d1d7c7bcde
create getConsensus action. but this action can not test because there is no createMention action.
one
parents:
23
diff
changeset
|
55 Object[] claims = getUserClaims(); |
22 | 56 HashMap<Object,Object[]> hash = new HashMap<Object, Object[]>(); |
24
81d1d7c7bcde
create getConsensus action. but this action can not test because there is no createMention action.
one
parents:
23
diff
changeset
|
57 hash.put(NodeModel.REQUESTS, requests); |
32 | 58 hash.put(NodeModel.CLAIM, claims); |
24
81d1d7c7bcde
create getConsensus action. but this action can not test because there is no createMention action.
one
parents:
23
diff
changeset
|
59 HashSet<Object> set = makeSet(requests, claims); |
81d1d7c7bcde
create getConsensus action. but this action can not test because there is no createMention action.
one
parents:
23
diff
changeset
|
60 hash.put(NodeModel.CONSENSUS, tpGraph.checkConsensus(set)); |
22 | 61 return hash; |
62 } | |
10 | 63 |
7 | 64 } |