class WorkspaceProviderImpl implements WorkspaceProvider {

    private final ProjectImpl project;
    private final List<Workspace> workspaces;
    private WorkspaceImpl currentWorkspace;

    public WorkspaceProviderImpl(ProjectImpl project) {
        this.project = project;
        workspaces = new ArrayList<>();
    }

    protected WorkspaceImpl newWorkspace() {
        return newWorkspace(project.nextWorkspaceId());
    }

    protected WorkspaceImpl newWorkspace(int id) {<FILL_FUNCTION_BODY>}

    protected void removeWorkspace(Workspace workspace) {
        synchronized (workspaces) {
            workspaces.remove(workspace);
        }
    }

    protected Workspace getPrecedingWorkspace(Workspace workspace) {
        Workspace[] ws = getWorkspaces();
        int index = -1;
        for (int i = 0; i < ws.length; i++) {
            if (ws[i] == workspace) {
                index = i;
            }
        }
        if (index >= 1) {
            //Get preceding
            return ws[index - 1];
        } else if (index == 0 && ws.length > 1) {
            //Get following
            return ws[1];
        }
        return null;
    }

    @Override
    public WorkspaceImpl getCurrentWorkspace() {
        synchronized (workspaces) {
            return currentWorkspace;
        }
    }

    protected void purge() {
        synchronized (workspaces) {
            workspaces.clear();
            this.currentWorkspace = null;
        }
    }

    protected void setCurrentWorkspace(Workspace currentWorkspace) {
        synchronized (workspaces) {
            if (this.currentWorkspace != null) {
                this.currentWorkspace.close();
            }
            this.currentWorkspace = (WorkspaceImpl) currentWorkspace;
            this.currentWorkspace.open();
        }
    }

    @Override
    public Workspace[] getWorkspaces() {
        synchronized (workspaces) {
            return workspaces.toArray(new Workspace[0]);
        }
    }

    @Override
    public Workspace getWorkspace(int id) {
        synchronized (workspaces) {
            for (Workspace w : workspaces) {
                if (w.getId() == id) {
                    return w;
                }
            }
            return null;
        }
    }

    @Override
    public boolean hasCurrentWorkspace() {
        synchronized (workspaces) {
            return currentWorkspace != null;
        }
    }
}

        synchronized (workspaces) {
            WorkspaceImpl workspace = new WorkspaceImpl(project, id);
            workspaces.add(workspace);
            return workspace;
        }
    
<no_super_class>