projects
/
xudocci.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
6721687
)
Override hashCode() and equals().
author
David ‘Bombe’ Roden
<bombe@pterodactylus.net>
Thu, 18 Apr 2013 04:10:43 +0000
(06:10 +0200)
committer
David ‘Bombe’ Roden
<bombe@pterodactylus.net>
Thu, 18 Apr 2013 04:10:43 +0000
(06:10 +0200)
src/main/java/net/pterodactylus/xdcc/data/Bot.java
patch
|
blob
|
history
src/main/java/net/pterodactylus/xdcc/data/Download.java
patch
|
blob
|
history
src/main/java/net/pterodactylus/xdcc/data/Pack.java
patch
|
blob
|
history
diff --git
a/src/main/java/net/pterodactylus/xdcc/data/Bot.java
b/src/main/java/net/pterodactylus/xdcc/data/Bot.java
index
724f0e0
..
96d91b6
100644
(file)
--- a/
src/main/java/net/pterodactylus/xdcc/data/Bot.java
+++ b/
src/main/java/net/pterodactylus/xdcc/data/Bot.java
@@
-17,6
+17,8
@@
package net.pterodactylus.xdcc.data;
package net.pterodactylus.xdcc.data;
+import static com.google.common.base.Preconditions.checkNotNull;
+
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
@@
-45,9
+47,12
@@
public class Bot implements Iterable<Pack> {
*
* @param network
* The network the bot is on
*
* @param network
* The network the bot is on
+ * @param name
+ * The name of the bot
*/
*/
- public Bot(Network network) {
- this.network = network;
+ public Bot(Network network, String name) {
+ this.network = checkNotNull(network, "network must not be null");
+ this.name = checkNotNull(name, "name must not be null");
}
//
}
//
@@
-93,7
+98,7
@@
public class Bot implements Iterable<Pack> {
* @return This bot
*/
public Bot name(String name) {
* @return This bot
*/
public Bot name(String name) {
- this.name =
name
;
+ this.name =
checkNotNull(name, "name must not be null")
;
return this;
}
return this;
}
@@
-125,6
+130,20
@@
public class Bot implements Iterable<Pack> {
//
@Override
//
@Override
+ public boolean equals(Object object) {
+ if (!(object instanceof Bot)) {
+ return false;
+ }
+ Bot bot = (Bot) object;
+ return network().equals(bot.network()) && name().equals(bot.name());
+ }
+
+ @Override
+ public int hashCode() {
+ return network().hashCode() ^ name().hashCode();
+ }
+
+ @Override
public String toString() {
return String.format("%s/%s", name(), network().name());
}
public String toString() {
return String.format("%s/%s", name(), network().name());
}
diff --git
a/src/main/java/net/pterodactylus/xdcc/data/Download.java
b/src/main/java/net/pterodactylus/xdcc/data/Download.java
index
5190ed0
..
0592eaf
100644
(file)
--- a/
src/main/java/net/pterodactylus/xdcc/data/Download.java
+++ b/
src/main/java/net/pterodactylus/xdcc/data/Download.java
@@
-17,6
+17,8
@@
package net.pterodactylus.xdcc.data;
package net.pterodactylus.xdcc.data;
+import static com.google.common.base.Preconditions.checkNotNull;
+
import java.io.OutputStream;
import java.net.InetAddress;
import java.io.OutputStream;
import java.net.InetAddress;
@@
-59,8
+61,8
@@
public class Download {
* The pack being downloaded
*/
public Download(Bot bot, Pack pack) {
* The pack being downloaded
*/
public Download(Bot bot, Pack pack) {
- this.bot =
bot
;
- this.pack =
pack
;
+ this.bot =
checkNotNull(bot, "bot must not be null")
;
+ this.pack =
checkNotNull(pack, "pack must not be null")
;
}
//
}
//
@@
-194,4
+196,22
@@
public class Download {
return this;
}
return this;
}
+ //
+ // OBJECT METHODS
+ //
+
+ @Override
+ public boolean equals(Object object) {
+ if (!(object instanceof Download)) {
+ return false;
+ }
+ Download download = (Download) object;
+ return bot().equals(download.bot()) && pack().equals(download.pack());
+ }
+
+ @Override
+ public int hashCode() {
+ return bot().hashCode() ^ pack().hashCode();
+ }
+
}
}
diff --git
a/src/main/java/net/pterodactylus/xdcc/data/Pack.java
b/src/main/java/net/pterodactylus/xdcc/data/Pack.java
index
1ec5a09
..
c41694f
100644
(file)
--- a/
src/main/java/net/pterodactylus/xdcc/data/Pack.java
+++ b/
src/main/java/net/pterodactylus/xdcc/data/Pack.java
@@
-17,6
+17,8
@@
package net.pterodactylus.xdcc.data;
package net.pterodactylus.xdcc.data;
+import static com.google.common.base.Preconditions.checkNotNull;
+
/**
* A pack is a downloadable file offered by a {@link Bot}.
*
/**
* A pack is a downloadable file offered by a {@link Bot}.
*
@@
-44,9
+46,9
@@
public class Pack {
* The name of the pack
*/
public Pack(String id, String size, String name) {
* The name of the pack
*/
public Pack(String id, String size, String name) {
- this.id =
id
;
- this.size =
size
;
- this.name =
name
;
+ this.id =
checkNotNull(id, "id must not be null")
;
+ this.size =
checkNotNull(size, "size must not be null")
;
+ this.name =
checkNotNull(name, "name must not be null")
;
}
//
}
//
@@
-83,4
+85,22
@@
public class Pack {
return name;
}
return name;
}
+ //
+ // OBJECT METHODS
+ //
+
+ @Override
+ public boolean equals(Object object) {
+ if (!(object instanceof Pack)) {
+ return false;
+ }
+ Pack pack = (Pack) object;
+ return id().equals(pack.id()) && name().equals(pack.name());
+ }
+
+ @Override
+ public int hashCode() {
+ return id().hashCode() ^ name().hashCode();
+ }
+
}
}