/** * Returns the id associated with the given value. * * @param value the n3 value. * @return the id associated with the given value. * @throws DataAccessLayerException in case of data access failure. */ public byte[] get(final String value) throws DataAccessLayerException { return _byValue.get(value); }
/** * Returns the id associated with the given value. * * @param value the n3 value. * @return the id associated with the given value. * @throws DataAccessLayerException in case of data access failure. */ public byte[] get(final String value) throws DataAccessLayerException { return _byValue.get(value); }
/** * Returns a collection containing all values of this map. * * @return a collection containing all values of this map. * @throws DataAccessLayerException in case of data access failure. */ public Collection<V> values() throws DataAccessLayerException { final List<V> values = new LinkedList<V>(); for (final K key : keySet()) { final Object val = get(key); if (val != null) { values.add(get(key)); } } return values; } }
/** * Returns a collection containing all values of this map. * * @return a collection containing all values of this map. * @throws DataAccessLayerException in case of data access failure. */ public Collection<V> values() throws DataAccessLayerException { final List<V> values = new LinkedList<V>(); for (final K key : keySet()) { final Object val = get(key); if (val != null) { values.add(get(key)); } } return values; } }
/** * Removes the entry with the given key from the map. * * @param key the key. * @return the old value mapped to the key, or null if nothing was mapped to * that key. * @throws DataAccessLayerException in case of data access failure. */ @SuppressWarnings("unchecked") public V remove(final K key) throws DataAccessLayerException { if (key == null) { return null; } final V oldValue = get(key); if (oldValue == null) { return null; } _dao.delete(key); _size--; return oldValue; }
/** * Returns a set containing all keys within thid map. * * @return a set containing all keys within thid map. * @throws DataAccessLayerException in case of data access failure. */ public Set<Map.Entry<K, V>> entrySet() throws DataAccessLayerException { final Set<Map.Entry<K, V>> entrySet = new HashSet<Map.Entry<K, V>>(); for (final K key : keySet()) { entrySet.add(new Entry(key, get(key))); } return entrySet; }
/** * Puts the given entry key/value into this map. If a mapping already exists * for that key, it will be replaced with the new value. * * @param key the key. * @param value the value. * @return the old mapping (if exists). * @throws DataAccessLayerException in case of data access failure. */ public V put(final K key, final V value) throws DataAccessLayerException { if (key == null || value == null) { return null; } final V old_value = get(key); _dao.set(key, value); if (old_value == null) { _size++; } return old_value; }
/** * Puts the given entry key/value into this map. If a mapping already exists * for that key, it will be replaced with the new value. * * @param key the key. * @param value the value. * @return the old mapping (if exists). * @throws DataAccessLayerException in case of data access failure. */ public V put(final K key, final V value) throws DataAccessLayerException { if (key == null || value == null) { return null; } final V old_value = get(key); _dao.set(key, value); if (old_value == null) { _size++; } return old_value; }
/** * Returns a set containing all keys within thid map. * * @return a set containing all keys within thid map. * @throws DataAccessLayerException in case of data access failure. */ public Set<Map.Entry<K, V>> entrySet() throws DataAccessLayerException { final Set<Map.Entry<K, V>> entrySet = new HashSet<Map.Entry<K, V>>(); for (final K key : keySet()) { entrySet.add(new Entry(key, get(key))); } return entrySet; }
@Override protected String getNamespaceInternal(final String prefix) throws SailException { if (prefix == null || prefix.isEmpty()) { return prefix; } try { return _crdf.getPrefix2Namespaces().get(prefix); } catch (DataAccessLayerException exception) { throw new SailException(exception); } }
@Override protected String getNamespaceInternal(final String prefix) throws SailException { if (prefix == null || prefix.isEmpty()) { return prefix; } try { return _crdf.getPrefix2Namespaces().get(prefix); } catch (DataAccessLayerException exception) { throw new SailException(exception); } }
@Override public V computeNext() { try { if (!_key_iter.hasNext()) { return endOfData(); } K key = _key_iter.next(); if (key == null) { return endOfData(); } return get(key); } catch (final DataAccessLayerException exception) { throw new RuntimeException(exception); } } };
@Override public V computeNext() { try { if (!_key_iter.hasNext()) { return endOfData(); } K key = _key_iter.next(); if (key == null) { return endOfData(); } return get(key); } catch (final DataAccessLayerException exception) { throw new RuntimeException(exception); } } };
/** * Removes the given resource from this index. * * @param n3 the n3 representation of the resource to be removed. * @throws DataAccessLayerException in case of data access failure. */ public void remove(final String n3) throws DataAccessLayerException { _byId.removeQuick(_byValue.get(n3)); _byValue.removeQuick(n3); } }
/** * Removes the given resource from this index. * * @param n3 the n3 representation of the resource to be removed. * @throws DataAccessLayerException in case of data access failure. */ public void remove(final String n3) throws DataAccessLayerException { _byId.removeQuick(_byValue.get(n3)); _byValue.removeQuick(n3); } }
@Test public void getValueTest() throws DataAccessLayerException { for (String key : TESTDATA1.keySet()) { assertEquals(TESTDATA1.get(key), map.get(key)); } }
@Test public void insertTest() throws DataAccessLayerException { for (String key : TESTDATA2.keySet()) { assertEquals(TESTDATA1.get(key), map.put(key, TESTDATA2.get(key))); } for (String key : TESTDATA2.keySet()) { assertEquals(TESTDATA2.get(key), map.get(key)); } }
/** * remove method should use the both indexes. * * @throws Exception never otherwise the test fails. */ @Test public void remove() throws Exception { final byte[] id = { 1, 2, 3, 4 }; final String value = randomString(); when(_byValue.get(value)).thenReturn(id); _cut.remove(value); verify(_byValue).get(value); verify(_byId).removeQuick(id); verify(_byValue).removeQuick(value); } }
/** * get method should use the "ByValue" index. * * @throws Exception never otherwise the test fails. */ @Test public void get() throws Exception { final String value = randomString(); _cut.get(value); verify(_byValue).get(value); }
@Test public void insertAllTest() throws DataAccessLayerException { map.clear(); assertTrue(map.isEmpty()); map.putAll(TESTDATA1); for (String key : TESTDATA1.keySet()) { assertTrue(map.containsKey(key)); } for (String key : TESTDATA1.keySet()) { assertEquals(TESTDATA1.get(key), map.get(key)); } }