Package it.unive.lisa.logging
Class Counter
- java.lang.Object
-
- it.unive.lisa.logging.Counter
-
public final class Counter extends java.lang.Object
A 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 void
count()
Progresses the count by one.int
getCurrentCount()
Yields the current count of this counter.boolean
isLogging()
Yieldstrue
if this counter is currently logging updates.void
off()
Turns off the counter, logging the event.void
on()
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. Ifcap
is less than1
orupdateFactor
is 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 ofcap
to 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()
Yieldstrue
if this counter is currently logging updates.- Returns:
true
if that condition holds
-
count
public void count()
Progresses the count by one.
-
off
public void off()
Turns off the counter, logging the event.
-
-