File: Describer.java

package info (click to toggle)
gpsprune 26.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,824 kB
  • sloc: java: 52,154; sh: 25; makefile: 21; python: 15
file content (49 lines) | stat: -rw-r--r-- 1,305 bytes parent folder | download | duplicates (4)
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
package tim.prune.function;

import tim.prune.I18nManager;

/**
 * Class to build descriptions using singular and plural versions of a token
 */
public class Describer
{
	private final String _singularToken;
	private final String _pluralToken;

	public Describer(String inSingularToken, String inPluralToken)
	{
		_singularToken = inSingularToken;
		_pluralToken = inPluralToken;
	}

	public String getDescriptionWithNameOrCount(String inName, int inCount)
	{
		if (inCount == 1) {
			return I18nManager.getText(_singularToken, inName == null ? "" : inName);
		}
		else if (inCount > 1) {
			return I18nManager.getTextWithNumber(_pluralToken, inCount);
		}
		throw new IllegalArgumentException("Count should not be <= 0");
	}

	public String getDescriptionWithCount(int inCount)
	{
		if (inCount == 1) {
			return I18nManager.getText(_singularToken);
		}
		else if (inCount > 1) {
			return I18nManager.getTextWithNumber(_pluralToken, inCount);
		}
		throw new IllegalArgumentException("Count should not be <= 0");
	}

	public String getDescriptionWithNameOrNot(String inName)
	{
		// We use singular and plural here, but it means without name and with
		if (inName == null || inName.isEmpty()) {
			return I18nManager.getText(_singularToken);
		}
		return I18nManager.getText(_pluralToken, inName);
	}
}