Skip to content

Commit

Permalink
Add inheritance to wrappers, reduce copy-paste code
Browse files Browse the repository at this point in the history
Inheritance changes: (-> : extends)
ClientInfo -> Client;
    + add getId() to ClientInfo
VirtualServerInfo -> VirtualServer;
    + rename all occurrences of "complain" to "complaint"
DatabaseClientInfo -> DatabaseClient
    + renamed getCreated() > getCreatedDate()
    + renamed getLastConnected() > getLastConnectedDate()
    + renamed getTotalBytseDownloaded() > getTotalBytesDownloaded()
Channel -> ChannelBase; ChannelInfo -> ChannelBase
    + return Codec for getCodec() instead of int
  • Loading branch information
rogermb committed Jun 4, 2015
1 parent 408b58b commit f6ea9c2
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 341 deletions.
12 changes: 6 additions & 6 deletions src/main/java/com/github/theholywaffle/teamspeak3/TS3Api.java
Original file line number Diff line number Diff line change
Expand Up @@ -1454,7 +1454,7 @@ public List<ChannelGroup> getChannelGroups() {
public ChannelInfo getChannelInfo(int channelId) {
final CChannelInfo info = new CChannelInfo(channelId);
if (query.doCommand(info)) {
return new ChannelInfo(info.getFirstResponse().getMap());
return new ChannelInfo(channelId, info.getFirstResponse().getMap());
}
return null;
}
Expand Down Expand Up @@ -1597,7 +1597,7 @@ public ClientInfo getClientByUId(String clientUId) {
public ClientInfo getClientInfo(int clientId) {
final CClientInfo info = new CClientInfo(clientId);
if (query.doCommand(info)) {
return new ClientInfo(info.getFirstResponse().getMap());
return new ClientInfo(clientId, info.getFirstResponse().getMap());
}
return null;
}
Expand Down Expand Up @@ -2501,7 +2501,7 @@ public boolean moveClient(int channelId) {
*
* @return whether the command succeeded or not
*/
public boolean moveClient(Channel channel) {
public boolean moveClient(ChannelBase channel) {
return moveClient(channel.getId(), null);
}

Expand Down Expand Up @@ -2531,7 +2531,7 @@ public boolean moveClient(int channelId, String channelPassword) {
*
* @return whether the command succeeded or not
*/
public boolean moveClient(Channel channel, String channelPassword) {
public boolean moveClient(ChannelBase channel, String channelPassword) {
return moveClient(0, channel.getId(), channelPassword);
}

Expand Down Expand Up @@ -2562,7 +2562,7 @@ public boolean moveClient(int clientId, int channelId) {
*
* @return whether the command succeeded or not
*/
public boolean moveClient(Client client, Channel channel) {
public boolean moveClient(Client client, ChannelBase channel) {
return moveClient(client.getId(), channel.getId(), null);
}

Expand Down Expand Up @@ -2598,7 +2598,7 @@ public boolean moveClient(int clientId, int channelId, String channelPassword) {
*
* @return whether the command succeeded or not
*/
public boolean moveClient(Client client, Channel channel, String channelPassword) {
public boolean moveClient(Client client, ChannelBase channel, String channelPassword) {
return moveClient(client.getId(), channel.getId(), channelPassword);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1512,15 +1512,15 @@ public void handle() {
* @see Channel#getId()
* @see ChannelInfo
*/
public CommandFuture<ChannelInfo> getChannelInfo(int channelId) {
public CommandFuture<ChannelInfo> getChannelInfo(final int channelId) {
final CChannelInfo info = new CChannelInfo(channelId);
final CommandFuture<ChannelInfo> future = new CommandFuture<>();

query.doCommandAsync(info, new Callback() {
@Override
public void handle() {
if (hasFailed(info, future)) return;
future.set(new ChannelInfo(info.getFirstResponse().getMap()));
future.set(new ChannelInfo(channelId, info.getFirstResponse().getMap()));
}
});
return future;
Expand Down Expand Up @@ -1706,7 +1706,7 @@ public CommandFuture<ClientInfo> getClientInfo(final int clientId) {
@Override
public void handle() {
if (hasFailed(info, future)) return;
future.set(new ClientInfo(info.getFirstResponse().getMap()));
future.set(new ClientInfo(clientId, info.getFirstResponse().getMap()));
}
});
return future;
Expand Down Expand Up @@ -2793,7 +2793,7 @@ public CommandFuture<Boolean> moveClient(int channelId) {
*
* @return whether the command succeeded or not
*/
public CommandFuture<Boolean> moveClient(Channel channel) {
public CommandFuture<Boolean> moveClient(ChannelBase channel) {
return moveClient(channel.getId(), null);
}

Expand Down Expand Up @@ -2823,7 +2823,7 @@ public CommandFuture<Boolean> moveClient(int channelId, String channelPassword)
*
* @return whether the command succeeded or not
*/
public CommandFuture<Boolean> moveClient(Channel channel, String channelPassword) {
public CommandFuture<Boolean> moveClient(ChannelBase channel, String channelPassword) {
return moveClient(0, channel.getId(), channelPassword);
}

Expand Down Expand Up @@ -2854,7 +2854,7 @@ public CommandFuture<Boolean> moveClient(int clientId, int channelId) {
*
* @return whether the command succeeded or not
*/
public CommandFuture<Boolean> moveClient(Client client, Channel channel) {
public CommandFuture<Boolean> moveClient(Client client, ChannelBase channel) {
return moveClient(client.getId(), channel.getId(), null);
}

Expand Down Expand Up @@ -2890,7 +2890,7 @@ public CommandFuture<Boolean> moveClient(int clientId, int channelId, String cha
*
* @return whether the command succeeded or not
*/
public CommandFuture<Boolean> moveClient(Client client, Channel channel, String channelPassword) {
public CommandFuture<Boolean> moveClient(Client client, ChannelBase channel, String channelPassword) {
return moveClient(client.getId(), channel.getId(), channelPassword);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,76 +30,21 @@

import com.github.theholywaffle.teamspeak3.api.ChannelProperty;

public class Channel extends Wrapper {
public class Channel extends ChannelBase {

public Channel(Map<String, String> map) {
super(map);
}

@Override
public int getId() {
return getInt(ChannelProperty.CID);
}

public int getParentChannelId() {
return getInt(ChannelProperty.PID);
}

public int getOrder() {
return getInt(ChannelProperty.CHANNEL_ORDER);
}

public String getName() {
return get(ChannelProperty.CHANNEL_NAME);
}

public String getTopic() {
return get(ChannelProperty.CHANNEL_TOPIC);
}

public boolean isDefault() {
return getBoolean(ChannelProperty.CHANNEL_FLAG_DEFAULT);
}

public boolean hasPassword() {
return getBoolean(ChannelProperty.CHANNEL_FLAG_PASSWORD);
}

public boolean isPermanent() {
return getBoolean(ChannelProperty.CHANNEL_FLAG_PERMANENT);
}

public boolean isSemiPermanent() {
return getBoolean(ChannelProperty.CHANNEL_FLAG_SEMI_PERMANENT);
}

public int getCodec() {
return getInt(ChannelProperty.CHANNEL_CODEC);
}

public int getCodecQuality() {
return getInt(ChannelProperty.CHANNEL_CODEC_QUALITY);
}

public int getNeededTalkPower() {
return getInt(ChannelProperty.CHANNEL_NEEDED_TALK_POWER);
}

public long getIconId() {
return getLong(ChannelProperty.CHANNEL_ICON_ID);
}

public int getTotalClientsFamily() {
return getInt("total_clients_family");
}

public int getMaxClients() {
return getInt(ChannelProperty.CHANNEL_MAXCLIENTS);
}

public int getMaxFamilyClients() {
return getInt(ChannelProperty.CHANNEL_MAXFAMILYCLIENTS);
}

public int getTotalClients() {
return getInt("total_clients");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package com.github.theholywaffle.teamspeak3.api.wrapper;

/*
* #%L
* TeamSpeak 3 Java API
* %%
* Copyright (C) 2014 - 2015 Bert De Geyter, Roger Baumgartner
* %%
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
* #L%
*/

import com.github.theholywaffle.teamspeak3.api.ChannelProperty;
import com.github.theholywaffle.teamspeak3.api.Codec;

import java.util.Map;

public abstract class ChannelBase extends Wrapper {

public ChannelBase(Map<String, String> map) {
super(map);
}

public abstract int getId();

public int getParentChannelId() {
return getInt(ChannelProperty.PID);
}

public int getOrder() {
return getInt(ChannelProperty.CHANNEL_ORDER);
}

public String getName() {
return get(ChannelProperty.CHANNEL_NAME);
}

public String getTopic() {
return get(ChannelProperty.CHANNEL_TOPIC);
}

public boolean isDefault() {
return getBoolean(ChannelProperty.CHANNEL_FLAG_DEFAULT);
}

public boolean hasPassword() {
return getBoolean(ChannelProperty.CHANNEL_FLAG_PASSWORD);
}

public boolean isPermanent() {
return getBoolean(ChannelProperty.CHANNEL_FLAG_PERMANENT);
}

public boolean isSemiPermanent() {
return getBoolean(ChannelProperty.CHANNEL_FLAG_SEMI_PERMANENT);
}

public Codec getCodec() {
final int codec = getInt(ChannelProperty.CHANNEL_CODEC);
for (final Codec c : Codec.values()) {
if (c.getIndex() == codec) {
return c;
}
}
return Codec.UNKNOWN;
}

public int getCodecQuality() {
return getInt(ChannelProperty.CHANNEL_CODEC_QUALITY);
}

public int getNeededTalkPower() {
return getInt(ChannelProperty.CHANNEL_NEEDED_TALK_POWER);
}

public long getIconId() {
return getLong(ChannelProperty.CHANNEL_ICON_ID);
}

public int getMaxClients() {
return getInt(ChannelProperty.CHANNEL_MAXCLIENTS);
}

public int getMaxFamilyClients() {
return getInt(ChannelProperty.CHANNEL_MAXFAMILYCLIENTS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,18 @@

import com.github.theholywaffle.teamspeak3.api.ChannelProperty;

public class ChannelInfo extends Wrapper {
public class ChannelInfo extends ChannelBase {

public ChannelInfo(Map<String, String> map) {
super(map);
}

public int getParentChannelId() {
return getInt(ChannelProperty.PID);
}
private final int channelId;

public String getName() {
return get(ChannelProperty.CHANNEL_NAME);
public ChannelInfo(int channelId, Map<String, String> map) {
super(map);
this.channelId = channelId;
}

public String getTopic() {
return get(ChannelProperty.CHANNEL_TOPIC);
@Override
public int getId() {
return channelId;
}

public String getDescription() {
Expand All @@ -56,42 +52,6 @@ public String getPassword() {
return get(ChannelProperty.CHANNEL_PASSWORD);
}

public int getCodec() {
return getInt(ChannelProperty.CHANNEL_CODEC);
}

public int getCodecQuality() {
return getInt(ChannelProperty.CHANNEL_CODEC_QUALITY);
}

public int getMaxClients() {
return getInt(ChannelProperty.CHANNEL_MAXCLIENTS);
}

public int getMaxFamilyClients() {
return getInt(ChannelProperty.CHANNEL_MAXFAMILYCLIENTS);
}

public int getOrder() {
return getInt(ChannelProperty.CHANNEL_ORDER);
}

public boolean isPermanent() {
return getBoolean(ChannelProperty.CHANNEL_FLAG_PERMANENT);
}

public boolean isSemiPermanent() {
return getBoolean(ChannelProperty.CHANNEL_FLAG_SEMI_PERMANENT);
}

public boolean isDefault() {
return getBoolean(ChannelProperty.CHANNEL_FLAG_DEFAULT);
}

public boolean hasPassword() {
return getBoolean(ChannelProperty.CHANNEL_FLAG_PASSWORD);
}

public int getCodecLatencyFactor() {
return getInt(ChannelProperty.CHANNEL_CODEC_LATENCY_FACTOR);
}
Expand All @@ -116,20 +76,11 @@ public String getFilePath() {
return get(ChannelProperty.CHANNEL_FILEPATH);
}

public int getNeededTalkPower() {
return getInt(ChannelProperty.CHANNEL_NEEDED_TALK_POWER);
}

public boolean isForcedSilence() {
return getBoolean(ChannelProperty.CHANNEL_FORCED_SILENCE);
}

public String getPhoneticName() {
return get(ChannelProperty.CHANNEL_NAME_PHONETIC);
}

public long getIconId() {
return getLong(ChannelProperty.CHANNEL_ICON_ID);
}

}
Loading

0 comments on commit f6ea9c2

Please sign in to comment.