Package it.unive.lisa.logging
Class Counter
- java.lang.Object
-
- it.unive.lisa.logging.Counter
-
public final class Counter extends java.lang.ObjectA counter that logs to a given logger while progressing during the count.
-
-
Constructor Summary
Constructors Constructor Description Counter(org.apache.logging.log4j.Logger logger, org.apache.logging.log4j.Level level, java.lang.String message, java.lang.String objects, int cap, double updateFactor)Builds the counter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcount()Progresses the count by one.intgetCurrentCount()Yields the current count of this counter.booleanisLogging()Yieldstrueif this counter is currently logging updates.voidoff()Turns off the counter, logging the event.voidon()Turns on the counter, logging the event.
-
-
-
Constructor Detail
-
Counter
public Counter(org.apache.logging.log4j.Logger logger, org.apache.logging.log4j.Level level, java.lang.String message, java.lang.String objects, int cap, double updateFactor)Builds the counter. Ifcapis less than1orupdateFactoris negative, eachcount()call will cause a new message to be logged. Otherwise, a message will be logged everymax(1, cap * updateFactor)count()call.- Parameters:
logger- the logger to log ontolevel- the level to log atmessage- the message to display while countingobjects- the objects being countedcap- the cap of the count, meaning the expected maximum numberupdateFactor- the percentage ofcapto use as interval between different log updates
-
-
Method Detail
-
getCurrentCount
public int getCurrentCount()
Yields the current count of this counter.- Returns:
- the current count
-
on
public void on()
Turns on the counter, logging the event.- Throws:
java.lang.IllegalStateException- if the counter is already logging
-
isLogging
public boolean isLogging()
Yieldstrueif this counter is currently logging updates.- Returns:
trueif that condition holds
-
count
public void count()
Progresses the count by one.
-
off
public void off()
Turns off the counter, logging the event.
-
-