[EGIT PATCH 02/11] Use Set instead of array to keep track of change listeners

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Also, add method for removing listeners, and remove unused
private method for getting the current listeners.

Signed-off-by: Tor Arne Vestbø <torarnv@xxxxxxxxx>
---
 .../spearce/egit/core/project/GitProjectData.java  |   33 +++++++++-----------
 1 files changed, 15 insertions(+), 18 deletions(-)

diff --git a/org.spearce.egit.core/src/org/spearce/egit/core/project/GitProjectData.java b/org.spearce.egit.core/src/org/spearce/egit/core/project/GitProjectData.java
index db5f20b..4ca4f8e 100644
--- a/org.spearce.egit.core/src/org/spearce/egit/core/project/GitProjectData.java
+++ b/org.spearce.egit.core/src/org/spearce/egit/core/project/GitProjectData.java
@@ -52,7 +52,7 @@
 
 	private static final Map<File, WeakReference> repositoryCache = new HashMap<File, WeakReference>();
 
-	private static RepositoryChangeListener[] repositoryChangeListeners = {};
+	private static Set<RepositoryChangeListener> repositoryChangeListeners = new HashSet<RepositoryChangeListener>();
 
 	@SuppressWarnings("synthetic-access")
 	private static final IResourceChangeListener rcl = new RCL();
@@ -112,16 +112,18 @@ public static synchronized void addRepositoryChangeListener(
 			final RepositoryChangeListener objectThatCares) {
 		if (objectThatCares == null)
 			throw new NullPointerException();
-		for (int k = repositoryChangeListeners.length - 1; k >= 0; k--) {
-			if (repositoryChangeListeners[k] == objectThatCares)
-				return;
-		}
-		final int p = repositoryChangeListeners.length;
-		final RepositoryChangeListener[] n;
-		n = new RepositoryChangeListener[p + 1];
-		System.arraycopy(repositoryChangeListeners, 0, n, 0, p);
-		n[p] = objectThatCares;
-		repositoryChangeListeners = n;
+		repositoryChangeListeners.add(objectThatCares);
+	}
+
+	/**
+	 * Remove a registered {@link RepositoryChangeListener}
+	 * 
+	 * @param objectThatCares
+	 *            The listener to remove
+	 */
+	public static synchronized void removeRepositoryChangeListener(
+			final RepositoryChangeListener objectThatCares) {
+		repositoryChangeListeners.remove(objectThatCares);
 	}
 
 	/**
@@ -131,13 +133,8 @@ public static synchronized void addRepositoryChangeListener(
 	 *            the repository which has had changes occur within it.
 	 */
 	static void fireRepositoryChanged(final RepositoryMapping which) {
-		final RepositoryChangeListener[] e = getRepositoryChangeListeners();
-		for (int k = e.length - 1; k >= 0; k--)
-			e[k].repositoryChanged(which);
-	}
-
-	private static synchronized RepositoryChangeListener[] getRepositoryChangeListeners() {
-		return repositoryChangeListeners;
+		for (RepositoryChangeListener listener : repositoryChangeListeners)
+			listener.repositoryChanged(which);
 	}
 
 	/**
-- 
1.6.1.2.309.g2ea3

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux