feat: 状态管理器新增是否可切换的检查.
This commit is contained in:
@@ -100,6 +100,11 @@ public abstract class AbstractStateManager<S> implements StateManager<S> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSwitchable() {
|
||||||
|
return stateList.size() > 1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将序号移动至下一个
|
* 将序号移动至下一个
|
||||||
* <li> 自动归零
|
* <li> 自动归零
|
||||||
|
|||||||
@@ -87,4 +87,9 @@ public final class BreakageUnidirectionalStateManager<S> extends DefaultUnidirec
|
|||||||
public void reset() {
|
public void reset() {
|
||||||
throw new UnsupportedOperationException("Cannot reset state for BreakageUnidirectionalStateManager!");
|
throw new UnsupportedOperationException("Cannot reset state for BreakageUnidirectionalStateManager!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSwitchable() {
|
||||||
|
return !isLast();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,4 +30,13 @@ public interface StateManager<S> {
|
|||||||
* 重置回默认状态, 一般为状态集合中的第一个
|
* 重置回默认状态, 一般为状态集合中的第一个
|
||||||
*/
|
*/
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否可切换
|
||||||
|
*
|
||||||
|
* @return 可切换返回真, 否则返回假
|
||||||
|
*/
|
||||||
|
default boolean isSwitchable() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,10 @@ public class ManagerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testBreakageUnidirectionalStateManager() {
|
public void testBreakageUnidirectionalStateManager() {
|
||||||
UnidirectionalStateManager<PrinterState> bum = new BreakageUnidirectionalStateManager<>(PrinterState.values());
|
UnidirectionalStateManager<PrinterState> bum = new BreakageUnidirectionalStateManager<>(PrinterState.values());
|
||||||
System.out.println(bum.isCircle());
|
|
||||||
bum.switchNext();
|
while (bum.isSwitchable()) {
|
||||||
|
System.out.println(bum.getAndSwitchNext());
|
||||||
|
}
|
||||||
|
System.out.println(bum.current());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user