class SimpleStateManager implements StateManager {

    @Override
    public void updateState(Resource stateId, Model newState) throws MobiException {
        if (!stateExists(stateId)) {
            throw new IllegalArgumentException("State not found");
        }
        try (RepositoryConnection conn = repository.getConnection()) {
            Model stateModel = modelFactory.createModel(newState);
            conn.getStatements(stateId, null, null).forEach(stateModel::add);
            stateFactory.getExisting(stateId, stateModel).ifPresent(state -> {
                removeState(state, conn);
                state.setStateResource(newState.subjects());
                conn.add(state.getModel());
            });
        }
    }

}