1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.esigate.util;
17
18 import java.util.Properties;
19
20
21
22
23
24
25
26 public abstract class Parameter<T> {
27 private final String name;
28 private final T defaultValue;
29
30 @Override
31 public boolean equals(Object obj) {
32 boolean equals = false;
33 if (obj != null) {
34 if (obj instanceof Parameter) {
35 equals = this.name.equals(((Parameter<?>) obj).getName());
36 } else if (obj instanceof String) {
37 equals = this.name.equals(obj);
38 }
39 }
40 return equals;
41 }
42
43 @Override
44 public String toString() {
45 return this.name;
46 }
47
48 @Override
49 public int hashCode() {
50 return this.name.hashCode();
51 }
52
53 public Parameter(String name) {
54 this(name, null);
55 }
56
57 Parameter(String name, T defaultValue) {
58 this.name = name;
59 this.defaultValue = defaultValue;
60
61 }
62
63 public String getName() {
64 return name;
65 }
66
67 public T getDefaultValue() {
68 return defaultValue;
69 }
70
71 public T getValue(Properties properties) {
72 T value = (T) properties.getProperty(this.name);
73
74 if (value == null) {
75 value = defaultValue;
76 }
77 return value;
78 }
79
80 }