TSelf
- the type of this statisticpublic abstract class Statistics<TSelf extends Statistics<TSelf>>
extends java.lang.Object
implements java.io.Serializable
Modifier and Type | Field and Description |
---|---|
protected Statistics<TSelf> |
replaceWith
Serialization replacement object
|
Modifier | Constructor and Description |
---|---|
protected |
Statistics(java.lang.String name)
Creates instance of Statistics with filled internal data
|
Modifier and Type | Method and Description |
---|---|
protected void |
addBoundStat(TSelf stat)
Bind a statistic to this statistic.
|
void |
bindTo(TSelf object)
Bind this statistic to the given one.
|
protected boolean |
canPerformOperation()
Check if this statistic can update itself.
|
protected abstract TSelf |
cast()
Returns this statistics as the type provided typed argument.
|
static void |
disableGlobally()
Disables all statistic counting globally.
|
static void |
enableGlobally()
Enables all statistic counting globally.
|
static java.util.Iterator<Statistics<?>> |
getAllStatistics()
Returns an iterator over all global statistics.
|
static java.util.Iterator<Statistics<?>> |
getAllStatistics(java.lang.String regex)
Returns an iterator over all global statistics with
names matching the provided regular expression.
|
protected java.util.Set<TSelf> |
getBoundStats()
Returns a set of all statistics that are bound to this one.
|
protected TSelf |
getBoundTo()
Returns the statistic that this stat is bound to.
|
java.lang.String |
getName()
Returns the registered name of this statistic.
|
static Statistics<?> |
getStatistics(java.lang.String statisticName)
Returns a registered global statistic.
|
static <T extends Statistics<? extends T>> |
getStatistics(java.lang.String statisticName,
java.lang.Class<? extends T> statisticClass)
Returns a registered global statistic.
|
abstract java.lang.Object |
getValue()
Returns the value of this statistic.
|
protected boolean |
isBound()
Returns true if this statistic is bound to another one.
|
static boolean |
isEnabledGlobally()
Returns true if statistics are globally enabled.
|
protected boolean |
isRegisteredGlobally()
Returns true if this statistic is present in global statistics registry.
|
static java.lang.String |
printStatistics()
Returns a string containing current states of all global statistics.
|
static java.lang.String |
printStatistics(java.lang.String regex)
Returns a string containing current states of global statistics with
names matching the provided regular expression.
|
static java.lang.String |
printStatistics(java.lang.String regex,
java.lang.String statSeparator)
Returns a string containing current states of global statistics with
names matching the provided regular expression and separated by specified separator.
|
protected java.lang.Object |
readResolve()
Deserialization method to replace the object with a global statistic's one.
|
protected void |
removeBoundStat(TSelf stat)
Remove a bound statistic from this one.
|
static boolean |
removeStatistic(java.lang.String name)
Remove the statistic from global registry.
|
abstract void |
reset()
Reset the value of this statistic.
|
static void |
resetStatistics()
Resets all statistics.
|
static void |
resetStatistics(java.lang.String regex)
Resets statistics matching the regular expression.
|
protected abstract void |
setFrom(TSelf sourceStat)
Set the value of this statistic to the actual value of the given
sourceStat . |
void |
unbind()
Deregister this statistic from the "parent" statistic it is bound to.
|
protected abstract void |
updateFrom(TSelf sourceStat)
Updates the value of this statistic from the given
sourceStat . |
protected transient Statistics<TSelf extends Statistics<TSelf>> replaceWith
protected Statistics(java.lang.String name)
name
- the name of this statpublic static <T extends Statistics<? extends T>> T getStatistics(java.lang.String statisticName, java.lang.Class<? extends T> statisticClass) throws java.lang.IllegalArgumentException, java.lang.ClassCastException
T
- the type of the statistic to getstatisticName
- the name of the statistic to getstatisticClass
- the type of the statistic to getjava.lang.IllegalArgumentException
- if the statistics of the given name does not exist and cannot be createdjava.lang.ClassCastException
- if the statistics of the given name exists, but is not instance of statisticClass
public static Statistics<?> getStatistics(java.lang.String statisticName)
statisticName
- the name of the statistic to getpublic java.lang.String getName()
public abstract java.lang.Object getValue()
protected TSelf getBoundTo()
protected boolean isBound()
protected abstract TSelf cast()
protected abstract void updateFrom(TSelf sourceStat)
sourceStat
.
Specifically, this method merges the value of the sourceStat
with this statistic.
The actual implementation depends on the type of the statistic.
sourceStat
- the statistic from which to update this statprotected abstract void setFrom(TSelf sourceStat)
sourceStat
.sourceStat
- the statistic from which to set this statpublic abstract void reset()
protected void addBoundStat(TSelf stat)
stat
to receive notifications when
the value of this statistic is updated.stat
- the statistic to registerprotected void removeBoundStat(TSelf stat)
stat
- the statistic to unbindprotected final java.util.Set<TSelf> getBoundStats()
public void unbind()
public void bindTo(TSelf object) throws java.lang.IllegalArgumentException
object
- the statistic to which this statistic should be bound tojava.lang.IllegalArgumentException
- if this statistic is already bound to another statprotected final boolean canPerformOperation()
public static final boolean isEnabledGlobally()
public static void disableGlobally()
public static void enableGlobally()
protected java.lang.Object readResolve() throws java.io.ObjectStreamException
java.io.ObjectStreamException
- if there was an error (not thrown by this implementation)protected boolean isRegisteredGlobally()
public static boolean removeStatistic(java.lang.String name)
name
- name of the statisticpublic static void resetStatistics()
public static void resetStatistics(java.lang.String regex)
regex
- the regular expression that matches the names of statistics to resetpublic static java.lang.String printStatistics(java.lang.String regex, java.lang.String statSeparator)
regex
- the regular expression that matches the names of statistics to usestatSeparator
- the string that separates the respective statistics (can be newline)public static java.lang.String printStatistics(java.lang.String regex)
regex
- the regular expression that matches the names of statistics to usepublic static java.lang.String printStatistics()
public static java.util.Iterator<Statistics<?>> getAllStatistics()
public static java.util.Iterator<Statistics<?>> getAllStatistics(java.lang.String regex)
regex
- the regular expression that matches the names of statistics to use