Implement toString method
[xudocci.git] / src / main / java / net / pterodactylus / xdcc / data / Pack.java
1 /*
2  * XdccDownloader - Pack.java - Copyright © 2013 David Roden
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 package net.pterodactylus.xdcc.data;
19
20 import static com.google.common.base.Preconditions.checkNotNull;
21
22 /**
23  * A pack is a downloadable file offered by a {@link Bot}.
24  *
25  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
26  */
27 public class Pack {
28
29         /** The ID of the pack. */
30         private final String id;
31
32         /** The size of the pack. */
33         private final String size;
34
35         /** The name of the pack. */
36         private final String name;
37
38         /**
39          * Creates a new pack.
40          *
41          * @param id
42          *              The ID of the pack
43          * @param size
44          *              The size of the pack
45          * @param name
46          *              The name of the pack
47          */
48         public Pack(String id, String size, String name) {
49                 this.id = checkNotNull(id, "id must not be null");
50                 this.size = checkNotNull(size, "size must not be null");
51                 this.name = checkNotNull(name, "name must not be null");
52         }
53
54         //
55         // ACCESSORS
56         //
57
58         /**
59          * Returns the ID of the pack. The ID is only guaranteed to be unique within a
60          * single {@link Bot}.
61          *
62          * @return The ID of the pack
63          */
64         public String id() {
65                 return id;
66         }
67
68         /**
69          * Returns the size of the pack. The size can contain decimal fractions and
70          * unit denotifiers, such as “1.2G”.
71          *
72          * @return The size of the pack
73          */
74         public String size() {
75                 return size;
76         }
77
78         /**
79          * Returns the name of the pack. This is usually the name of the single file
80          * that makes up this pack.
81          *
82          * @return The name of the pack
83          */
84         public String name() {
85                 return name;
86         }
87
88         //
89         // OBJECT METHODS
90         //
91
92         @Override
93         public boolean equals(Object object) {
94                 if (!(object instanceof Pack)) {
95                         return false;
96                 }
97                 Pack pack = (Pack) object;
98                 return id().equals(pack.id()) && name().equals(pack.name());
99         }
100
101         @Override
102         public int hashCode() {
103                 return id().hashCode() ^ name().hashCode();
104         }
105
106         @Override
107         public String toString() {
108                 return String.format("%s [%s] %s", id(), size(), name());
109         }
110
111 }