Note that there are some explanatory texts on larger screens.

plurals
  1. POHashset allows duplicates?
    primarykey
    data
    text
    <p>This question surely isn't a new one, but I didn't find any helpful answer anywhere.</p> <p>As you can see in the code below, the equals and hashcode methods are overriden, but it still allows duplicates. The Hashcode has been generated automatically by Netbeans.</p> <pre><code>@Override public boolean equals(Object o) { TaskDetails other = (TaskDetails) o; if ( (id_subtask == other.id_subtask) &amp;&amp; ((date.compareTo(other.date)) == 0) ) { System.err.println("Duplicate Entry"+id_subtask+" + "+other.id_subtask); return true; } else { System.out.println("Good!" +id_subtask+" + "+other.id_subtask); return false; } } @Override public int hashCode() { int hash = 7; hash = 71 * hash + this.id_subtask; hash = 71 * hash + this.id_team_member; hash = 71 * hash + Float.floatToIntBits(this.nb_hours); hash = 71 * hash + (this.date != null ? this.date.hashCode() : 0); hash = 71 * hash + (this.comment != null ? this.comment.hashCode() : 0); hash = 71 * hash + (this.subtask_name != null ? this.subtask_name.hashCode() : 0); System.out.println("Hash : "+hash + "Subtask : " + id_subtask); return hash; } </code></pre> <p>This the code used to add an entry into the hashset :</p> <pre><code>TaskDetails newTaskDetails = new TaskDetails ( s.getId_subtask(), mus.teamMember.getId_team_member(), f, mysqlFormat.format(caldate), c.substring(0, Math.min(c.length(), 100)), s.getName_subtask() ); allTasks.add(newTaskDetails); </code></pre> <p>(allTasks being the Hashset)</p> <p>This code is used in function A and B.</p> <p>If only function A is executed, it works fine. If function B is executed after function A (so the code above is executed twice), then the hashset suddenly accepts duplicates, even though system.err is triggered saying there is a duplicate entry?</p> <p>Is there a flaw in the code, or am I just missing something?</p> <p>Thanks for the help!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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