java/nekurak.net-lib/src/cz/frantovo/nekurak/dto/VysledekHlasovani.java
author František Kučera <franta-hg@frantovo.cz>
Wed Jan 12 16:15:37 2011 +0100 (2011-01-12)
changeset 164 e146e2e3b80b
parent 145 0efefbf5f8b6
child 165 cdfc1e9e3a1b
permissions -rw-r--r--
Spokojenost: soulad kuřáckosti podniku s výsledky hlasování.
franta-hg@107
     1
package cz.frantovo.nekurak.dto;
franta-hg@107
     2
franta-hg@164
     3
import java.util.logging.Level;
franta-hg@164
     4
import java.util.logging.Logger;
franta-hg@164
     5
franta-hg@107
     6
/**
franta-hg@107
     7
 * Agregovaný výsledek hlasování o tom,
franta-hg@107
     8
 * zda se má v daném (jednom) podniku kouřit nebo ne.
franta-hg@107
     9
 * @author fiki
franta-hg@107
    10
 */
franta-hg@107
    11
public class VysledekHlasovani {
franta-hg@107
    12
franta-hg@164
    13
	private static final Logger log = Logger.getLogger(VysledekHlasovani.class.getSimpleName());
franta-hg@164
    14
franta-hg@145
    15
	private int hlasuAno;
franta-hg@145
    16
	private int hlasuNe;
franta-hg@164
    17
	private Podnik podnik;
franta-hg@164
    18
franta-hg@164
    19
	public VysledekHlasovani(Podnik podnik) {
franta-hg@164
    20
		this.podnik = podnik;
franta-hg@164
    21
	}
franta-hg@107
    22
franta-hg@145
    23
	/**
franta-hg@145
    24
	 * @return počet hlasů pro kuřácký podnik
franta-hg@145
    25
	 */
franta-hg@145
    26
	public int getHlasuAno() {
franta-hg@145
    27
		return hlasuAno;
franta-hg@145
    28
	}
franta-hg@107
    29
franta-hg@145
    30
	public void setHlasuAno(int pocet) {
franta-hg@145
    31
		this.hlasuAno = pocet;
franta-hg@145
    32
	}
franta-hg@107
    33
franta-hg@145
    34
	/**
franta-hg@145
    35
	 * @return počet hlasů pro nekuřácký podnik
franta-hg@145
    36
	 */
franta-hg@145
    37
	public int getHlasuNe() {
franta-hg@145
    38
		return hlasuNe;
franta-hg@145
    39
	}
franta-hg@107
    40
franta-hg@145
    41
	public void setHlasuNe(int pocet) {
franta-hg@145
    42
		this.hlasuNe = pocet;
franta-hg@145
    43
	}
franta-hg@164
    44
franta-hg@164
    45
	public Boolean getSpokojenost() {
franta-hg@164
    46
		int k = podnik.getKurackost().getId();
franta-hg@164
    47
franta-hg@164
    48
		if (k == 0) {
franta-hg@164
    49
			/** neznámý stav → neznámá spokojenost */
franta-hg@164
    50
			return null;
franta-hg@164
    51
		} else if (k == 1 || k == 4) {
franta-hg@164
    52
			/** zakouřený podnik */
franta-hg@164
    53
			return hlasuAno > hlasuNe;
franta-hg@164
    54
		} else if (k == 2) {
franta-hg@164
    55
			/** nekuřácký podnik */
franta-hg@164
    56
			return hlasuAno < hlasuNe;
franta-hg@164
    57
		} else if (k == 3) {
franta-hg@164
    58
			/** důkladně oddělené části → pokud hlasování vyšlo mezi 35% a 65% bude spokojenost */
franta-hg@164
    59
			int soucet = hlasuAno + hlasuNe;
franta-hg@164
    60
			return hlasuAno > 0.35 * soucet && hlasuAno < 0.65 * soucet;
franta-hg@164
    61
		} else {
franta-hg@164
    62
			log.log(Level.SEVERE, "Neznámá hodnota kuřáckosti: {0} u podniku: {1}", new Integer[] {k, podnik.getId()});
franta-hg@164
    63
			return null;
franta-hg@164
    64
		}
franta-hg@164
    65
	}
franta-hg@107
    66
}