File: TipDefinition.java

package info (click to toggle)
gpsprune 17-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,984 kB
  • ctags: 5,218
  • sloc: java: 39,403; sh: 25; makefile: 17; python: 15
file content (66 lines) | stat: -rw-r--r-- 1,298 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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;
	}
}