X-Git-Url: http://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=src%2Ftim%2Fprune%2Ftips%2FTipDefinition.java;fp=src%2Ftim%2Fprune%2Ftips%2FTipDefinition.java;h=c58fe5ca85a179a4cf53395e634b00a1f1f7e7f7;hp=0000000000000000000000000000000000000000;hb=ce6f2161b8596f7018d6a76bff79bc9e571f35fd;hpb=2d8cb72e84d5cc1089ce77baf1e34ea3ea2f8465 diff --git a/src/tim/prune/tips/TipDefinition.java b/src/tim/prune/tips/TipDefinition.java new file mode 100644 index 0000000..c58fe5c --- /dev/null +++ b/src/tim/prune/tips/TipDefinition.java @@ -0,0 +1,66 @@ +package tim.prune.tips; + +/** + * Definition of a tip, including key and whether the tip + * has already been shown or not. + * This class is only visible within this package + */ +class TipDefinition +{ + /** Key of message to show when fired */ + private String _messageKey = null; + /** Threshold of calls before tip is shown */ + private int _threshold = 0; + /** Number of times this tip has been hit */ + private int _hitCount = 0; + /** Flag whether tip is active or has already been shown */ + private boolean _active = true; + + /** + * Constructor + * @param inKey key for message to show + */ + TipDefinition(String inKey) + { + this(inKey, 0); + } + + /** + * Constructor + * @param inKey message key + * @param inThreshold threshold + */ + TipDefinition(String inKey, int inThreshold) + { + _messageKey = inKey; + _threshold = inThreshold; + } + + /** + * Hit this definition and check the threshold + * @return true if the message should be shown + */ + boolean shouldShowMessage() + { + if (_active) + { + boolean overThreshold = (_hitCount >= _threshold); + if (!overThreshold) { + _hitCount++; + } + else { + _active = false; // only fire once + } + return overThreshold; + } + // not active + return false; + } + + /** + * @return message key + */ + String getMessageKey() { + return _messageKey; + } +}