1 package org.sf.jlaunchpad.util;
2
3 import java.util.HashMap;
4 import java.text.MessageFormat;
5
6
7
8
9
10
11 public class FormatElement {
12
13
14
15 protected String value;
16
17 private static HashMap<String, MessageFormat> formatMap = new HashMap<String, MessageFormat>();
18 private static final String CHECKSUM = "CHECKSUM";
19 private static final String MD5SUM = "MD5SUM";
20 private static final String SVF = "SVF";
21
22 static {
23 formatMap.put(CHECKSUM, new MessageFormat("{0}"));
24 formatMap.put(MD5SUM, new MessageFormat("{0} *{1}"));
25 formatMap.put(SVF, new MessageFormat("MD5 ({1}) = {0}"));
26 }
27
28
29
30
31 public FormatElement() {
32 super();
33 }
34
35
36
37
38 public final void setValue(String value) {
39
40
41
42
43
44
45 this.value = value;
46 }
47
48
49
50
51
52
53
54
55
56 public final int indexOfValue(String value) {
57 String[] values = getValues();
58 if (values == null || value == null) {
59 return -1;
60 }
61 for (int i = 0; i < values.length; i++) {
62 if (value.equals(values[i])) {
63 return i;
64 }
65 }
66 return -1;
67 }
68
69
70
71
72 public final String getValue() {
73 return value;
74 }
75
76
77
78
79
80
81 public static FormatElement getDefault() {
82 FormatElement e = new FormatElement();
83 e.setValue(CHECKSUM);
84 return e;
85 }
86
87
88
89
90
91
92 public MessageFormat getFormat() {
93 return formatMap.get(getValue());
94 }
95
96
97
98
99
100
101 public String[] getValues() {
102 return new String[]{CHECKSUM, MD5SUM, SVF};
103 }
104
105 }