IndexStore { public void index(T element) { ElementImpl elementImpl = (ElementImpl) element; lock(); try { ensureAttributeArrayLength(elementImpl, columnStore.length); final int length = columnStore.length; final ColumnImpl[] cols = columnStore.columns; for (int i = 0; i < length; i++) { Column c = cols[i]; if (c != null && c.isIndexed()) { Object value = elementImpl.attributes[c.getIndex()]; value = mainIndex.put(c, value, element); elementImpl.attributes[c.getIndex()] = value; } } } finally { unlock(); } } IndexStore(ColumnStore<T> columnStore); Object set(Column column, Object oldValue, Object value, T element); void clear(T element); void index(T element); void indexView(Graph graph); void indexInView(T element, GraphView view); void clearInView(T element, GraphView view); void clear(GraphView view); void clear();  }
@Test public void testIndexNodeNull() { IndexStore<Node> indexStore = generateBasicNodeColumnStore().indexStore; NodeImpl n = new NodeImpl("0"); indexStore.index(n); Assert.assertEquals(n.attributes.length, indexStore.columnStore.length); }
@Test public void testIndexNode() { ColumnStore<Node> columnStore = generateBasicNodeColumnStore(); IndexStore<Node> indexStore = columnStore.indexStore; IndexImpl<Node> mainIndex = indexStore.mainIndex; Column col1 = columnStore.getColumn("foo"); Column col2 = columnStore.getColumn("age"); NodeImpl n = new NodeImpl("0"); n.setAttribute(col1, "A"); n.setAttribute(col2, 20); indexStore.index(n); Assert.assertEquals(mainIndex.count(col1, "A"), 1); Assert.assertEquals(mainIndex.count("foo", "A"), 1); Assert.assertEquals(mainIndex.count(col2, 20), 1); Assert.assertEquals(mainIndex.count("age", 20), 1); Assert.assertEquals(mainIndex.countElements(col1), 1); Assert.assertEquals(mainIndex.countElements(col2), 1); Assert.assertEquals(mainIndex.countValues(col1), 1); Assert.assertEquals(mainIndex.countValues(col2), 1); Assert.assertTrue(mainIndex.values(col1).contains("A")); Assert.assertTrue(mainIndex.values(col2).contains(20)); Assert.assertSame(getIterable(mainIndex.get(col1, "A"))[0], n); Assert.assertNull(mainIndex.get(col1, "B")); Assert.assertSame(getIterable(mainIndex.get("foo", "A"))[0], n); Assert.assertNull(mainIndex.get("foo", "B")); }
@Test public void testIndexNodeNullValue() { ColumnStore<Node> columnStore = generateBasicNodeColumnStore(); IndexStore<Node> indexStore = columnStore.indexStore; IndexImpl<Node> mainIndex = indexStore.mainIndex; Column col1 = columnStore.getColumn("foo"); Column col2 = columnStore.getColumn("age"); NodeImpl n = new NodeImpl("0"); n.setAttribute(col1, null); n.setAttribute(col2, null); indexStore.index(n); Assert.assertEquals(mainIndex.count(col1, null), 1); Assert.assertEquals(mainIndex.count(col2, null), 1); Assert.assertEquals(mainIndex.countElements(col1), 1); Assert.assertEquals(mainIndex.countElements(col2), 1); Assert.assertEquals(mainIndex.countValues(col1), 1); Assert.assertEquals(mainIndex.countValues(col2), 1); Assert.assertTrue(mainIndex.values(col1).contains(null)); Assert.assertTrue(mainIndex.values(col2).contains(null)); Assert.assertSame(getIterable(mainIndex.get(col1, null))[0], n); }
@Test public void testIndexNodeUnique() { ColumnStore<Node> columnStore = generateBasicNodeColumnStore(); IndexStore<Node> indexStore = columnStore.indexStore; IndexImpl<Node> mainIndex = indexStore.mainIndex; Column col1 = columnStore.getColumn("foo"); Column col2 = columnStore.getColumn("age"); NodeImpl[] nodes = generateNodesWithUniqueAttributes(columnStore); for (NodeImpl n : nodes) { indexStore.index(n); } Assert.assertEquals(mainIndex.countElements(col1), nodes.length); Assert.assertEquals(mainIndex.countElements(col2), nodes.length); Assert.assertEquals(mainIndex.countValues(col1), nodes.length); Assert.assertEquals(mainIndex.countValues(col2), nodes.length); Assert.assertEquals(mainIndex.values(col1).size(), nodes.length); Assert.assertEquals(mainIndex.values(col2).size(), nodes.length); }