Class 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()
      Yields true 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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. If cap is less than 1 or updateFactor is negative, each count() call will cause a new message to be logged. Otherwise, a message will be logged every max(1, cap * updateFactor) count() call.
        Parameters:
        logger - the logger to log onto
        level - the level to log at
        message - the message to display while counting
        objects - the objects being counted
        cap - the cap of the count, meaning the expected maximum number
        updateFactor - the percentage of cap 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()
        Yields true 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.