change: 代码整理、定向切换时校验当前状态.

This commit is contained in:
2024-12-31 09:21:03 +08:00
parent 682266b591
commit 5fed1bbf19
9 changed files with 46 additions and 15 deletions

View File

@@ -61,11 +61,18 @@ public class DefaultUnidirectionalStateManager<S> extends AbstractStateManager<S
@Override
public boolean switchTo(S state) {
final int i;
if ((i = indexOf(state)) == -1 ||
i == currentIndex()) {
return false;
}
try {
writeLock.lock();
final int i;
if ((i = indexOf(state)) == -1 ||
(!isLast() && i < currentIndex()) ||
// 重新检查
if (i == currentIndex()) {
return false;
}
if ((!isLast() && i < currentIndex()) ||
(isLast() && i != getDefault())) {
return false;
}