@@ -44,7 +44,9 @@ This file is part of the iText (R) project.
44
44
package com .itextpdf .kernel .log ;
45
45
46
46
import java .util .ArrayList ;
47
+ import java .util .HashSet ;
47
48
import java .util .List ;
49
+ import java .util .Set ;
48
50
49
51
/**
50
52
* Manager that works with {@link ICounterFactory}. Create {@link ICounter} for each registered {@link ICounterFactory}
@@ -65,9 +67,9 @@ public class CounterManager {
65
67
private static CounterManager instance = new CounterManager ();
66
68
67
69
/**
68
- * List of all registered factories.
70
+ * All registered factories.
69
71
*/
70
- private List <ICounterFactory > factories = new ArrayList <>();
72
+ private Set <ICounterFactory > factories = new HashSet <>();
71
73
72
74
private CounterManager () {
73
75
register (new SimpleCounterFactory (new DefaultCounter ()));
@@ -95,7 +97,7 @@ public List<ICounter> getCounters(Class<?> cls) {
95
97
}
96
98
97
99
/**
98
- * Register new {@link ICounterFactory}.
100
+ * Register new {@link ICounterFactory}. Does nothing if same factory was already registered.
99
101
*
100
102
* @param factory {@link ICounterFactory} to be registered
101
103
*/
@@ -105,5 +107,16 @@ public void register(ICounterFactory factory) {
105
107
}
106
108
}
107
109
108
-
110
+ /**
111
+ * Unregister specified {@link ICounterFactory}. Does nothing if this factory wasn't registered first.
112
+ *
113
+ * @param factory {@link ICounterFactory} to be unregistered
114
+ * @return {@code true} if specified factory was registered first
115
+ */
116
+ public boolean unregister (ICounterFactory factory ) {
117
+ if (factory != null ) {
118
+ return factories .remove (factory );
119
+ }
120
+ return false ;
121
+ }
109
122
}
0 commit comments