I have the following enum
public enum StudentType {
Domestic, International;
}
and a Student class with the following constructor:
//Left out additonal parameters and validation
public Student(StudentType type, List<String> documents){
if(type == null){
throw new IllegalArgumentException("You must provide Student type");
}
this.type = type;
this.documents = this.validateList(documents);
}
and a private method to validate the list:
private List<String> validateList(List<String> validate){
if(this.type == StudentType.Domestic && validate.isEmpty()){
return validate;
}
else
if(this.type == StudentType.Domestic && !validate.isEmpty()){
return Collections.emptyList();
}
return new ArrayList<String>(validate);
}
My plan to make the Student class immutable.
Explanation:
Only students that are International require documentation(passports, etc). Domestic students don't require any documentation.
In my constructor I check to make sure the type isn't null, the client must provide either domestic or international.
In my private validateList method I check the student type, and if the List is empty or not. If it's domestic and empty, return the list, if it's domensitc and not empty, return an empty collection, otherwise return the ArrayList<String> of documents.
My question concerns if checking the type in the private method is code smell? My concern is that one parameter(list of documents), is determined/validated by the type of student. If checking the type in the private method is code smell, what should I do instead?