Skip to content

Instantly share code, notes, and snippets.

@DarkSeraphim
Created October 1, 2014 19:25
Show Gist options
  • Save DarkSeraphim/d298007d5291d0a4b1ce to your computer and use it in GitHub Desktop.
Save DarkSeraphim/d298007d5291d0a4b1ce to your computer and use it in GitHub Desktop.
It's... so pwetty - forwarding the Iterator removal for wrapped object Lists to the unwrapped object variant
List<Trade> trades = new ArrayList<Trade>()
{
public Iterator<Trade> iterator()
{
final Iterator<Trade> s = super.iterator();
return new Iterator<Trade>()
{
private final List<?> nmsList = list;
private final Iterator<Trade> delegate = s;
private Trade last;
@Override
public boolean hasNext()
{
return this.delegate.hasNext();
}
@Override
public Trade next()
{
return this.last = this.delegate.next();
}
@Override
public void remove()
{
this.delegate.remove();
this.nmsList.remove(unwrap(this.last));
}
};
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment