[vlma-devel] commit: Fix Order#equals. (Adrien Grand )
git version control
git at videolan.org
Tue Aug 26 23:22:03 CEST 2008
vlma | branch: master | Adrien Grand <jpountz at videolan.org> | Tue Aug 26 23:12:28 2008 +0200| [bf34c2417b79c087a8eec36b9411d55b7bb6b5fa] | committer: Adrien Grand
Fix Order#equals.
> http://git.videolan.org/gitweb.cgi/vlma.git/?a=commit;h=bf34c2417b79c087a8eec36b9411d55b7bb6b5fa
---
.../main/java/org/videolan/vlma/model/Adapter.java | 15 +++++++++++++++
.../java/org/videolan/vlma/model/MediaGroup.java | 8 ++++++--
.../main/java/org/videolan/vlma/model/Server.java | 15 ++++++++-------
3 files changed, 29 insertions(+), 9 deletions(-)
diff --git a/vlma-api/src/main/java/org/videolan/vlma/model/Adapter.java b/vlma-api/src/main/java/org/videolan/vlma/model/Adapter.java
index 53f907d..2962eee 100644
--- a/vlma-api/src/main/java/org/videolan/vlma/model/Adapter.java
+++ b/vlma-api/src/main/java/org/videolan/vlma/model/Adapter.java
@@ -141,4 +141,19 @@ public abstract class Adapter implements Serializable {
this.isUp = isUp;
}
+ @Override
+ public boolean equals(Object other) {
+ if (other == null || !(other instanceof Adapter)) {
+ return false;
+ }
+ Adapter adapter = (Adapter) other;
+ return adapter.getName().equals(getName()) &&
+ adapter.getServer().equals(getServer());
+ }
+
+ @Override
+ public int hashCode() {
+ return name.hashCode() + server.getIp().hashCode();
+ }
+
}
diff --git a/vlma-api/src/main/java/org/videolan/vlma/model/MediaGroup.java b/vlma-api/src/main/java/org/videolan/vlma/model/MediaGroup.java
index 2acfbbf..493c5b4 100644
--- a/vlma-api/src/main/java/org/videolan/vlma/model/MediaGroup.java
+++ b/vlma-api/src/main/java/org/videolan/vlma/model/MediaGroup.java
@@ -55,9 +55,13 @@ public class MediaGroup extends ArrayList<Media> implements Comparable<MediaGrou
if (o == null) return false;
if (o instanceof MediaGroup) {
MediaGroup g = (MediaGroup) o;
- if (!g.isEmpty() && !isEmpty()) {
- return g.get(0).belongsToGroup(this);
+ if (g.size() != this.size())
+ return false;
+ for (Media media : this) {
+ if (!g.contains(media))
+ return false;
}
+ return true;
}
return false;
}
diff --git a/vlma-api/src/main/java/org/videolan/vlma/model/Server.java b/vlma-api/src/main/java/org/videolan/vlma/model/Server.java
index b4156ba..1e1a2b8 100644
--- a/vlma-api/src/main/java/org/videolan/vlma/model/Server.java
+++ b/vlma-api/src/main/java/org/videolan/vlma/model/Server.java
@@ -22,6 +22,7 @@ package org.videolan.vlma.model;
import java.io.Serializable;
import java.net.InetAddress;
+import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
@@ -51,6 +52,9 @@ public class Server implements Serializable {
public Server() {
adapters = new ArrayList<Adapter>();
setUp(true);
+ try {
+ this.ip = InetAddress.getLocalHost();
+ } catch (UnknownHostException e) {}
}
/**
@@ -67,13 +71,10 @@ public class Server implements Serializable {
@Override
public boolean equals(Object o) {
- if (o == null) return false;
- try {
- Server server = (Server) o;
- return this.hashCode() == server.hashCode();
- } catch (ClassCastException e) {
+ if (o == null || !(o instanceof Server))
return false;
- }
+ Server server = (Server) o;
+ return server.getIp().equals(getIp());
}
/**
@@ -148,7 +149,7 @@ public class Server implements Serializable {
@Override
public int hashCode() {
- return name == null ? 0 : name.hashCode();
+ return ip.hashCode();
}
/**
More information about the vlma-devel
mailing list