Int2ObjectAVLTreeMap map = new Int2ObjectAVLTreeMap();
TreeMap map = new TreeMap();
	public Occurrences[] scanIndexedElements(		Collection collection,		boolean inclusive)		throws PermissionDeniedException {		if (!collection.getPermissions().validate(user, Permission.READ))			throw new PermissionDeniedException(				"you don't have the permission"					+ " to read collection "					+ collection.getName());		List collections =			inclusive ? collection.getDescendants(this, user) : new ArrayList();		collections.add(collection);		short collectionId, elementId;		ElementValue ref;		IndexQuery query;		ArrayList values;		Value val[];		String name;		Collection current;		Int2ObjectAVLTreeMap map = new Int2ObjectAVLTreeMap();		Occurrences oc;		VariableByteInputStream is;		int docId;		int len;		final Lock lock = elementsDb.getLock();		for (Iterator i = collections.iterator(); i.hasNext();) {			current = (Collection) i.next();			collectionId = current.getId();			ref = new ElementValue(ElementValue.ELEMENT, collectionId);			query = new IndexQuery(IndexQuery.TRUNC_RIGHT, ref);			try {				lock.acquire();				values = elementsDb.findEntries(query);				for (Iterator j = values.iterator(); j.hasNext();) {					val = (Value[]) j.next();					elementId = ByteConversion.byteToShort(val[0].getData(), 2);					name = NativeBroker.getSymbols().getName(elementId);					oc = (Occurrences) map.get(elementId);					if (oc == null) {						oc = new Occurrences(name);						map.put(elementId, oc);					}					is =						new VariableByteInputStream(							val[1].data(),							val[1].start(),							val[1].length());					try {						while (is.available() > 0) {							docId = is.readInt();							len = is.readInt();							oc.addOccurrences(len);							is.skip(len * 4);						}					} catch (EOFException e) {					} catch (IOException e) {						LOG.warn("unexpected exception", e);					}				}			} catch (BTreeException e) {				LOG.warn("exception while reading element index", e);			} catch (IOException e) {				LOG.warn("exception while reading element index", e);			} catch (LockException e) {				LOG.warn("failed to acquire lock", e);			} finally {				lock.release();			}		}		Occurrences[] result = new Occurrences[map.size()];		return (Occurrences[]) map.values().toArray(result);	}