Skip to content

Commit 9ceb416

Browse files
committed
Minor code cleanup in Wrapper, DefaultArrayResponse, TS3ApiAsync
1 parent bd9c90b commit 9ceb416

File tree

3 files changed

+14
-21
lines changed

3 files changed

+14
-21
lines changed

src/main/java/com/github/theholywaffle/teamspeak3/TS3ApiAsync.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5189,10 +5189,9 @@ public CommandFuture<Void> uploadFileDirect(byte[] data, String filePath, boolea
51895189
* @see #downloadIcon(OutputStream, long)
51905190
*/
51915191
public CommandFuture<Long> uploadIcon(InputStream dataIn, long dataLength) {
5192-
FileTransferHelper helper = query.getFileTransferHelper();
51935192
byte[] data;
51945193
try {
5195-
data = helper.readFully(dataIn, dataLength);
5194+
data = FileTransferHelper.readFully(dataIn, dataLength);
51965195
} catch (IOException e) {
51975196
throw new TS3FileTransferFailedException("Reading stream failed", e);
51985197
}
@@ -5219,10 +5218,9 @@ public CommandFuture<Long> uploadIcon(InputStream dataIn, long dataLength) {
52195218
* @see #downloadIconDirect(long)
52205219
*/
52215220
public CommandFuture<Long> uploadIconDirect(byte[] data) {
5222-
FileTransferHelper helper = query.getFileTransferHelper();
52235221
CommandFuture<Long> future = new CommandFuture<>();
52245222

5225-
long iconId = helper.getIconId(data);
5223+
long iconId = FileTransferHelper.getIconId(data);
52265224
String path = "/icon_" + iconId;
52275225

52285226
uploadFileDirect(data, path, false, 0)

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

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@
4444
*/
4545
public class Wrapper {
4646

47-
public static final Wrapper EMPTY = new Wrapper(Collections.<String, String>emptyMap());
47+
/**
48+
* An empty wrapper whose getters will always return the default values
49+
* ({@code -1}, {@code false}, or {@code ""}).
50+
*/
51+
public static final Wrapper EMPTY = new Wrapper(Collections.emptyMap());
4852

4953
private final Map<String, String> map;
5054

@@ -103,11 +107,8 @@ public boolean getBoolean(Property property) {
103107
* @return the double value of the property or {@code -1.0} if the property doesn't exist
104108
*/
105109
public double getDouble(String propertyName) {
106-
final String value = get(propertyName);
107-
if (value == null || value.isEmpty()) {
108-
return -1D;
109-
}
110-
return Double.valueOf(value);
110+
String value = get(propertyName);
111+
return value.isEmpty() ? -1D : Double.parseDouble(value);
111112
}
112113

113114
/**
@@ -133,11 +134,8 @@ public double getDouble(Property property) {
133134
* @return the long value of the property or {@code -1} if the property doesn't exist
134135
*/
135136
public long getLong(String propertyName) {
136-
final String value = get(propertyName);
137-
if (value == null || value.isEmpty()) {
138-
return -1L;
139-
}
140-
return Long.parseLong(value);
137+
String value = get(propertyName);
138+
return value.isEmpty() ? -1L : Long.parseLong(value);
141139
}
142140

143141
/**
@@ -163,11 +161,8 @@ public long getLong(Property property) {
163161
* @return the integer value of the property or {@code -1} if the property doesn't exist
164162
*/
165163
public int getInt(String propertyName) {
166-
final String value = get(propertyName);
167-
if (value == null || value.isEmpty()) {
168-
return -1;
169-
}
170-
return Integer.parseInt(value);
164+
String value = get(propertyName);
165+
return value.isEmpty() ? -1 : Integer.parseInt(value);
171166
}
172167

173168
/**

src/main/java/com/github/theholywaffle/teamspeak3/commands/response/DefaultArrayResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private static Map<String, String> parseMap(String rawMap) {
9090
return map;
9191
}
9292

93-
private static final DefaultArrayResponse EMPTY = new DefaultArrayResponse(new ArrayList<Wrapper>(0), "");
93+
private static final DefaultArrayResponse EMPTY = new DefaultArrayResponse(Collections.emptyList(), "");
9494

9595
private final List<Wrapper> responses;
9696
private final String rawResponse;

0 commit comments

Comments
 (0)