title: Java - remove objects in a collection that are in another collection, with an arbitrary meaning of "equals"
body: <p>This is very easy if I just want to base this on absolute equality. I'd just do:</p>
  
  <pre><code>collectionA.removeAll(collectionB).
  </code></pre>
  
  <p>However, let's say I have this object:</p>
  
  <pre><code>class Item {
     private String color;
     private String name;
     private String type;
  }
  </code></pre>
  
  <p>And two collections...</p>
  
  <pre><code>List&lt;Item&gt; items1, List&lt;item&gt; items2.
  </code></pre>
  
  <p>...but I just want to remove everything from item1 that has the same <em>name and type</em> as something in item2. </p>
  
  <p>Note that I can't subclass or define equals, hashcode for this class.</p>
  
  <p>I'd want this to be the same complexity of the existing collections.removeAll method.</p>
  
  <p>The best solution I can think of would be something like:</p>
  
  <pre><code>class SimpleItem {
    String name;
    String type;
    Item item;
  
    public SimpleItem(Item item) {
      this.name = item.getName();
      this.type = item.getType();
    }
  
    @Override
    public boolean equals(Object obj) {
      ...
    }
  
    @Override
    public int hashCode() {
      ...
    }
  }
  
  Set&lt;SimpleItem&gt; simpleItems1 = ...;
  for (Item item : items1) {
    simpleItems1.add(new SimpleItem(item));
  }
  
  Set&lt;SimpleItem&gt; simpleItems2 = ...;
  for (Item item : items2) {
    simpleItems2.add(new SimpleItem(item));
  }
  
  simpleItems1.removeAll(simpleItems2);
  
  Set&lt;Item&gt; items = ...;
  for (SimpleItem simpleItem : simpleItems) {
    items.add(simpleItem.item);
  }
  </code></pre>
  
  <p>...but that is insanely verbose. It's Java 8. What clever solution am I missing?</p>