Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I don't know if this will help you.But it works in both the directions as you say</p> <pre><code>import java.util.HashSet; public class Flows implements Comparable&lt;Flows&gt; { String srcAddr = "", dstAddr = "", protocol = ""; int srcPort = 0, dstPort = 0; public Flows(String sIP, String dIP, int sPort, int dPort){ this.srcAddr = sIP; this.dstAddr = dIP; this.srcPort = sPort; this.dstPort = dPort; //this.protocol = protocol; } public Flows(){ } public int compareTo(Flows other) { if(this.equals(other)){ return 0; }else return 1; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((dstAddr == null) ? 0 : dstAddr.hashCode())+((srcAddr == null) ? 0 : srcAddr.hashCode()); result = prime * result + dstPort+srcPort; return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if(obj instanceof Flows) { Flows c=(Flows)obj; if(srcAddr.equals(c.dstAddr) &amp;&amp; dstAddr.equals(c.srcAddr) &amp;&amp;srcPort==c.dstPort &amp;&amp; dstPort==c.srcPort) return true; if(srcAddr.equals(c.srcAddr) &amp;&amp; dstAddr.equals(c.dstAddr) &amp;&amp; srcPort==c.srcPort &amp;&amp; dstPort==c.dstPort) return true; } return false; } @Override public String toString() { return String.format("[%s, %s, %s, %s, %s]", srcAddr, dstAddr, srcPort, dstPort, protocol); } public static void main(String[] args) { Flows f1=new Flows("192.168.1.65","217.174.16.1", 123456,80); Flows f2=new Flows("217.174.16.1","192.168.1.65",80,123456); Flows f3=new Flows("192.168.1.66","217.174.16.1", 123456,80); Flows f4=new Flows("217.174.16.1","192.168.1.66",80, 123456); System.out.println(f1.hashCode()+ " "+f2.hashCode()); HashSet&lt;Flows&gt; hh=new HashSet&lt;Flows&gt;(); hh.add(f1); hh.add(f2); hh.add(f3); hh.add(f4); System.out.println(f1.compareTo(f2)); System.out.println(hh); } } </code></pre> <p>I have used hashset to test.So it should work fine for hashmap too.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload