franta-hg@107: package cz.frantovo.nekurak.dto; franta-hg@107: franta-hg@164: import java.util.logging.Level; franta-hg@164: import java.util.logging.Logger; franta-hg@164: franta-hg@107: /** franta-hg@107: * Agregovaný výsledek hlasování o tom, franta-hg@107: * zda se má v daném (jednom) podniku kouřit nebo ne. franta-hg@107: * @author fiki franta-hg@107: */ franta-hg@107: public class VysledekHlasovani { franta-hg@107: franta-hg@164: private static final Logger log = Logger.getLogger(VysledekHlasovani.class.getSimpleName()); franta-hg@145: private int hlasuAno; franta-hg@145: private int hlasuNe; franta-hg@164: private Podnik podnik; franta-hg@164: franta-hg@164: public VysledekHlasovani(Podnik podnik) { franta-hg@164: this.podnik = podnik; franta-hg@164: } franta-hg@107: franta-hg@145: /** franta-hg@145: * @return počet hlasů pro kuřácký podnik franta-hg@145: */ franta-hg@145: public int getHlasuAno() { franta-hg@145: return hlasuAno; franta-hg@145: } franta-hg@107: franta-hg@145: public void setHlasuAno(int pocet) { franta-hg@145: this.hlasuAno = pocet; franta-hg@145: } franta-hg@107: franta-hg@145: /** franta-hg@145: * @return počet hlasů pro nekuřácký podnik franta-hg@145: */ franta-hg@145: public int getHlasuNe() { franta-hg@145: return hlasuNe; franta-hg@145: } franta-hg@107: franta-hg@145: public void setHlasuNe(int pocet) { franta-hg@145: this.hlasuNe = pocet; franta-hg@145: } franta-hg@164: franta-hg@164: public Boolean getSpokojenost() { franta-hg@164: int k = podnik.getKurackost().getId(); franta-hg@164: franta-hg@165: if (k == 0 || (hlasuAno == 0 && hlasuNe == 0)) { franta-hg@164: /** neznámý stav → neznámá spokojenost */ franta-hg@164: return null; franta-hg@164: } else if (k == 1 || k == 4) { franta-hg@164: /** zakouřený podnik */ franta-hg@164: return hlasuAno > hlasuNe; franta-hg@164: } else if (k == 2) { franta-hg@164: /** nekuřácký podnik */ franta-hg@164: return hlasuAno < hlasuNe; franta-hg@164: } else if (k == 3) { franta-hg@164: /** důkladně oddělené části → pokud hlasování vyšlo mezi 35% a 65% bude spokojenost */ franta-hg@164: int soucet = hlasuAno + hlasuNe; franta-hg@164: return hlasuAno > 0.35 * soucet && hlasuAno < 0.65 * soucet; franta-hg@164: } else { franta-hg@165: log.log(Level.SEVERE, "Neznámá hodnota kuřáckosti: {0} u podniku: {1}", new Integer[]{k, podnik.getId()}); franta-hg@164: return null; franta-hg@164: } franta-hg@164: } franta-hg@107: }