Mercurial > hg > Members > nobuyasu > Consensus
view app/models/NodeModel.java @ 131:2b6e9496fb0c draft default tip
modified updateUserConsensusStatus
author | one |
---|---|
date | Fri, 26 Apr 2013 02:47:01 +0900 |
parents | 52b0c88a0b1b |
children |
line wrap: on
line source
package models; import java.util.ArrayList; import java.util.HashMap; import com.tinkerpop.blueprints.Direction; import com.tinkerpop.blueprints.Edge; import com.tinkerpop.blueprints.Vertex; import com.tinkerpop.gremlin.java.GremlinPipeline; public class NodeModel { protected Vertex vertex; protected Object id; protected HashMap<Object, Object> properties = new HashMap<Object, Object>(); public static final String ID = "id"; public static final String TYPE = "type"; public static final String MENTIONS = "mentions"; public static final String TIMESTAMP = "timestamp"; /* * Edge Labels. */ public static final String L_AUTHOR = "author"; public static final String L_REQUEST = "request"; public static final String L_QUESTION = "question"; public static final String L_REFUTATION = "refutation"; public static final String L_SUGGESTION = "suggestion"; public static final String L_PREV = "prev"; public static final String MAJORITY = "majority"; public static final String UNANIMOUSLY = "unanimously"; /* * Claim information key. */ public static final String TOULMIN = "toulmin"; public static final String TITLE = "title"; public static final String CONTENTS = "contents"; public static final String QUALIFIER = "q"; public static final String DATA = "d"; public static final String WARRANT = "w"; public static final String BACKING = "b"; public static final String REBUTTLE = "r"; public static final String USERS = "users"; public static final String STATUS = "status"; // Status statement public static final String PASSED = "passed"; public static final String FAILED = "failed"; public static final String AGREED = "agreed"; public static final String DENIED = "denied"; public static final String UNKNOWN = "unknown"; public static final String PEND = "pend"; // Use This key Json Data public static final String CLAIM = "claim"; public static final String REQUESTS = "requests"; public static final String CONSENSUS = "consensus"; public NodeModel(Vertex vertex) { this.vertex = vertex; if (vertex == null) { this.id = null; } else { this.id = vertex.getId(); } } public void setId(Object id) { this.id = id; } public Object getId() { return this.id; } public Vertex getVertex() { return this.vertex; } public void setProperty(String key, Object value) { this.vertex.setProperty(key, value); } public Object getProperty(String key) { return this.vertex.getProperty(key); } public HashMap<Object, Object> getAllProperty() { for (String key : vertex.getPropertyKeys()) { properties.put(key, vertex.getProperty(key)); } return properties; } protected Iterable<Vertex> getVertexIterable(Direction direction, String... labels) { GremlinPipeline<Vertex, Vertex> pipe = new GremlinPipeline<Vertex, Vertex>(); if (direction.equals(Direction.IN)) { pipe.start(vertex).in(labels); } else if (direction.equals(Direction.OUT)) { pipe.start(vertex).out(labels); } else { pipe.start(vertex).both(labels); } ArrayList<Vertex> array = new ArrayList<Vertex>(); for (Vertex v : pipe) { array.add(v); } if (array.size() == 0) { return null; } return array; } public Object[] getVertexIdArrayTraverseLabel(Direction direction, String... labels) { Iterable<Vertex> iter = getVertexIterable(direction, labels); if (iter == null) { return null; } ArrayList<Object> array = new ArrayList<Object>(); for (Vertex v : iter) { array.add(v.getId()); } return array.toArray(); } protected Iterable<Edge> getEdgeIterable(Direction direction, String... labels) { GremlinPipeline<Vertex, Edge> pipe = new GremlinPipeline<Vertex, Edge>(); if (direction.equals(Direction.IN)) { pipe.start(vertex).inE(labels); } else if (direction.equals(Direction.OUT)) { pipe.start(vertex).outE(labels); } else { pipe.start(vertex).bothE(labels); } ArrayList<Edge> array = new ArrayList<Edge>(); for (Edge v : pipe) { array.add(v); } if (array.size() == 0) { return null; } return array; } public Object[] getEdgeArray(Direction direction, String... labels) { Iterable<Edge> iter = getEdgeIterable(direction, labels); /* * GremlinPipeline<Vertex,Edge> pipe = new * GremlinPipeline<Vertex,Edge>(); pipe.start(vertex).outE(labels); */ ArrayList<Object> array = new ArrayList<Object>(); for (Edge e : iter) { array.add(e.getId()); } if (array.size() == 0) { return null; } return array.toArray(); } public Object[] getRequestEdges() { return getEdgeArray(Direction.OUT, L_REQUEST); } }