@Override public void initialise(final DataAccessLayerFactory factory) throws InitialisationException { _byValue = new PersistentMap<String, byte[]>( String.class, byte[].class, _indexName, false, ValueDictionaryBase.NOT_SET); _byValue.initialise(factory); _byId = new PersistentMap<byte[], String>( byte[].class, String.class, _indexName + "_REVERSE", false, ""); _byId.initialise(factory); }
/** * Removes all elements from this set. * * @throws DataAccessLayerException in case of data access failure. */ public void clear() throws DataAccessLayerException { _map.clear(); }
/** * Returns true if this index contains the given id. * * @param id the id of a given resource. * @return true if this index contains the given id. * @throws DataAccessLayerException in case of data access failure. */ public boolean contains(final byte[] id) throws DataAccessLayerException { return _byId.containsKey(id); }
/** * 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 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)); } }
/** * 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; } }
@Test public void removeTest() throws DataAccessLayerException { assertEquals(TESTDATA1.size(), map.size()); for (String key : TESTDATA4.keySet()) { assertNull(map.remove(key)); } for (String key : TESTDATA1.keySet()) { assertEquals(TESTDATA1.get(key), map.remove(key)); } assertTrue(map.isEmpty()); }
/** * 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); }
/** * Adds a new element to this set. * * @param e the element. * @return true if the add succeeds. * @throws DataAccessLayerException in case of data access failure. */ public boolean add(final E e) throws DataAccessLayerException { return e == null ? false : (_map.put(e, PRESENT) == null); }
/** * Returns an array containing all elements of this set. * * @param a the destination array. * @return an array containing all elements of this set. * @throws DataAccessLayerException in case of data access failure. * @param <E> the element kind. */ @SuppressWarnings("hiding") public <E> E[] toArray(final E[] a) throws DataAccessLayerException { return _map.keySet().toArray(a); } }
/** * Returns the amount of entries in this map. * * @return the amount of entries in this map. * @throws DataAccessLayerException in case of data access failure. */ public int size() throws DataAccessLayerException { if (_size == -1) { _size = entrySet().size(); } return _size; }
/** * Returns the value associated with the given id. * * @param id the Cumulus internal id. * @return the value associated with the given id. * @throws DataAccessLayerException in case of data access failure. */ public String getQuick(final byte[] id) throws DataAccessLayerException { return _byId.getQuick(id); }
/** * Builds a new set with a given element class and identified by a given name. * * @param elementClass the element class. * @param name the set (identity) name. */ public PersistentSet(final Class<E> elementClass, final String name) { _map = new PersistentMap<E, byte[]>(elementClass, byte[].class, name, false, null); }
@Override public void initialise(final DataAccessLayerFactory factory) throws InitialisationException { _map.initialise(factory); }
/** * Returns true if this set is empty. * * @return true if this set is empty. * @throws DataAccessLayerException in case of data access failure. */ public boolean isEmpty() throws DataAccessLayerException { return _map.isEmpty(); }