/** * Create an index for said element class ({@link Vertex} or {@link Edge}) and said property key. * Whenever an element has the specified key mutated, the index is updated. * When the index is created, all existing elements are indexed to ensure that they are captured by the index. * * @param key the property key to index * @param elementClass the element class to index * @param <E> The type of the element class */ public <E extends Element> void createIndex(final String key, final Class<E> elementClass) { if (Vertex.class.isAssignableFrom(elementClass)) { if (null == this.vertexIndex) this.vertexIndex = new TinkerIndex<>(this, TinkerVertex.class); this.vertexIndex.createKeyIndex(key); } else if (Edge.class.isAssignableFrom(elementClass)) { if (null == this.edgeIndex) this.edgeIndex = new TinkerIndex<>(this, TinkerEdge.class); this.edgeIndex.createKeyIndex(key); } else { throw new IllegalArgumentException("Class is not indexable: " + elementClass); } }
public static void autoUpdateIndex(final TinkerEdge edge, final String key, final Object newValue, final Object oldValue) { final TinkerGraph graph = (TinkerGraph) edge.graph(); if (graph.edgeIndex != null) graph.edgeIndex.autoUpdate(key, newValue, oldValue, edge); }
/** * Drop the index for the specified element class ({@link Vertex} or {@link Edge}) and key. * * @param key the property key to stop indexing * @param elementClass the element class of the index to drop * @param <E> The type of the element class */ public <E extends Element> void dropIndex(final String key, final Class<E> elementClass) { if (Vertex.class.isAssignableFrom(elementClass)) { if (null != this.vertexIndex) this.vertexIndex.dropKeyIndex(key); } else if (Edge.class.isAssignableFrom(elementClass)) { if (null != this.edgeIndex) this.edgeIndex.dropKeyIndex(key); } else { throw new IllegalArgumentException("Class is not indexable: " + elementClass); } }
public void autoRemove(final String key, final Object oldValue, final T element) { if (this.indexedKeys.contains(key)) this.remove(key, oldValue, element); }
public static void removeElementIndex(final TinkerVertex vertex) { final TinkerGraph graph = (TinkerGraph) vertex.graph(); if (graph.vertexIndex != null) graph.vertexIndex.removeElement(vertex); }
public static List<TinkerEdge> queryEdgeIndex(final TinkerGraph graph, final String key, final Object value) { return null == graph.edgeIndex ? Collections.emptyList() : graph.edgeIndex.get(key, value); }
public void createKeyIndex(final String key) { if (null == key) throw Graph.Exceptions.argumentCanNotBeNull("key"); if (key.isEmpty()) throw new IllegalArgumentException("The key for the index cannot be an empty string"); if (this.indexedKeys.contains(key)) return; this.indexedKeys.add(key); (Vertex.class.isAssignableFrom(this.indexClass) ? this.graph.vertices.values().<T>parallelStream() : this.graph.edges.values().<T>parallelStream()) .map(e -> new Object[]{((T) e).property(key), e}) .filter(a -> ((Property) a[0]).isPresent()) .forEach(a -> this.put(key, ((Property) a[0]).value(), (T) a[1])); }
/** * Return all the keys currently being index for said element class ({@link Vertex} or {@link Edge}). * * @param elementClass the element class to get the indexed keys for * @param <E> The type of the element class * @return the set of keys currently being indexed */ public <E extends Element> Set<String> getIndexedKeys(final Class<E> elementClass) { if (Vertex.class.isAssignableFrom(elementClass)) { return null == this.vertexIndex ? Collections.emptySet() : this.vertexIndex.getIndexedKeys(); } else if (Edge.class.isAssignableFrom(elementClass)) { return null == this.edgeIndex ? Collections.emptySet() : this.edgeIndex.getIndexedKeys(); } else { throw new IllegalArgumentException("Class is not indexable: " + elementClass); } }
public static void removeIndex(final TinkerEdge edge, final String key, final Object value) { final TinkerGraph graph = (TinkerGraph) edge.graph(); if (graph.edgeIndex != null) graph.edgeIndex.remove(key, value, edge); }
public static void removeElementIndex(final TinkerEdge edge) { final TinkerGraph graph = (TinkerGraph) edge.graph(); if (graph.edgeIndex != null) graph.edgeIndex.removeElement(edge); }
public static List<TinkerVertex> queryVertexIndex(final TinkerGraph graph, final String key, final Object value) { return null == graph.vertexIndex ? Collections.emptyList() : graph.vertexIndex.get(key, value); }
public void createKeyIndex(final String key) { if (null == key) throw Graph.Exceptions.argumentCanNotBeNull("key"); if (key.isEmpty()) throw new IllegalArgumentException("The key for the index cannot be an empty string"); if (this.indexedKeys.contains(key)) return; this.indexedKeys.add(key); (Vertex.class.isAssignableFrom(this.indexClass) ? this.graph.vertices.values().<T>stream() : this.graph.edges.values().<T>stream()) .map(e -> new Object[]{((T) e).property(key), e}) .filter(a -> ((Property) a[0]).isPresent()) .forEach(a -> this.put(key, ((Property) a[0]).value(), (T) a[1])); }
/** * Return all the keys currently being index for said element class ({@link Vertex} or {@link Edge}). * * @param elementClass the element class to get the indexed keys for * @param <E> The type of the element class * @return the set of keys currently being indexed */ public <E extends Element> Set<String> getIndexedKeys(final Class<E> elementClass) { if (Vertex.class.isAssignableFrom(elementClass)) { return null == this.vertexIndex ? Collections.emptySet() : this.vertexIndex.getIndexedKeys(); } else if (Edge.class.isAssignableFrom(elementClass)) { return null == this.edgeIndex ? Collections.emptySet() : this.edgeIndex.getIndexedKeys(); } else { throw new IllegalArgumentException("Class is not indexable: " + elementClass); } }
/** * Create an index for said element class ({@link Vertex} or {@link Edge}) and said property key. * Whenever an element has the specified key mutated, the index is updated. * When the index is created, all existing elements are indexed to ensure that they are captured by the index. * * @param key the property key to index * @param elementClass the element class to index * @param <E> The type of the element class */ public <E extends Element> void createIndex(final String key, final Class<E> elementClass) { if (Vertex.class.isAssignableFrom(elementClass)) { if (null == this.vertexIndex) this.vertexIndex = new TinkerIndex<>(this, TinkerVertex.class); this.vertexIndex.createKeyIndex(key); } else if (Edge.class.isAssignableFrom(elementClass)) { if (null == this.edgeIndex) this.edgeIndex = new TinkerIndex<>(this, TinkerEdge.class); this.edgeIndex.createKeyIndex(key); } else { throw new IllegalArgumentException("Class is not indexable: " + elementClass); } }
public static void removeIndex(final TinkerVertex vertex, final String key, final Object value) { final TinkerGraph graph = (TinkerGraph) vertex.graph(); if (graph.vertexIndex != null) graph.vertexIndex.remove(key, value, vertex); }
public static void removeElementIndex(final TinkerEdge edge) { final TinkerGraph graph = (TinkerGraph) edge.graph(); if (graph.edgeIndex != null) graph.edgeIndex.removeElement(edge); }
public static void autoUpdateIndex(final TinkerVertex vertex, final String key, final Object newValue, final Object oldValue) { final TinkerGraph graph = (TinkerGraph) vertex.graph(); if (graph.vertexIndex != null) graph.vertexIndex.autoUpdate(key, newValue, oldValue, vertex); }