@Override public boolean remove(Object o) { if(strategy == null) { return super.remove(o); } else { Iterator<JsonElement> it = iterator(); while (it.hasNext()) { JsonElement jsonElement = it.next(); if(strategy.equals((JsonElement)o,jsonElement)) { it.remove(); return true; } } } return false; }
/** * Changes the strategy on the current set. * @param strategy id strategy * @return the current set. */ public JsonSet withIdStrategy(IdStrategy strategy) { this.strategy = strategy; if(size()>0) { JsonSet seen=new JsonSet().withIdStrategy(strategy); Iterator<JsonElement> iterator = this.iterator(); while (iterator.hasNext()) { JsonElement e = iterator.next(); if(seen.contains(e)) { iterator.remove(); } else { seen.add(e); } } } return this; }