I can't seem to find a solution for this problem:
a.example 1.1.1.1
a.example 1.2.1.1
where first column is the hostname and the second one is the ip.
These two information are used to compose an object of a class Router.java
. I want to use objects of Router.java
as a key to a Hashmap and Boolean
as value i.e. HashMap < Router,Boolean >
.
The way I want to use my ".containsKey" method is that it checks if one of the fields (either hostname
or ip
) are the same , then it should return true. Also in such a case I want to make the value corresponding to such an Object of Router.java
askey in the hashmap as true.
My problem is that I don't know how to write the hash method in order for the two objects to have the same hash and go to the .equals().
import java.util.Objects;
`enter code here`public class Router {
String hostname;
String ip_address;
String patched;
String os_version;
String notes;
public Router(String hostname,String ip_address,String patched,String os_version,String notes)
{
this.hostname = hostname;
this.ip_address = ip_address;
this.patched = patched;
this.os_version = os_version;
this.notes = notes;
}
@Override
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof Router)) {
return false;
}
Router r = (Router) o;
return r.hostname.equals(hostname) ||
r.ip_address.equals(ip_address) ;
}
@Override
public int hashCode() {
}
}