本文整理汇总了Java中org.apache.tinkerpop.gremlin.structure.T类的典型用法代码示例。如果您正苦于以下问题:Java T类的具体用法?Java T怎么用?Java T使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
T类属于org.apache.tinkerpop.gremlin.structure包,在下文中一共展示了T类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: apply
import org.apache.tinkerpop.gremlin.structure.T; //导入依赖的package包/类
@Override
@SneakyThrows
public GraphTraversal<Element, Element> apply(GraphTraversalSource g) {
GraphTraversal traversal = g.addV(element.label());
if (element.id() != null && HasFeature.Verifier.of(g)
.verify(supportsUserSuppliedIds(element))) {
traversal.property(T.id, element.id());
}
for (Field field : keyFields(element)) {
String key = propertyKey(field);
Object value = propertyValue(field, element);
if (isMissing(value)) {
throw org.apache.tinkerpop.gremlin.object.structure.Element.Exceptions.requiredKeysMissing(
element.getClass(), key);
}
traversal.property(key, value);
}
return traversal;
}
示例2: insert
import org.apache.tinkerpop.gremlin.structure.T; //导入依赖的package包/类
protected org.apache.tinkerpop.gremlin.structure.Vertex insert(Vertex vertex) {
try {
org.apache.tinkerpop.gremlin.structure.Vertex delegate;
if (useGraph(vertex)) {
Object vertexId = maybeSupplyId(vertex);
delegate = g.getGraph().addVertex(
vertexId != null ? simple(vertex, T.id, T.label) : simple(vertex, T.label));
update(delegate, vertex, Properties::complex);
} else {
delegate = complete(hasPrimaryKeys(vertex) ? g.inject(1).coalesce(
check(vertex), create(vertex)) : create(vertex));
}
return delegate;
} catch (Exception e) {
log.warn("The vertex {} already exists", vertex);
throw Element.Exceptions.elementAlreadyExists(vertex);
}
}
示例3: id
import org.apache.tinkerpop.gremlin.structure.T; //导入依赖的package包/类
/**
* Supply an id for the given element, in terms of a {@link Map} that contains its label, and all
* of it's {@link PrimaryKey} and {@link OrderingKey}s.
*/
@SneakyThrows
@SuppressWarnings("PMD.ShortMethodName")
public static <E extends Element> Object id(E element) {
if (element == null) {
return null;
}
Object elementId = element.id();
if (elementId != null) {
return elementId;
}
Map<String, Object> mappedId = new HashMap<>();
if (isVertex(element)) {
mappedId.put(T.label.getAccessor(), element.label());
}
Consumer<Field> addKey = field -> {
Object propertyValue = propertyValue(field, element);
if (isMissing(propertyValue)) {
throw Element.Exceptions.requiredKeysMissing(element.getClass(), propertyKey(field));
}
mappedId.put(propertyKey(field), propertyValue);
};
primaryKeyFields(element).forEach(addKey);
orderingKeyFields(element).forEach(addKey);
return mappedId.isEmpty() ? null : mappedId;
}
示例4: all
import org.apache.tinkerpop.gremlin.structure.T; //导入依赖的package包/类
/**
* Get the key value array of fields of the element that match the given predicate, including the
* given system properties.
*/
@SuppressWarnings({"PMD.ShortMethodName"})
public static <E extends Element> Object[] all(E element, Predicate<Field> predicate, T... ts) {
List<Object> properties = new ArrayList<>();
for (T t : ts) {
switch (t) {
case id:
if (element.id() != null) {
properties.add(T.id);
properties.add(element.id());
}
break;
case label:
properties.add(T.label);
properties.add(element.label());
break;
default:
break;
}
}
properties.addAll(some(element, predicate));
return properties.toArray(new Object[] {});
}
示例5: testDetermineCurrentLocation
import org.apache.tinkerpop.gremlin.structure.T; //导入依赖的package包/类
@Test
public void testDetermineCurrentLocation() {
TheCrew crew = TheCrew.of(graph);
Selections selections = query
.by(g -> g.V().as("a").
properties("locations").as("b").
hasNot("endTime").as("c").
order().by("startTime").
select("a", "b", "c").by("name").by(T.value).by("startTime").dedup())
.as("a", String.class)
.as("b", String.class)
.as("c", Instant.class)
.select();
assertNotNull(selections);
assertEquals(Selections.of(
Selection.of().add("a", crew.marko.name()).add("b", "santa fe").add("c", year(2005)),
Selection.of().add("a", crew.stephen.name()).add("b", "purcellville")
.add("c", year(2006)),
Selection.of().add("a", crew.daniel.name()).add("b", "aachen").add("c", year(2009)),
Selection.of().add("a", crew.matthias.name()).add("b", "seattle").add("c", year(2014))
), selections);
}
示例6: create
import org.apache.tinkerpop.gremlin.structure.T; //导入依赖的package包/类
public User create(User user) throws Exception {
// Must first create the person and then create its wishList
String password = user.getPassword();
if (StringUtils.isNotBlank(password)) {
final byte[] salt = new byte[SALT_LENGTH];
final byte[] passwordHash = createSaltThenComputePasswordHash(salt, password);
return graphUtils.doInGraphTransaction(graph -> {
Vertex reactionVertex = graph.addVertex(
T.label, "User",
"login", user.getLogin(),
"email", user.getEmail(),
"passwordHash", passwordHash,
"salt", salt,
"creationDate", new Date());
graphUtils.getRoot(graph).addEdge("created", reactionVertex);
user.setId(graphUtils.getStringVertexId(reactionVertex, graph));
return user;
});
} else {
throw new IllegalArgumentException("The given user must define a password");
}
}
示例7: createByReactionReactingToReactionId
import org.apache.tinkerpop.gremlin.structure.T; //导入依赖的package包/类
public Reaction createByReactionReactingToReactionId(Reaction reaction, final String reactToReactionId) throws Exception {
if (reactToReactionId == null) {
return create(reaction);
} else {
return graphUtils.doInGraphTransaction(graph -> {
Vertex reactionVertex = graph.addVertex(
T.label, "Reaction",
"title", reaction.getTitle(),
"content", reaction.getContent(),
"creationDate", new Date());
graph.traversal().V(graphUtils.getObjectVertexId(reactToReactionId, graph)).has(T.label, "Reaction").next()
.addEdge("reactedTo", reactionVertex);
reaction.setId(graphUtils.getStringVertexId(reactionVertex, graph));
return reaction;
});
}
}
示例8: projectTraverser
import org.apache.tinkerpop.gremlin.structure.T; //导入依赖的package包/类
@Override
public JSONObject projectTraverser(final Traverser.Admin<Path> traverser) {
final JSONObject root = new JSONObject();
JSONObject currentNode = root;
for (final Object object : traverser.get()) {
if (object instanceof Map) {
for(final Map.Entry entry : (Set<Map.Entry>)((Map)object).entrySet()) {
if(entry.getKey().equals(T.id))
currentNode.put(T.id.getAccessor(),entry.getValue());
else if(entry.getKey().equals(T.label))
currentNode.put(T.label.getAccessor(),entry.getValue());
else
currentNode.put(entry.getKey(),entry.getValue());
}
}
else if (object instanceof String)
currentNode.put(object, currentNode = new JSONObject());
}
return root;
}
示例9: shouldDeserializeGraphSONIntoTinkerGraphKeepingTypes
import org.apache.tinkerpop.gremlin.structure.T; //导入依赖的package包/类
/**
* Thorough types verification for Vertex ids, Vertex props, Edge ids, Edge props
*/
@Test
public void shouldDeserializeGraphSONIntoTinkerGraphKeepingTypes() throws IOException {
final GraphWriter writer = getWriter(defaultMapperV2d0);
final GraphReader reader = getReader(defaultMapperV2d0);
final Graph sampleGraph1 = TinkerFactory.createModern();
final Vertex v1 = sampleGraph1.addVertex(T.id, 100, "name", "kevin", "theUUID", UUID.randomUUID());
final Vertex v2 = sampleGraph1.addVertex(T.id, 101L, "name", "henri", "theUUID", UUID.randomUUID());
v1.addEdge("hello", v2, T.id, 101L,
"uuid", UUID.randomUUID());
try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
writer.writeObject(out, sampleGraph1);
final String json = out.toString();
final TinkerGraph read = reader.readObject(new ByteArrayInputStream(json.getBytes()), TinkerGraph.class);
assertTrue(approximateGraphsCheck(sampleGraph1, read));
}
}
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:23,代码来源:TinkerGraphGraphSONSerializerV2d0Test.java
示例10: shouldLoseTypesWithGraphSONNoTypesForVertexIds
import org.apache.tinkerpop.gremlin.structure.T; //导入依赖的package包/类
/**
* Asserts the approximateGraphsChecks function fails when expected. Vertex ids.
*/
@Test
public void shouldLoseTypesWithGraphSONNoTypesForVertexIds() throws IOException {
final GraphWriter writer = getWriter(noTypesMapperV2d0);
final GraphReader reader = getReader(noTypesMapperV2d0);
final TinkerGraph sampleGraph1 = TinkerGraph.open();
TinkerFactory.generateModern(sampleGraph1);
sampleGraph1.addVertex(T.id, 100L, "name", "kevin");
try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
writer.writeGraph(out, sampleGraph1);
final String json = out.toString();
final TinkerGraph read = TinkerGraph.open();
reader.readGraph(new ByteArrayInputStream(json.getBytes()), read);
// Should fail on deserialized vertex Id.
assertFalse(approximateGraphsCheck(sampleGraph1, read));
}
}
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:20,代码来源:TinkerGraphGraphSONSerializerV2d0Test.java
示例11: shouldLoseTypesWithGraphSONNoTypesForVertexProps
import org.apache.tinkerpop.gremlin.structure.T; //导入依赖的package包/类
/**
* Asserts the approximateGraphsChecks function fails when expected. Vertex props.
*/
@Test
public void shouldLoseTypesWithGraphSONNoTypesForVertexProps() throws IOException {
final GraphWriter writer = getWriter(noTypesMapperV2d0);
final GraphReader reader = getReader(noTypesMapperV2d0);
final TinkerGraph sampleGraph1 = TinkerGraph.open();
TinkerFactory.generateModern(sampleGraph1);
sampleGraph1.addVertex(T.id, 100, "name", "kevin", "uuid", UUID.randomUUID());
try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
writer.writeGraph(out, sampleGraph1);
final String json = out.toString();
final TinkerGraph read = TinkerGraph.open();
reader.readGraph(new ByteArrayInputStream(json.getBytes()), read);
// Should fail on deserialized vertex prop.
assertFalse(approximateGraphsCheck(sampleGraph1, read));
}
}
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:21,代码来源:TinkerGraphGraphSONSerializerV2d0Test.java
示例12: shouldLoseTypesWithGraphSONNoTypesForEdgeIds
import org.apache.tinkerpop.gremlin.structure.T; //导入依赖的package包/类
/**
* Asserts the approximateGraphsChecks function fails when expected. Edge ids.
*/
@Test
public void shouldLoseTypesWithGraphSONNoTypesForEdgeIds() throws IOException {
final GraphWriter writer = getWriter(noTypesMapperV2d0);
final GraphReader reader = getReader(noTypesMapperV2d0);
final TinkerGraph sampleGraph1 = TinkerGraph.open();
TinkerFactory.generateModern(sampleGraph1);
final Vertex v1 = sampleGraph1.addVertex(T.id, 100, "name", "kevin");
v1.addEdge("hello", sampleGraph1.traversal().V().has("name", "marko").next(), T.id, 101L);
try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
writer.writeGraph(out, sampleGraph1);
final String json = out.toString();
final TinkerGraph read = TinkerGraph.open();
reader.readGraph(new ByteArrayInputStream(json.getBytes()), read);
// Should fail on deserialized edge Id.
assertFalse(approximateGraphsCheck(sampleGraph1, read));
}
}
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:21,代码来源:TinkerGraphGraphSONSerializerV2d0Test.java
示例13: shouldLoseTypesWithGraphSONNoTypesForEdgeProps
import org.apache.tinkerpop.gremlin.structure.T; //导入依赖的package包/类
/**
* Asserts the approximateGraphsChecks function fails when expected. Edge props.
*/
@Test
public void shouldLoseTypesWithGraphSONNoTypesForEdgeProps() throws IOException {
final GraphWriter writer = getWriter(noTypesMapperV2d0);
final GraphReader reader = getReader(noTypesMapperV2d0);
final Graph sampleGraph1 = TinkerFactory.createModern();
final Vertex v1 = sampleGraph1.addVertex(T.id, 100, "name", "kevin");
v1.addEdge("hello", sampleGraph1.traversal().V().has("name", "marko").next(), T.id, 101,
"uuid", UUID.randomUUID());
try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
writer.writeGraph(out, sampleGraph1);
final String json = out.toString();
final TinkerGraph read = TinkerGraph.open();
reader.readGraph(new ByteArrayInputStream(json.getBytes()), read);
// Should fail on deserialized edge prop.
assertFalse(approximateGraphsCheck(sampleGraph1, read));
}
}
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:22,代码来源:TinkerGraphGraphSONSerializerV2d0Test.java
示例14: write
import org.apache.tinkerpop.gremlin.structure.T; //导入依赖的package包/类
@Override
public void write(final Kryo kryo, final Output output, final Color color) {
final TinkerGraph graph = TinkerGraph.open();
final Vertex v = graph.addVertex(T.id, 1, T.label, "color", "name", color.toString());
final Vertex vRed = graph.addVertex(T.id, 2, T.label, "primary", "name", "red");
final Vertex vGreen = graph.addVertex(T.id, 3, T.label, "primary", "name", "green");
final Vertex vBlue = graph.addVertex(T.id, 4, T.label, "primary", "name", "blue");
v.addEdge("hasComponent", vRed, "amount", color.getRed());
v.addEdge("hasComponent", vGreen, "amount", color.getGreen());
v.addEdge("hasComponent", vBlue, "amount", color.getBlue());
// make some junk so the graph is kinda big
generate(graph);
try (final ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
GryoWriter.build().mapper(() -> kryo).create().writeGraph(stream, graph);
final byte[] bytes = stream.toByteArray();
output.writeInt(bytes.length);
output.write(bytes);
} catch (Exception ex) {
ex.printStackTrace();
}
}
示例15: testPlay6
import org.apache.tinkerpop.gremlin.structure.T; //导入依赖的package包/类
@Test
@Ignore
public void testPlay6() throws Exception {
final Graph graph = TinkerGraph.open();
final GraphTraversalSource g = graph.traversal();
for (int i = 0; i < 1000; i++) {
graph.addVertex(T.label, "person", T.id, i);
}
graph.vertices().forEachRemaining(a -> {
graph.vertices().forEachRemaining(b -> {
if (a != b) {
a.addEdge("knows", b);
}
});
});
graph.vertices(50).next().addEdge("uncle", graph.vertices(70).next());
logger.info(TimeUtil.clockWithResult(500, () -> g.V().match(as("a").out("knows").as("b"), as("a").out("uncle").as("b")).toList()).toString());
}