/** * Gets the contents of this DataWatcher as a map. * @return The contents */ public Map<Integer, WrappedWatchableObject> asMap() { return new ConvertedMap<Integer, Object, WrappedWatchableObject>(getMap()) { @Override protected WrappedWatchableObject toOuter(Object inner) { return inner != null ? new WrappedWatchableObject(inner) : null; } @Override protected Object toInner(WrappedWatchableObject outer) { return outer != null ? outer.getHandle() : null; } }; }
/** * Clears the contents of this DataWatcher. The watcher will be empty after * this operation is called. */ public void clear() { getMap().clear(); }
/** * Gets the size of this DataWatcher's contents. * @return The size */ public int size() { return getMap().size(); }
/** * Returns a set containing all the registered indexes * @return The set */ public Set<Integer> indexSet() { return getMap().keySet(); }
/** * Gets a set containing the registered indexes. * @return The set */ public Set<Integer> getIndexes() { return getMap().keySet(); }
/** * Removes the item at a given index. * * @param index Index to remove * @return The previous value, or null if none existed */ public WrappedWatchableObject remove(int index) { Object removed = getMap().remove(index); return removed != null ? new WrappedWatchableObject(removed) : null; }
/** * Gets the item at a given index. * * @param index Index to get * @return The watchable object, or null if none exists */ public WrappedWatchableObject getWatchableObject(int index) { Object handle = getMap().get(index); if (handle != null) { return new WrappedWatchableObject(handle); } else { return null; } }