airport.dispatcher.weather.Humidity.java Source code

Java tutorial

Introduction

Here is the source code for airport.dispatcher.weather.Humidity.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package airport.dispatcher.weather;

import java.util.Random;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

/**
 *
 * @author mcdoker
 */
public class Humidity implements SetComponentWeather {

    private final static Logger LOG = Logger.getLogger(Humidity.class);

    private int value;
    private final static String NAME = "?";
    private final static String UNIT = "% .";

    private final static int MAX_DEGREE = 100;
    private final static int MIN_DEGREE = 50;

    public Humidity() {
        value = new Random().nextInt(MAX_DEGREE - MIN_DEGREE) + MIN_DEGREE;

        if (LOG.isInfoEnabled()) {
            LOG.info("create Humidity");
        }
    }

    @Override
    public void update() {
        if (value == MAX_DEGREE) {
            value--;
            return;
        }

        if (value == MIN_DEGREE) {
            value++;
            return;
        }

        Random random = new Random();

        if (random.nextBoolean()) {
            value++;
        } else {
            value--;
        }

        if (LOG.isInfoEnabled()) {
            LOG.info("update Humidity. New value : " + value);
        }
    }

    @Override
    public String getName() {
        if (LOG.isInfoEnabled()) {
            LOG.info("get name");
        }

        return NAME;
    }

    @Override
    public int getValue() {
        if (LOG.isInfoEnabled()) {
            LOG.info("get value");
        }

        return value;
    }

    @Override
    public String getUnit() {
        if (LOG.isInfoEnabled()) {
            LOG.info("get unit");
        }

        return UNIT;
    }

    @Override
    public void setValue(int value) {
        if (LOG.isInfoEnabled()) {
            LOG.info("set value");
        }

        this.value = value;
    }
}