Improve equals
This commit is contained in:
parent
5c9069f441
commit
e7e5633434
|
@ -94,7 +94,7 @@ gluonfx {
|
|||
//providedKeyAlias = ""
|
||||
//providedKeyAliasPassword = ""
|
||||
// iOS
|
||||
//bundleName = ""
|
||||
//bundleName = "mDNS Explorer"
|
||||
//bundleVersion = ""
|
||||
//bundleShortVersion = ""
|
||||
//providedSigningIdentity = ""
|
||||
|
|
|
@ -18,6 +18,7 @@ public class NetworkServiceCell extends CharmListCell<NetworkService> {
|
|||
private final Clipboard clipboard;
|
||||
private final ClipboardContent clipboardContent;
|
||||
|
||||
|
||||
public NetworkServiceCell() {
|
||||
clipboard = Clipboard.getSystemClipboard();
|
||||
clipboardContent = new ClipboardContent();
|
||||
|
@ -40,6 +41,7 @@ public class NetworkServiceCell extends CharmListCell<NetworkService> {
|
|||
setText(null);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateItem(NetworkService item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
|
|
|
@ -29,6 +29,8 @@ public class NetworkServiceListener implements ServiceListener {
|
|||
|
||||
@Override
|
||||
public void serviceAdded(ServiceEvent event) {
|
||||
ServiceInfo serviceInfo = event.getInfo();
|
||||
log.info("serviceRemoved() - Service: " + serviceInfo.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -37,12 +39,14 @@ public class NetworkServiceListener implements ServiceListener {
|
|||
if (serviceInfo != null) {
|
||||
String name = serviceInfo.getName();
|
||||
log.info("serviceRemoved() - Service: " + name);
|
||||
NetworkService oldNetworkService = new NetworkService(name, service, serviceInfo.getSubtype(), serviceInfo.getApplication(), serviceInfo.getURLs()[0], color);
|
||||
NetworkService networkService = new NetworkService(name, service, serviceInfo.getSubtype(), serviceInfo.getApplication(), serviceInfo.getURLs()[0], color);
|
||||
while (observableList.contains(networkService)) {
|
||||
Platform.runLater(() -> {
|
||||
observableList.remove(oldNetworkService);
|
||||
observableList.remove(networkService);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serviceResolved(ServiceEvent event) {
|
||||
|
@ -52,10 +56,10 @@ public class NetworkServiceListener implements ServiceListener {
|
|||
String name = serviceInfo.getName();
|
||||
String app = serviceInfo.getApplication();
|
||||
log.info("serviceResolved() - Service: {} - {} with url {}", app, name, url);
|
||||
NetworkService newNetworkService = new NetworkService(name, service, serviceInfo.getSubtype(), app, url, color);
|
||||
NetworkService networkService = new NetworkService(name, service, serviceInfo.getSubtype(), app, url, color);
|
||||
Platform.runLater(() -> {
|
||||
if(!observableList.contains(newNetworkService)) {
|
||||
observableList.add(newNetworkService);
|
||||
if(!observableList.contains(networkService)) {
|
||||
observableList.add(networkService);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package biz.nellemann.mdexpl.model;
|
|||
|
||||
import javafx.scene.paint.Color;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class NetworkService {
|
||||
|
||||
private String name;
|
||||
|
@ -75,13 +77,23 @@ public class NetworkService {
|
|||
return name + " (" + type + "), app=" + app + ", url=" + url;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof NetworkService networkService)) {
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
NetworkService networkService = (NetworkService) o;
|
||||
return Objects.equals(type, networkService.type) && Objects.equals(name, networkService.name) && Objects.equals(url, networkService.url);
|
||||
}
|
||||
return networkService.name.equals(name) && networkService.type.equals(type) && networkService.url.equals(url);
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((url == null) ? 0 : url.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -51,6 +51,7 @@ public class DiscoveryService {
|
|||
put("ipp", Color.LIGHTGRAY);
|
||||
put("ipps", Color.LIGHTGRAY);
|
||||
put("printer", Color.LIGHTGRAY);
|
||||
put("scanner", Color.LIGHTGRAY);
|
||||
|
||||
put("nfs", Color.CORAL);
|
||||
put("smb", Color.CORAL);
|
||||
|
@ -58,7 +59,9 @@ public class DiscoveryService {
|
|||
put("webdav", Color.CORAL);
|
||||
|
||||
put("smartenergy", Color.LIGHTGREEN);
|
||||
put("hap", Color.LIGHTGREEN);
|
||||
put("homekit", Color.LIGHTGREEN);
|
||||
put("homebridge", Color.LIGHTGREEN);
|
||||
|
||||
put("sip", Color.YELLOW);
|
||||
put("skype", Color.YELLOW);
|
||||
|
|
Loading…
Reference in a new issue