|
|
@@ -1,13 +1,10 @@
|
|
|
package info.knacki.prometheusandroidexporter;
|
|
|
|
|
|
-import androidx.annotation.NonNull;
|
|
|
-
|
|
|
import java.util.Collection;
|
|
|
import java.util.HashMap;
|
|
|
-import java.util.Iterator;
|
|
|
import java.util.Map;
|
|
|
|
|
|
-public class CollectorManager implements Iterable<CollectorValue> {
|
|
|
+public class CollectorManager {
|
|
|
private static CollectorManager sInstance = null;
|
|
|
private final HashMap<String, ICollector> fCollectors;
|
|
|
private HashMap<String, Collection<CollectorValue>> fValues;
|
|
|
@@ -41,26 +38,14 @@ public class CollectorManager implements Iterable<CollectorValue> {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @NonNull
|
|
|
- @Override
|
|
|
- public Iterator<CollectorValue> iterator() {
|
|
|
- return new Iterator<CollectorValue>() {
|
|
|
- private final Iterator<Map.Entry<String, Collection<CollectorValue>>> mainIterator = fValues.entrySet().iterator();
|
|
|
- private Iterator<CollectorValue> secondIterator = null;
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean hasNext() {
|
|
|
- if (secondIterator == null)
|
|
|
- return mainIterator.hasNext();
|
|
|
- return secondIterator.hasNext() || mainIterator.hasNext();
|
|
|
- }
|
|
|
+ public interface Runnable {
|
|
|
+ void Run(CollectorValue value);
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
- public CollectorValue next() {
|
|
|
- if (secondIterator == null || secondIterator.hasNext())
|
|
|
- secondIterator = mainIterator.next().getValue().iterator();
|
|
|
- return secondIterator.next();
|
|
|
- }
|
|
|
- };
|
|
|
+ public void forEach(Runnable action) {
|
|
|
+ for (Map.Entry<String, Collection<CollectorValue>> i: fValues.entrySet()) {
|
|
|
+ for (CollectorValue j: i.getValue())
|
|
|
+ action.Run(j);
|
|
|
+ }
|
|
|
}
|
|
|
}
|