EdgeTypeStore { public int addType(final Object label) { checkType(label); short id = labelMap.getShort(label); if (id == NULL_SHORT) { if (!garbageQueue.isEmpty()) { id = garbageQueue.firstShort(); garbageQueue.remove(id); } else { id = intToShort(length); if (length >= MAX_SIZE) { throw new RuntimeException("Maximum number of edge types reached at " + MAX_SIZE); } length++; } labelMap.put(label, id); idMap.put(id, label); } return shortToInt(id); } EdgeTypeStore();  EdgeTypeStore(Configuration config); int getId(final Object label); Object getLabel(final int id); int addType(final Object label); boolean addType(final Object label, final int id); int removeType(final Object label); Object removeType(final int type); Object[] getLabels(); int[] getIdsAsInts(); boolean contains(final Object label); boolean contains(final int id); void clear(); int size(); int deepHashCode(); boolean deepEquals(Object obj); final static int MAX_SIZE; }
@Test public void testAddType() { EdgeTypeStore edgeTypeStore = new EdgeTypeStore(); int type = edgeTypeStore.addType("0"); Assert.assertEquals(type, 1); Assert.assertTrue(edgeTypeStore.contains("0")); type = edgeTypeStore.addType("0"); Assert.assertEquals(type, 1); Assert.assertTrue(edgeTypeStore.contains("0")); }
@Test(expectedExceptions = RuntimeException.class) public void testMaximumLengthException() { EdgeTypeStore edgeTypeStore = new EdgeTypeStore(); for (int i = 0; i < 65534; i++) { edgeTypeStore.addType(String.valueOf(i)); } }
@Test public void testAddDirectTypeSameId() { EdgeTypeStore edgeTypeStore = new EdgeTypeStore(); Assert.assertEquals(edgeTypeStore.addType("foo"), 1); Assert.assertFalse(edgeTypeStore.addType("foo", 1)); }
@Test(expectedExceptions = RuntimeException.class) public void testAddDirectTypeDifferentId() { EdgeTypeStore edgeTypeStore = new EdgeTypeStore(); Assert.assertEquals(edgeTypeStore.addType("foo"), 1); edgeTypeStore.addType("foo", 2); }
@Test(expectedExceptions = RuntimeException.class) public void testAddDirectTypeDifferentLabel() { EdgeTypeStore edgeTypeStore = new EdgeTypeStore(); Assert.assertEquals(edgeTypeStore.addType("foo"), 1); edgeTypeStore.addType("bar", 1); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testAddWrongType() { EdgeTypeStore edgeTypeStore = new EdgeTypeStore(); edgeTypeStore.addType(42); }