/** * Creates a new identifier for a given resource. * The method takes care about (eventual) hash collision. * * @param value the resource. * @param n3 the N3 representation of resource. * @param index the dictionary index that could already hold that resource / id. * @return a new identifier for the given resource. * @throws DataAccessLayerException in case of data access failure. */ private byte[] newId(final Value value, final String n3, final BIndex index) throws DataAccessLayerException { byte[] id = makeNewHashID(value, n3); for (int i = 0; index.contains(id) && i <= 100; i++) { id = resolveHashCollision(id, i); if (i == 100) { _log.error(MessageCatalog._00071_UNABLE_TO_RESOLVE_COLLISION, n3, i); } } return id; }
/** * Creates a new identifier for a given resource. * The method takes care about (eventual) hash collision. * * @param n3 the N3 representation of resource. * @param index the dictionary index that could already hold that resource / id. * @return a new identifier for the given resource. * @throws DataAccessLayerException in case of data access failure. */ protected byte[] newId(final String n3, final BIndex index) throws DataAccessLayerException { byte[] id = makeNewHashID(n3); for (int i = 0; index.contains(id) && i <= 100; i++) { id = resolveHashCollision(id, i); if (i == 100) { _log.error(MessageCatalog._00071_UNABLE_TO_RESOLVE_COLLISION, n3, i); } } return id; }
/** * Creates a new identifier for a given resource. * The method takes care about (eventual) hash collision. * * @param n3 the N3 representation of resource. * @param index the dictionary index that could already hold that resource / id. * @return a new identifier for the given resource. * @throws DataAccessLayerException in case of data access failure. */ protected byte[] newId(final String n3, final BIndex index) throws DataAccessLayerException { byte[] id = makeNewHashID(n3); for (int i = 0; index.contains(id) && i <= 100; i++) { id = resolveHashCollision(id, i); if (i == 100) { _log.error(MessageCatalog._00071_UNABLE_TO_RESOLVE_COLLISION, n3, i); } } return id; }
/** * Creates a new identifier for a given resource. * The method takes care about (eventual) hash collision. * * @param value the resource. * @param n3 the N3 representation of resource. * @param index the dictionary index that could already hold that resource / id. * @return a new identifier for the given resource. * @throws DataAccessLayerException in case of data access failure. */ private byte[] newId(final Value value, final String n3, final BIndex index) throws DataAccessLayerException { byte[] id = makeNewHashID(value, n3); for (int i = 0; index.contains(id) && i <= 100; i++) { id = resolveHashCollision(id, i); if (i == 100) { _log.error(MessageCatalog._00071_UNABLE_TO_RESOLVE_COLLISION, n3, i); } } return id; }
/** * contains(id) method should use the "ById" index. * * @throws Exception never otherwise the test fails. */ @Test public void contains() throws Exception { final byte[] id = { 1, 2, 3, 4 }; _cut.contains(id); verify(_byId).containsKey(id); }
/** * Positive test for getID() method. * * @throws Exception never otherwise the test fails. */ @Test public void getIDNotPreviouslySet() throws Exception { when(_dummyIndex.contains(any(byte[].class))).thenReturn(false); final String aValue = randomString(); when(_dummyIndex.get(aValue)).thenReturn(IDictionary.NOT_SET); byte[] result = _cut.getID(aValue, RANDOMIZER.nextBoolean()); assertEquals(PersistentStringDictionary.ID_LENGTH, result.length); verify(_dummyIndex).get(aValue); verify(_dummyIndex).putQuick(aValue, result); }