### Question:
TaskStateSnapshot implements CompositeStateHandle { public boolean hasState() { for (OperatorSubtaskState operatorSubtaskState : subtaskStatesByOperatorID.values()) { if (operatorSubtaskState != null && operatorSubtaskState.hasState()) { return true; } } return false; } TaskStateSnapshot();  TaskStateSnapshot(int size);  TaskStateSnapshot(Map<OperatorID, OperatorSubtaskState> subtaskStatesByOperatorID); @Nullable OperatorSubtaskState getSubtaskStateByOperatorID(OperatorID operatorID); OperatorSubtaskState putSubtaskStateByOperatorID(
		@Nonnull OperatorID operatorID,
		@Nonnull OperatorSubtaskState state); Set<Map.Entry<OperatorID, OperatorSubtaskState>> getSubtaskStateMappings(); boolean hasState(); @Override void discardState(); @Override long getStateSize(); @Override void registerSharedStates(SharedStateRegistry stateRegistry); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }### Answer:
@Test public void hasState() { Random random = new Random(0x42); TaskStateSnapshot taskStateSnapshot = new TaskStateSnapshot(); Assert.assertFalse(taskStateSnapshot.hasState()); OperatorSubtaskState emptyOperatorSubtaskState = new OperatorSubtaskState(); Assert.assertFalse(emptyOperatorSubtaskState.hasState()); taskStateSnapshot.putSubtaskStateByOperatorID(new OperatorID(), emptyOperatorSubtaskState); Assert.assertFalse(taskStateSnapshot.hasState()); OperatorStateHandle stateHandle = StateHandleDummyUtil.createNewOperatorStateHandle(2, random); OperatorSubtaskState nonEmptyOperatorSubtaskState = new OperatorSubtaskState( stateHandle, null, null, null ); Assert.assertTrue(nonEmptyOperatorSubtaskState.hasState()); taskStateSnapshot.putSubtaskStateByOperatorID(new OperatorID(), nonEmptyOperatorSubtaskState); Assert.assertTrue(taskStateSnapshot.hasState()); }
@Test public void hasState() { Random random = new Random(0x42); TaskStateSnapshot taskStateSnapshot = new TaskStateSnapshot(); Assert.assertFalse(taskStateSnapshot.hasState()); OperatorSubtaskState emptyOperatorSubtaskState = new OperatorSubtaskState(); Assert.assertFalse(emptyOperatorSubtaskState.hasState()); taskStateSnapshot.putSubtaskStateByOperatorID(new OperatorID(), emptyOperatorSubtaskState); Assert.assertFalse(taskStateSnapshot.hasState()); OperatorStateHandle stateHandle = StateHandleDummyUtil.createNewOperatorStateHandle(2, random); OperatorSubtaskState nonEmptyOperatorSubtaskState = new OperatorSubtaskState( stateHandle, null, null, null, null, null ); Assert.assertTrue(nonEmptyOperatorSubtaskState.hasState()); taskStateSnapshot.putSubtaskStateByOperatorID(new OperatorID(), nonEmptyOperatorSubtaskState); Assert.assertTrue(taskStateSnapshot.hasState()); }