Java Code Examples for org.apache.tinkerpop.gremlin.structure.T#id()
The following examples show how to use
org.apache.tinkerpop.gremlin.structure.T#id() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StarGraph.java From tinkerpop with Apache License 2.0 | 6 votes |
@Override public Edge addEdge(final String label, final Vertex inVertex, final Object... keyValues) { final Edge edge = this.addOutEdge(label, inVertex, keyValues); if (inVertex.equals(this)) { if (ElementHelper.getIdValue(keyValues).isPresent()) { // reuse edge ID from method params this.addInEdge(label, this, keyValues); } else { // copy edge ID that we just allocated with addOutEdge final Object[] keyValuesWithId = Arrays.copyOf(keyValues, keyValues.length + 2); keyValuesWithId[keyValuesWithId.length - 2] = T.id; keyValuesWithId[keyValuesWithId.length - 1] = edge.id(); this.addInEdge(label, this, keyValuesWithId); } } return edge; }
Example 2
Source File: AddVertexStartStep.java From tinkerpop with Apache License 2.0 | 6 votes |
@Override public void configure(final Object... keyValues) { if (keyValues[0] == T.label && this.parameters.contains(T.label)) { if (this.parameters.contains(T.label, Vertex.DEFAULT_LABEL)) { this.parameters.remove(T.label); this.parameters.set(this, keyValues); } else { throw new IllegalArgumentException(String.format("Vertex T.label has already been set to [%s] and cannot be overridden with [%s]", this.parameters.getRaw().get(T.label).get(0), keyValues[1])); } } else if (keyValues[0] == T.id && this.parameters.contains(T.id)) { throw new IllegalArgumentException(String.format("Vertex T.id has already been set to [%s] and cannot be overridden with [%s]", this.parameters.getRaw().get(T.id).get(0), keyValues[1])); } else { this.parameters.set(this, keyValues); } }
Example 3
Source File: AddVertexStep.java From tinkerpop with Apache License 2.0 | 6 votes |
@Override public void configure(final Object... keyValues) { if (keyValues[0] == T.label && this.parameters.contains(T.label)) { if (this.parameters.contains(T.label, Vertex.DEFAULT_LABEL)) { this.parameters.remove(T.label); this.parameters.set(this, keyValues); } else { throw new IllegalArgumentException(String.format("Vertex T.label has already been set to [%s] and cannot be overridden with [%s]", this.parameters.getRaw().get(T.label).get(0), keyValues[1])); } } else if (keyValues[0] == T.id && this.parameters.contains(T.id)) { throw new IllegalArgumentException(String.format("Vertex T.id has already been set to [%s] and cannot be overridden with [%s]", this.parameters.getRaw().get(T.id).get(0), keyValues[1])); } else { this.parameters.set(this, keyValues); } }
Example 4
Source File: DefaultImportCustomizerTest.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test public void shouldReturnAssignedImportsWhenBuiltViaCollections() throws Exception { final Method abs = Math.class.getMethod("abs", double.class); final Enum dayOfWeekEnum = DayOfWeek.SATURDAY; final Enum tEnum = T.id; final ImportCustomizer imports = DefaultImportCustomizer.build() .addClassImports(Arrays.asList(java.awt.Color.class, java.awt.AlphaComposite.class)) .addMethodImports(Collections.singletonList(abs)) .addEnumImports(Arrays.asList(dayOfWeekEnum, tEnum)).create(); assertEquals(2, imports.getClassImports().size()); assertThat(imports.getClassImports(), hasItems(java.awt.Color.class, java.awt.AlphaComposite.class)); assertEquals(1, imports.getMethodImports().size()); assertThat(imports.getMethodImports(), hasItems(abs)); assertEquals(2, imports.getEnumImports().size()); assertThat(imports.getEnumImports(), hasItems(dayOfWeekEnum, tEnum)); }
Example 5
Source File: TokenTraversalTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test public void shouldWorkOnVertex() { final TokenTraversal<Vertex, Integer> t = new TokenTraversal<>(T.id); final Vertex v = mock(Vertex.class); when(v.id()).thenReturn(100); t.addStart(new B_O_Traverser<>(v, 1).asAdmin()); assertEquals(100, t.next().intValue()); }
Example 6
Source File: TokenTraversalTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test public void shouldWorkOnVertexProperty() { final TokenTraversal<VertexProperty, Integer> t = new TokenTraversal<>(T.id); final VertexProperty vo = mock(VertexProperty.class); when(vo.id()).thenReturn(100); t.addStart(new B_O_Traverser<>(vo, 1).asAdmin()); assertEquals(100, t.next().intValue()); }
Example 7
Source File: TokenTraversalTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test public void shouldWorkOnEdge() { final TokenTraversal<Edge, Integer> t = new TokenTraversal<>(T.id); final Edge e = mock(Edge.class); when(e.id()).thenReturn(100); t.addStart(new B_O_Traverser<>(e, 1).asAdmin()); assertEquals(100, t.next().intValue()); }
Example 8
Source File: DefaultImportCustomizerTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test public void shouldReturnAssignedImports() throws Exception { final Method abs = Math.class.getMethod("abs", double.class); final Enum dayOfWeekEnum = DayOfWeek.SATURDAY; final Enum tEnum = T.id; final Field fieldLabels = WithOptions.class.getDeclaredField("labels"); final ImportCustomizer imports = DefaultImportCustomizer.build() .addClassImports(java.awt.Color.class, java.awt.AlphaComposite.class) .addFieldImports(fieldLabels) .addMethodImports(abs) .addEnumImports(dayOfWeekEnum, tEnum).create(); assertEquals(2, imports.getClassImports().size()); assertThat(imports.getClassImports(), hasItems(java.awt.Color.class, java.awt.AlphaComposite.class)); assertEquals(1, imports.getClassPackages().size()); assertThat(imports.getClassPackages(), hasItems(java.awt.Color.class.getPackage())); assertEquals(1, imports.getMethodImports().size()); assertThat(imports.getMethodImports(), hasItems(abs)); assertEquals(1, imports.getMethodClasses().size()); assertThat(imports.getMethodClasses(), hasItems(Math.class)); assertEquals(2, imports.getEnumImports().size()); assertThat(imports.getEnumImports(), hasItems(dayOfWeekEnum, tEnum)); assertEquals(2, imports.getEnumClasses().size()); assertThat(imports.getEnumClasses(), hasItems(T.class, DayOfWeek.class)); assertEquals(1, imports.getFieldImports().size()); assertThat(imports.getFieldImports(), hasItems(fieldLabels)); assertEquals(1, imports.getFieldClasses().size()); assertThat(imports.getFieldClasses(), hasItems(WithOptions.class)); }
Example 9
Source File: SparkMessengerTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test public void testSparkMessenger() throws Exception { // Define scopes final MessageScope.Local<String> orderSrcMessageScope = MessageScope.Local .of(__::inE, (message, edge) -> { if ("mocked_edge_label1".equals(edge.label())) { return message; } return null; }); // Define star graph final StarGraph starGraph = StarGraph.open(); Object[] vertex0Array = new Object[]{T.id, 0, T.label, "mocked_vertex_label1"}; Object[] vertex1Array = new Object[]{T.id, 1, T.label, "mocked_vertex_label2"}; Object[] vertex2Array = new Object[]{T.id, 2, T.label, "mocked_vertex_label2"}; Vertex vertex0 = starGraph.addVertex(vertex0Array); Vertex vertex1 = starGraph.addVertex(vertex1Array); Vertex vertex2 = starGraph.addVertex(vertex2Array); vertex1.addEdge("mocked_edge_label1", vertex0); vertex2.addEdge("mocked_edge_label2", vertex0); // Create Spark Messenger final SparkMessenger<String> messenger = new SparkMessenger<>(); final List<String> incomingMessages = Arrays.asList("a", "b", "c"); messenger.setVertexAndIncomingMessages(vertex0, incomingMessages); messenger.sendMessage(orderSrcMessageScope, "a"); List<Tuple2<Object, String>> outgoingMessages0 = messenger.getOutgoingMessages(); Assert.assertEquals("a", outgoingMessages0.get(0)._2()); Assert.assertNull(outgoingMessages0.get(1)._2()); }
Example 10
Source File: BitsyVertex.java From bitsy with Apache License 2.0 | 4 votes |
@Override public Edge addEdge(String label, Vertex inVertex, Object... keyValues) { if (keyValues.length % 2 == 1) { throw new IllegalArgumentException("Expecting even number of items in the keyValue array. Found " + keyValues.length); } if (label == null) { throw new IllegalArgumentException("You have to specify a non-null String label when adding an edge"); } else if (label.length() == 0) { throw new IllegalArgumentException("You have to specify a non-empty String label when adding an edge"); } else if (label.charAt(0) == '~') { throw new IllegalArgumentException("Labels beginning with ~ are invalid"); } if (inVertex == null) { throw new IllegalArgumentException("The inVertex supplied to addEdge() is null"); } // Validate first for (int i = 0; i < keyValues.length; i = i+2) { if (keyValues[i] == T.label) { throw new UnsupportedOperationException("Encountered T.label in addVertex"); } else if (keyValues[i] == T.id) { throw new UnsupportedOperationException("Encountered T.id in addVertex", new BitsyException(BitsyErrorCodes.NO_CUSTOM_ID_SUPPORT)); } else if (keyValues[i] == null) { throw new IllegalArgumentException("Encountered a null key in argument #" + i); } else if (keyValues[i+1] == null) { throw new IllegalArgumentException("Encountered a null value in argument #" + i); } else if (!(keyValues[i] instanceof String)) { throw new IllegalArgumentException("Encountered a non-string key: " + keyValues[i] + " in argument #" + i); } } // Construct the edge with this as the out vertex BitsyEdge edge = new BitsyEdge(UUID.randomUUID(), null, tx, BitsyState.M, 0, label, (UUID)id(), (UUID)inVertex.id()); for (int i = 0; i < keyValues.length; i = i+2) { String key = (String)keyValues[i]; edge.property(key, keyValues[i+1]); } tx.addEdge(edge); return edge; }
Example 11
Source File: ArangoDBVertex.java From arangodb-tinkerpop-provider with Apache License 2.0 | 4 votes |
@Override public <V> VertexProperty<V> property( Cardinality cardinality, String key, V value, Object... keyValues) { logger.debug("setting vertex property {} = {} ({})", key, value, keyValues); ElementHelper.validateProperty(key, value); ElementHelper.legalPropertyKeyValueArray(keyValues); Optional<Object> idValue = ElementHelper.getIdValue(keyValues); String id = null; if (idValue.isPresent()) { if (graph.features().vertex().willAllowId(idValue.get())) { id = idValue.get().toString(); if (id.toString().contains("/")) { String fullId = id.toString(); String[] parts = fullId.split("/"); // The collection name is the last part of the full name String[] collectionParts = parts[0].split("_"); String collectionName = collectionParts[collectionParts.length-1]; if (collectionName.contains(ArangoDBGraph.ELEMENT_PROPERTIES_COLLECTION)) { id = parts[1]; } } Matcher m = ArangoDBUtil.DOCUMENT_KEY.matcher((String)id); if (!m.matches()) { throw new ArangoDBGraphException(String.format("Given id (%s) has unsupported characters.", id)); } } else { throw VertexProperty.Exceptions.userSuppliedIdsOfThisTypeNotSupported(); } int idIndex = 0; for (int i = 0; i < keyValues.length; i+=2) { if (keyValues[i] == T.id) { idIndex = i; break; } } keyValues = ArrayUtils.remove(keyValues, idIndex); keyValues = ArrayUtils.remove(keyValues, idIndex); } final Optional<VertexProperty<V>> optionalVertexProperty = ElementHelper.stageVertexProperty(this, cardinality, key, value, keyValues); if (optionalVertexProperty.isPresent()) return optionalVertexProperty.get(); ArangoDBVertexProperty<V> p = ArangoDBUtil.createArangoDBVertexProperty(id, key, value, this); ElementHelper.attachProperties(p, keyValues); return p; }