title: IdentitySet / IdentityHashSet (use IdentityHashMap)
body: <p>I know about <a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/IdentityHashMap.html" rel="noreferrer"><code>IdentityHashMap</code></a>, but I need to use to something like <code>&quot;IdentitySet&quot;</code> (use <code>equals</code> as <code>o1 == o2</code> ). I'm going to use one to listen Observable list with &quot;extractor&quot; (<strong>JavaFX</strong>):</p>
  <pre><code> List&lt;Person&gt; deleteList = new ArrayList&lt;&gt;();
   List&lt;Person&gt; addList = new ArrayList&lt;&gt;();
  
   ObservableList&lt;Person&gt; list = FXCollections.observableArrayList(Person.extractor());
      list.add(new Person(&quot;a&quot;,1));
      list.add(new Person(&quot;b&quot;,2));
      list.add(new Person(&quot;c&quot;,3));
  
      list.addListener((ListChangeListener&lt;Person&gt;) observable -&gt; {
          if(observable.next()) {
              if (observable.wasAdded()) {
                  addList.addAll(observable.getAddedSubList());
              }
              if (observable.wasUpdated()) {
                  deleteList.add(list.get(observable.getFrom()));
              }
              if (observable.wasRemoved()) {
                  deleteList.addAll(observable.getRemoved());
              }
          }
      });
  </code></pre>
  <p>Person class:</p>
  <pre><code>public class Person {
  private final StringProperty s;
  private final DoubleProperty d;
  
  //Getters and Setters
  // ...
  
  @Override
  public int hashCode() {
      int result = s != null ? s.getValue().hashCode() : 0;
      result = 21 * result + (d != null ? Double.hashCode(d.getValue()) : 0);
      return result;
  }
  
  @Override
  public boolean equals(Object o) {
      if (this == o) return true;
      if (o == null || getClass() != o.getClass()) return false;
  
      Person person = (Person) o;
      if (!s.getValue().equals(person.s.getValue())) return false;
      return d.getValue().equals(person.d.getValue());
  }
  
  
  /**
   *Extractor to observe changes in &quot;Property&quot; fields.
   * @return extractor
   */
  public static Callback&lt;Person, Observable[]&gt; extractor() {
      return (Person p) -&gt; new Observable[]{p.sProperty(), p.dProperty()};
  }
  </code></pre>
  <p>I need to override <code>equals</code> and <code>hashCode</code> to solve my other issues.</p>
  <pre><code>Person p = new Person(&quot;a&quot;,1);
  Set&lt;Object&gt; persons = new HashSet&lt;&gt;();
  persons.add(p);
  p.setD(999);
  persons.add(p);
  System.out.println(persons.size());  // size = 2;
  
  persons.remove(p);
  System.out.println(persons.size());  // size = 1;
  </code></pre>