/** * Return the number of bundles being tracked by this {@code BundleTracker}. * * @return The number of bundles being tracked. */ public int size() { final Tracked t = tracked(); if (t == null) { /* if BundleTracker is not open */ return 0; } synchronized (t) { return t.size(); } }
/** * Returns the customized object for the specified {@code Bundle} if the * specified bundle is being tracked by this {@code BundleTracker}. * * @param bundle The {@code Bundle} being tracked. * @return The customized object for the specified {@code Bundle} or * {@code null} if the specified {@code Bundle} is not being * tracked. */ public T getObject(Bundle bundle) { final Tracked t = tracked(); if (t == null) { /* if BundleTracker is not open */ return null; } synchronized (t) { return t.getCustomizedObject(bundle); } }
/** * Return if this {@code BundleTracker} is empty. * * @return {@code true} if this {@code BundleTracker} is not tracking any * bundles. * @since 1.5 */ public boolean isEmpty() { final Tracked t = tracked(); if (t == null) { /* if BundleTracker is not open */ return true; } synchronized (t) { return t.isEmpty(); } }
/** * Remove a bundle from this {@code BundleTracker}. * * The specified bundle will be removed from this {@code BundleTracker} . If * the specified bundle was being tracked then the * {@code BundleTrackerCustomizer.removedBundle} method will be called for * that bundle. * * @param bundle The {@code Bundle} to be removed. */ public void remove(Bundle bundle) { final Tracked t = tracked(); if (t == null) { /* if BundleTracker is not open */ return; } t.untrack(bundle, null); }
/** * Return a {@code Map} with the {@code Bundle}s and customized objects for * all bundles being tracked by this {@code BundleTracker}. * * @return A {@code Map} with the {@code Bundle}s and customized objects for * all services being tracked by this {@code BundleTracker}. If no * bundles are being tracked, then the returned map is empty. * @since 1.5 */ public Map<Bundle, T> getTracked() { Map<Bundle, T> map = new HashMap<Bundle, T>(); final Tracked t = tracked(); if (t == null) { /* if BundleTracker is not open */ return map; } synchronized (t) { return t.copyEntries(map); } }
/** * Returns the tracking count for this {@code BundleTracker}. * * The tracking count is initialized to 0 when this {@code BundleTracker} is * opened. Every time a bundle is added, modified or removed from this * {@code BundleTracker} the tracking count is incremented. * * <p> * The tracking count can be used to determine if this {@code BundleTracker} * has added, modified or removed a bundle by comparing a tracking count * value previously collected with the current tracking count value. If the * value has not changed, then no bundle has been added, modified or removed * from this {@code BundleTracker} since the previous tracking count was * collected. * * @return The tracking count for this {@code BundleTracker} or -1 if this * {@code BundleTracker} is not open. */ public int getTrackingCount() { final Tracked t = tracked(); if (t == null) { /* if BundleTracker is not open */ return -1; } synchronized (t) { return t.getTrackingCount(); } }
/** * Return an array of {@code Bundle}s for all bundles being tracked by this * {@code BundleTracker}. * * @return An array of {@code Bundle}s or {@code null} if no bundles are * being tracked. */ public Bundle[] getBundles() { final Tracked t = tracked(); if (t == null) { /* if BundleTracker is not open */ return null; } synchronized (t) { int length = t.size(); if (length == 0) { return null; } return t.copyKeys(new Bundle[length]); } }