public VersionedGraphBase(T baseGraph, GraphIdentifierBehavior<V> identifierBehavior, Configuration conf) { Preconditions.checkNotNull(baseGraph, "Base graph must be set."); Preconditions.checkNotNull(identifierBehavior, "Identifier behavior must be set."); this.underlineGraph = baseGraph; this.identifierBehavior = identifierBehavior; this.identifierBehavior.setGraph(this); if (conf == null) { this.conf = new Configuration.ConfBuilder().build(); } else { this.conf = conf; } this.features = baseGraph.getFeatures().copyFeatures(); features.isWrapper = true; if (this.conf.useNaturalIds || (this.conf.useNaturalIdsOnlyIfSuppliedIdsAreIgnored && baseGraph.getFeatures().ignoresSuppliedIds)) { features.ignoresSuppliedIds = true; } }
/** * Whether or not graph is configured to maintain natural IDs. * * @return true if graph is configured to maintain natural IDs. */ public boolean isNaturalIds() { return (conf.getUseNaturalIds() || (conf.getUseNaturalIdsOnlyIfSuppliedIdsAreIgnored() && getBaseGraph() .getFeatures().ignoresSuppliedIds)); }
/** * Adds custom ID functionality to the given graph, * supporting either custom vertex IDs, custom edge IDs, or both. * * @param baseGraph the base graph which does not necessarily support custom IDs * @param supportVertexIds whether to support custom vertex IDs * @param supportEdgeIds whether to support custom edge IDs */ public IdGraph(final T baseGraph, final boolean supportVertexIds, final boolean supportEdgeIds) { this.baseGraph = baseGraph; this.features = this.baseGraph.getFeatures().copyFeatures(); features.isWrapper = true; features.ignoresSuppliedIds = false; this.supportVertexIds = supportVertexIds; this.supportEdgeIds = supportEdgeIds; if (!supportVertexIds && !supportEdgeIds) { throw new IllegalArgumentException("if neither custom vertex IDs nor custom edge IDs are supported, IdGraph can't help you!"); } createIndices(); vertexIdFactory = new DefaultIdFactory(); edgeIdFactory = new DefaultIdFactory(); }
/** * Adds custom ID functionality to the given graph, supporting either custom vertex IDs, custom edge IDs, or both. * * @param baseGraph the base graph which does not necessarily support custom IDs * @param supportVertexIds whether to support custom vertex IDs * @param supportEdgeIds whether to support custom edge IDs */ public IdGraph(KeyIndexableGraph baseGraph, boolean supportVertexIds, boolean supportEdgeIds) { this.baseGraph = checkNotNull(baseGraph, "baseGraph"); this.supportVertexIds = supportVertexIds; this.supportEdgeIds = supportEdgeIds; checkArgument(supportVertexIds || supportEdgeIds, "If neither custom vertex IDs nor custom edge IDs are supported, IdGraph can't help you!"); // Create indices if (supportVertexIds && !baseGraph.getIndexedKeys(Vertex.class).contains(ID)) { baseGraph.createKeyIndex(ID, Vertex.class); } if (supportEdgeIds && !baseGraph.getIndexedKeys(Edge.class).contains(ID)) { baseGraph.createKeyIndex(ID, Edge.class); } features = baseGraph.getFeatures().copyFeatures(); features.isWrapper = true; features.ignoresSuppliedIds = false; }