Last active
April 4, 2016 13:53
-
-
Save karlkilden/f6d0db08a4eeb99db499f08933d3eb26 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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