From: David ‘Bombe’ Roden Date: Mon, 8 Apr 2013 19:15:16 +0000 (+0200) Subject: Add bots and packs. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=118763df651faf501ce55d9cd09bbebf00654e8b;p=xudocci.git Add bots and packs. --- diff --git a/src/main/java/net/pterodactylus/xdcc/data/Bot.java b/src/main/java/net/pterodactylus/xdcc/data/Bot.java new file mode 100644 index 0000000..33bec20 --- /dev/null +++ b/src/main/java/net/pterodactylus/xdcc/data/Bot.java @@ -0,0 +1,122 @@ +/* + * XdccDownloader - Bot.java - Copyright © 2013 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.xdcc.data; + +import java.util.Collection; +import java.util.Map; + +import com.beust.jcommander.internal.Maps; + +/** + * A bot is a client in a {@link Network} that carries {@link Pack}s which are + * available for download. + * + * @author David ‘Bombe’ Roden + */ +public class Bot { + + /** The network this bot is on. */ + private final Network network; + + /** The packs this bot carries. */ + private final Map packs = Maps.newHashMap(); + + /** The current name of the bot. */ + private String name; + + /** + * Creates a new bot. + * + * @param network + * The network the bot is on + */ + public Bot(Network network) { + this.network = network; + } + + // + // ACCESSORS + // + + /** + * Returns the network the bot is on. + * + * @return The network the bot is on + */ + public Network network() { + return network; + } + + /** + * Returns the current name of this bot. + * + * @return The current name of this bot + */ + public String name() { + return name; + } + + /** + * Returns the packs this bot carries. + * + * @return The packs this bot carries + */ + public Collection packs() { + return packs.values(); + } + + // + // MUTATORS + // + + /** + * Sets the current name of this bot. + * + * @param name + * The name of this bot + * @return This bot + */ + public Bot name(String name) { + this.name = name; + return this; + } + + // + // ACTIONS + // + + /** + * Adds the given pack to this bot. + * + * @param pack + * The pack to add + */ + public void addPack(Pack pack) { + packs.put(pack.id(), pack); + } + + // + // OBJECT METHODS + // + + @Override + public String toString() { + return String.format("%s/%s", name(), network().name()); + } + +} diff --git a/src/main/java/net/pterodactylus/xdcc/data/Pack.java b/src/main/java/net/pterodactylus/xdcc/data/Pack.java new file mode 100644 index 0000000..1ec5a09 --- /dev/null +++ b/src/main/java/net/pterodactylus/xdcc/data/Pack.java @@ -0,0 +1,86 @@ +/* + * XdccDownloader - Pack.java - Copyright © 2013 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.xdcc.data; + +/** + * A pack is a downloadable file offered by a {@link Bot}. + * + * @author David ‘Bombe’ Roden + */ +public class Pack { + + /** The ID of the pack. */ + private final String id; + + /** The size of the pack. */ + private final String size; + + /** The name of the pack. */ + private final String name; + + /** + * Creates a new pack. + * + * @param id + * The ID of the pack + * @param size + * The size of the pack + * @param name + * The name of the pack + */ + public Pack(String id, String size, String name) { + this.id = id; + this.size = size; + this.name = name; + } + + // + // ACCESSORS + // + + /** + * Returns the ID of the pack. The ID is only guaranteed to be unique within a + * single {@link Bot}. + * + * @return The ID of the pack + */ + public String id() { + return id; + } + + /** + * Returns the size of the pack. The size can contain decimal fractions and + * unit denotifiers, such as “1.2G”. + * + * @return The size of the pack + */ + public String size() { + return size; + } + + /** + * Returns the name of the pack. This is usually the name of the single file + * that makes up this pack. + * + * @return The name of the pack + */ + public String name() { + return name; + } + +}