From: "Tor Arne Vestbø" <torarnv@gmail.com>
To: "Shawn O. Pearce" <spearce@spearce.org>,
Robin Rosenberg <robin.rosenberg@dewire.com>
Cc: git@vger.kernel.org
Subject: [EGIT PATCH 02/11 v2] Use Set instead of array to keep track of change listeners
Date: Thu, 5 Feb 2009 19:28:38 +0100 [thread overview]
Message-ID: <1233858518-21563-1-git-send-email-torarnv@gmail.com> (raw)
In-Reply-To: <498B159B.4040001@gmail.com>
Also, add method for removing listeners.
Signed-off-by: Tor Arne Vestbø <torarnv@gmail.com>
---
.../spearce/egit/core/project/GitProjectData.java | 40 ++++++++++++-------
1 files changed, 25 insertions(+), 15 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..b12a85f 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,21 @@ 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);
+ for (RepositoryChangeListener listener : getRepositoryChangeListeners())
+ listener.repositoryChanged(which);
}
+ /**
+ * Get a copy of the current set of repository change listeners
+ * <p>
+ * The array has no references, so is safe for iteration and modification
+ *
+ * @return a copy of the current repository change listeners
+ */
private static synchronized RepositoryChangeListener[] getRepositoryChangeListeners() {
- return repositoryChangeListeners;
+ return repositoryChangeListeners
+ .toArray(new RepositoryChangeListener[repositoryChangeListeners
+ .size()]);
}
/**
--
1.6.1.2.309.g2ea3
next prev parent reply other threads:[~2009-02-05 18:29 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-05 1:00 [EGIT PATCH 00/11] Support customizable label decorations Tor Arne Vestbø
2009-02-05 1:00 ` [EGIT PATCH 01/11] Add support code to handle plugin property changes Tor Arne Vestbø
2009-02-05 1:00 ` [EGIT PATCH 02/11] Use Set instead of array to keep track of change listeners Tor Arne Vestbø
2009-02-05 1:00 ` [EGIT PATCH 03/11] Add a specialized team exception for Git Tor Arne Vestbø
2009-02-05 1:00 ` [EGIT PATCH 04/11] Add new class ExceptionCollector for grouping exceptions Tor Arne Vestbø
2009-02-05 1:00 ` [EGIT PATCH 05/11] Add new class SWTUtils with helper-methods for creating controls Tor Arne Vestbø
2009-02-05 1:00 ` [EGIT PATCH 06/11] Implement basic customizable label decorations with preferences Tor Arne Vestbø
2009-02-05 1:00 ` [EGIT PATCH 07/11] Add binding for name of the current branch Tor Arne Vestbø
2009-02-05 1:00 ` [EGIT PATCH 08/11] Add icon decoration for tracked and untracked resources Tor Arne Vestbø
2009-02-05 1:00 ` [EGIT PATCH 09/11] Implement decorations of dirty, staged, and conflicting resources Tor Arne Vestbø
2009-02-05 1:00 ` [EGIT PATCH 10/11] Don't decorate every single resource on repository change Tor Arne Vestbø
2009-02-05 1:00 ` [EGIT PATCH 11/11] Implement label decorations for folders and projects Tor Arne Vestbø
2009-02-05 20:02 ` [EGIT PATCH 06/11] Implement basic customizable label decorations with preferences Robin Rosenberg
2009-02-05 20:21 ` Tor Arne Vestbø
2009-02-05 21:00 ` Tor Arne Vestbø
2009-02-05 21:36 ` Robin Rosenberg
2009-02-05 21:44 ` Tor Arne Vestbø
2009-02-05 20:04 ` Robin Rosenberg
2009-02-05 15:48 ` [EGIT PATCH 02/11] Use Set instead of array to keep track of change listeners Shawn O. Pearce
2009-02-05 16:36 ` Tor Arne Vestbø
2009-02-05 18:28 ` Tor Arne Vestbø [this message]
2009-02-05 15:53 ` [EGIT PATCH 01/11] Add support code to handle plugin property changes Shawn O. Pearce
2009-02-05 16:35 ` Tor Arne Vestbø
2009-02-05 16:40 ` Shawn O. Pearce
2009-02-05 18:22 ` [EGIT PATCH v2] " Tor Arne Vestbø
2009-02-05 1:04 ` [EGIT PATCH 00/11] Support customizable label decorations Tor Arne Vestbø
2009-02-05 16:06 ` Shawn O. Pearce
2009-02-05 16:17 ` Tor Arne Vestbø
2009-02-05 18:32 ` Robin Rosenberg
2009-02-05 18:37 ` Tor Arne Vestbø
2009-02-05 22:09 ` Robin Rosenberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1233858518-21563-1-git-send-email-torarnv@gmail.com \
--to=torarnv@gmail.com \
--cc=git@vger.kernel.org \
--cc=robin.rosenberg@dewire.com \
--cc=spearce@spearce.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).