package me.Max.ue13;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Max on 25.09.2017.
 */
public class TempConverter {

    private final double in;
    private final TempUnit from;

    public TempConverter(double in, TempUnit from){
        this.in = in;
        this.from = from;
    }

    public Map<TempUnit, Double> computeValues(){
        Map<TempUnit, Double> map = new HashMap<>();
        map.put(TempUnit.C, toCelsius(in, from));
        map.put(TempUnit.F, toFahrenheit(in, from));
        map.put(TempUnit.K, toKelvin(in, from));
        return map;
    }

    private double toKelvin(double in, TempUnit u){
        switch (u){
            case C:
                return in + 273.15;
            case F:
                return (in - 32) * 5/9 + 273.15;
            case K:
                return in;
        }
        return 0;
    }

    private double toCelsius(double in, TempUnit u){
        return toKelvin(in, u) - 273.15;
    }
    private double toFahrenheit(double in, TempUnit u){
        return (toKelvin(in, u) - 273.15) * 9/5 + 32;
    }

}
