Feuermagier / autograder

Automatic grading of student's Java code
MIT License
13 stars 7 forks source link

Suggest wrapper classes #483

Open Luro02 opened 3 months ago

Luro02 commented 3 months ago

What it does

Note the repeated if with throw

Lint Name

No response

Category

oop

Example

class A {
    public int changeAccesses(int id, String filePath, int newAccesses) throws DirectoryInconsistencyException {
        if (id < 0 || id >= directories.size()) {
            throw new DirectoryInconsistencyException(EXC_ID_INVALID);
        }
        return directories.get(id).changeAccesses(filePath, newAccesses);
    }

    public IGComputationTree run(int id) throws DirectoryInconsistencyException {
        if (id < 0 || id >= directories.size()) {
            throw new DirectoryInconsistencyException(EXC_ID_INVALID);
        }
        return  directories.get(id).runSplitting();
    }

    public ProbabilityDirectoryTree printDir(int id) throws DirectoryInconsistencyException {
        if (id < 0 || id >= directories.size()) {
            throw new DirectoryInconsistencyException(EXC_ID_INVALID);
        }
        return directories.get(id).getFileTree();
    }
}

Could be written as:

class A {
    public int changeAccesses(Id id, String filePath, int newAccesses) throws DirectoryInconsistencyException {
        return directories.get(id).changeAccesses(filePath, newAccesses);
    }

    public IGComputationTree run(Id id) throws DirectoryInconsistencyException {
        return  directories.get(id).runSplitting();
    }

    public ProbabilityDirectoryTree printDir(id id) throws DirectoryInconsistencyException {
        return directories.get(id).getFileTree();
    }
}