Skip to content

Instantly share code, notes, and snippets.

@senneco
Created April 6, 2017 05:56
Show Gist options
  • Save senneco/98a532df9915901da8065448722cef9f to your computer and use it in GitHub Desktop.
Save senneco/98a532df9915901da8065448722cef9f to your computer and use it in GitHub Desktop.
import java.util.Iterator;
import java.util.List;
import com.arellomobile.mvp.MvpView;
import com.arellomobile.mvp.viewstate.ViewCommand;
import com.arellomobile.mvp.viewstate.strategy.StateStrategy;
public class AddToEndSingleByTagStateStrategy implements StateStrategy {
@Override
public <View extends MvpView> void beforeApply(List<ViewCommand<View>> currentState, ViewCommand<View> incomingCommand) {
Iterator<ViewCommand<View>> iterator = currentState.iterator();
while (iterator.hasNext()) {
ViewCommand<View> entry = iterator.next();
if (entry.getTag().equals(incomingCommand.getTag())) {
iterator.remove();
break;
}
}
currentState.add(incomingCommand);
}
@Override
public <View extends MvpView> void afterApply(List<ViewCommand<View>> currentState, ViewCommand<View> incomingCommand) {
// pass
}
}
@horse315
Copy link

horse315 commented Jun 5, 2017

As long as while breaks, entry and incomingCommand types should be compared

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment