aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/pixart/messenger/utils')
-rw-r--r--src/main/java/de/pixart/messenger/utils/WeakReferenceSet.java26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/main/java/de/pixart/messenger/utils/WeakReferenceSet.java b/src/main/java/de/pixart/messenger/utils/WeakReferenceSet.java
new file mode 100644
index 000000000..b6ccbd560
--- /dev/null
+++ b/src/main/java/de/pixart/messenger/utils/WeakReferenceSet.java
@@ -0,0 +1,26 @@
+package de.pixart.messenger.utils;
+
+import java.lang.ref.WeakReference;
+import java.util.HashSet;
+import java.util.Iterator;
+
+public class WeakReferenceSet<T> extends HashSet<WeakReference<T>> {
+
+ public void removeWeakReferenceTo(T reference) {
+ for (Iterator<WeakReference<T>> iterator = iterator(); iterator.hasNext(); ) {
+ if (reference == iterator.next().get()) {
+ iterator.remove();
+ }
+ }
+ }
+
+
+ public void addWeakReferenceTo(T reference) {
+ for (WeakReference<T> weakReference : this) {
+ if (reference == weakReference.get()) {
+ return;
+ }
+ }
+ this.add(new WeakReference<>(reference));
+ }
+} \ No newline at end of file