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
|
package cgeo.geocaching.enumerations;
import cgeo.geocaching.R;
import cgeo.geocaching.cgeoapplication;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/**
* Enum listing cache sizes
*/
public enum CacheSize {
MICRO("Micro", 1, R.string.cache_size_micro),
SMALL("Small", 2, R.string.cache_size_small),
REGULAR("Regular", 3, R.string.cache_size_regular),
LARGE("Large", 4, R.string.cache_size_large),
VIRTUAL("Virtual", 0, R.string.cache_size_virtual),
NOT_CHOSEN("Not chosen", 0, R.string.cache_size_notchosen),
OTHER("Other", 0, R.string.cache_size_other),
UNKNOWN("Unknown", 0, R.string.cache_size_unknown); // CacheSize not init. yet
public final String id;
public final int comparable;
private final int stringId;
private CacheSize(String id, int comparable, int stringId) {
this.id = id;
this.comparable = comparable;
this.stringId = stringId;
}
final private static Map<String, CacheSize> FIND_BY_ID;
static {
final HashMap<String, CacheSize> mapping = new HashMap<String, CacheSize>();
for (CacheSize cs : values()) {
mapping.put(cs.id.toLowerCase(), cs);
}
FIND_BY_ID = Collections.unmodifiableMap(mapping);
}
public static CacheSize getById(final String id) {
if (id == null) {
return UNKNOWN;
}
// avoid String operations for performance reasons
final CacheSize result = CacheSize.FIND_BY_ID.get(id);
if (result != null) {
return result;
}
// only if String was not found, normalize it
final CacheSize resultNormalized = CacheSize.FIND_BY_ID.get(id.toLowerCase().trim());
if (resultNormalized != null) {
return resultNormalized;
}
return UNKNOWN;
}
public final String getL10n() {
return cgeoapplication.getInstance().getBaseContext().getResources().getString(stringId);
}
}
|