Skip to content

Instantly share code, notes, and snippets.

@karlkilden
Last active April 4, 2016 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karlkilden/f6d0db08a4eeb99db499f08933d3eb26 to your computer and use it in GitHub Desktop.
Save karlkilden/f6d0db08a4eeb99db499f08933d3eb26 to your computer and use it in GitHub Desktop.
public class UnitSelection {
private Unit selectedUnit;
private List<Unit> units;
private boolean renderSelection;
public UnitSelection(List<Unit> units) {
this.units = units;
validateNotEmpty();
setupPreselectedAndRenderSelection();
}
private void setupPreselectedAndRenderSelection() {
if (units.size() == 1) {
setSelectedUnit(units.get(0));
this.units = null;
} else {
renderSelection = true;
}
}
protected void validateNotEmpty() {
if (CollectionUtils.isEmpty(this.units)) {
throw new IllegalArgumentException("At least one unit is required");
}
}
public Unit getSelectedUnit() {
return selectedUnit;
}
public void setSelectedUnit(Unit selectedUnit) {
this.selectedUnit = selectedUnit;
}
public boolean isRenderSelection() {
return renderSelection;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment