airport.dispatcher.weather.TemperatureCentigrade.java Source code

Java tutorial

Introduction

Here is the source code for airport.dispatcher.weather.TemperatureCentigrade.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 TemperatureCentigrade implements SetComponentWeather {

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

    private int degree;
    private final static String NAME = "";
    private final static String UNIT = "C";

    private final static int MAX_DEGREE = 50;
    private final static int MIN_DEGREE = -30;

    public TemperatureCentigrade() {
        degree = new Random().nextInt(MAX_DEGREE - MIN_DEGREE) + MIN_DEGREE;

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

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

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

        Random random = new Random();

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

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

    @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 degree;
    }

    @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");
        }

        degree = value;
    }

}