Skip to content

Commit d4be5d1

Browse files
committed
Add some documentation to Wrapper.java
1 parent b0d14c6 commit d4be5d1

1 file changed

Lines changed: 128 additions & 23 deletions

File tree

  • src/main/java/com/github/theholywaffle/teamspeak3/api/wrapper

src/main/java/com/github/theholywaffle/teamspeak3/api/wrapper/Wrapper.java

Lines changed: 128 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,80 +30,185 @@
3030

3131
import java.util.Map;
3232

33+
/**
34+
* A wrapper class around a {@link Map}.
35+
* <p>
36+
* We use wrapper classes instead of just passing around plain Maps because
37+
* </p><ul>
38+
* <li>it's more descriptive</li>
39+
* <li>there's no confusion between types (e.g. {@code Client} and {@code Channel})</li>
40+
* <li>we can create getters for the specific use-cases</li>
41+
* <li>we don't have to check for {@code null} each time</li>
42+
* </ul>
43+
*/
3344
public class Wrapper {
3445

3546
private final Map<String, String> map;
3647

48+
/**
49+
* Creates a new wrapper around the given map.
50+
*
51+
* @param map
52+
* the Map to abstract, cannot be {@code null}
53+
*/
3754
public Wrapper(Map<String, String> map) {
3855
this.map = map;
3956
}
4057

58+
/**
59+
* Gets the map underlying this {@code Wrapper}.
60+
*
61+
* @return the underlying map
62+
*/
4163
public Map<String, String> getMap() {
4264
return map;
4365
}
4466

45-
public boolean getBoolean(String str) {
46-
return getInt(str) == 1;
67+
/**
68+
* Gets a property as a boolean from the underlying map.
69+
* Returns {@code true} if the property exists in the map and its value is {@code "1"}.
70+
*
71+
* @param propertyName
72+
* the name of the property
73+
*
74+
* @return the boolean value of the property or {@code false} if the property doesn't exist
75+
*/
76+
public boolean getBoolean(String propertyName) {
77+
return getInt(propertyName) == 1;
4778
}
4879

49-
public boolean getBoolean(Property p) {
50-
return getBoolean(p.getName());
80+
/**
81+
* Gets a property as a boolean from the underlying map.
82+
* Returns {@code true} if the property exists in the map and its value is {@code "1"}.
83+
*
84+
* @param property
85+
* the property
86+
*
87+
* @return the boolean value of the property or {@code false} if the property doesn't exist
88+
*/
89+
public boolean getBoolean(Property property) {
90+
return getBoolean(property.getName());
5191
}
5292

53-
public double getDouble(String str) {
54-
final String value = get(str);
93+
/**
94+
* Gets a property as a double from the underlying map.
95+
* If the property doesn't exist in the underlying map, {@code -1.0} is returned.
96+
*
97+
* @param propertyName
98+
* the name of the property
99+
*
100+
* @return the double value of the property or {@code -1.0} if the property doesn't exist
101+
*/
102+
public double getDouble(String propertyName) {
103+
final String value = get(propertyName);
55104
if (value == null || value.isEmpty()) {
56105
return -1D;
57106
}
58107
return Double.valueOf(value);
59108
}
60109

61-
public double getDouble(Property p) {
62-
return getDouble(p.getName());
110+
/**
111+
* Gets a property as a double from the underlying map.
112+
* If the property doesn't exist in the underlying map, {@code -1.0} is returned.
113+
*
114+
* @param property
115+
* the property
116+
*
117+
* @return the double value of the property or {@code -1.0} if the property doesn't exist
118+
*/
119+
public double getDouble(Property property) {
120+
return getDouble(property.getName());
63121
}
64122

65-
public long getLong(String str) {
66-
final String value = get(str);
123+
/**
124+
* Gets a property as a long from the underlying map.
125+
* If the property doesn't exist in the underlying map, {@code -1} is returned.
126+
*
127+
* @param propertyName
128+
* the name of the property
129+
*
130+
* @return the long value of the property or {@code -1} if the property doesn't exist
131+
*/
132+
public long getLong(String propertyName) {
133+
final String value = get(propertyName);
67134
if (value == null || value.isEmpty()) {
68135
return -1L;
69136
}
70137
return Long.valueOf(value);
71138
}
72139

73-
public long getLong(Property p) {
74-
return getLong(p.getName());
140+
/**
141+
* Gets a property as a long from the underlying map.
142+
* If the property doesn't exist in the underlying map, {@code -1} is returned.
143+
*
144+
* @param property
145+
* the property
146+
*
147+
* @return the long value of the property or {@code -1} if the property doesn't exist
148+
*/
149+
public long getLong(Property property) {
150+
return getLong(property.getName());
75151
}
76152

77-
public int getInt(String str) {
78-
final String value = get(str);
153+
/**
154+
* Gets a property as an integer from the underlying map.
155+
* If the property doesn't exist in the underlying map, {@code -1} is returned.
156+
*
157+
* @param propertyName
158+
* the name of the property
159+
*
160+
* @return the integer value of the property or {@code -1} if the property doesn't exist
161+
*/
162+
public int getInt(String propertyName) {
163+
final String value = get(propertyName);
79164
if (value == null || value.isEmpty()) {
80165
return -1;
81166
}
82167
return Integer.valueOf(value);
83168
}
84169

85-
public int getInt(Property p) {
86-
return getInt(p.getName());
170+
/**
171+
* Gets a property as an integer from the underlying map.
172+
* If the property doesn't exist in the underlying map, {@code -1} is returned.
173+
*
174+
* @param property
175+
* the property
176+
*
177+
* @return the integer value of the property or {@code -1} if the property doesn't exist
178+
*/
179+
public int getInt(Property property) {
180+
return getInt(property.getName());
87181
}
88182

89183
/**
90-
* Only use this if you know what you are doing.
184+
* Gets a property as a String from the underlying map.
185+
* If the property doesn't exist in the underlying map, an empty String is returned.
186+
*
187+
* @param propertyName
188+
* the name of the property
189+
*
190+
* @return the String value of the property or an empty String if the property doesn't exist
91191
*/
92-
public String get(String str) {
93-
final String result = map.get(str);
192+
public String get(String propertyName) {
193+
final String result = map.get(propertyName);
94194
return result != null ? result : "";
95195
}
96196

97197
/**
98-
* Only use this if you know what you are doing.
198+
* Gets a property as a {@code String} from the underlying map.
199+
* If the property doesn't exist in the underlying map, an empty String is returned.
200+
*
201+
* @param property
202+
* the property
203+
*
204+
* @return the String value of the property or an empty String if the property doesn't exist
99205
*/
100-
public String get(Property p) {
101-
return get(p.getName());
206+
public String get(Property property) {
207+
return get(property.getName());
102208
}
103209

104210
@Override
105211
public String toString() {
106212
return map.toString();
107213
}
108-
109214
}

0 commit comments

Comments
 (0)