com.arellomobile.mvp.viewstate.strategy.AddToEndSingleStrategy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of moxy Show documentation
Show all versions of moxy Show documentation
MoxyX, we added X for make this library coolest
The newest version!
package com.arellomobile.mvp.viewstate.strategy;
import java.util.Iterator;
import java.util.List;
import com.arellomobile.mvp.MvpView;
import com.arellomobile.mvp.viewstate.ViewCommand;
/**
* Command will be added to end of commands queue. If commands queue contains same type command, then existing command will be removed.
*
* Date: 17.12.2015
* Time: 11:24
*
* @author Yuri Shmakov
*/
public class AddToEndSingleStrategy implements StateStrategy {
@Override
public void beforeApply(List> currentState, ViewCommand incomingCommand) {
Iterator> iterator = currentState.iterator();
while (iterator.hasNext()) {
ViewCommand entry = iterator.next();
if (entry.getClass() == incomingCommand.getClass()) {
iterator.remove();
break;
}
}
currentState.add(incomingCommand);
}
@Override
public void afterApply(List> currentState, ViewCommand incomingCommand) {
// pass
}
}