Skip to content

Commit bc849c3

Browse files
committed
Support removal of counter factories
DEVSIX-1465
1 parent 873ad8c commit bc849c3

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

kernel/src/main/java/com/itextpdf/kernel/log/CounterManager.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ This file is part of the iText (R) project.
4444
package com.itextpdf.kernel.log;
4545

4646
import java.util.ArrayList;
47+
import java.util.HashSet;
4748
import java.util.List;
49+
import java.util.Set;
4850

4951
/**
5052
* Manager that works with {@link ICounterFactory}. Create {@link ICounter} for each registered {@link ICounterFactory}
@@ -65,9 +67,9 @@ public class CounterManager {
6567
private static CounterManager instance = new CounterManager();
6668

6769
/**
68-
* List of all registered factories.
70+
* All registered factories.
6971
*/
70-
private List<ICounterFactory> factories = new ArrayList<>();
72+
private Set<ICounterFactory> factories = new HashSet<>();
7173

7274
private CounterManager() {
7375
register(new SimpleCounterFactory(new DefaultCounter()));
@@ -95,7 +97,7 @@ public List<ICounter> getCounters(Class<?> cls) {
9597
}
9698

9799
/**
98-
* Register new {@link ICounterFactory}.
100+
* Register new {@link ICounterFactory}. Does nothing if same factory was already registered.
99101
*
100102
* @param factory {@link ICounterFactory} to be registered
101103
*/
@@ -105,5 +107,16 @@ public void register(ICounterFactory factory) {
105107
}
106108
}
107109

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+
}
109122
}

0 commit comments

Comments
 (0)