com.github.bloodshura.x.utilities.temperature.Temperature Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of shurax-utilities Show documentation
Show all versions of shurax-utilities Show documentation
A collection of general utilities.
The newest version!
/*
* Copyright (c) 2013-2018, João Vitor Verona Biazibetti - All Rights Reserved
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*
* https://www.github.com/BloodShura
*/
package com.github.bloodshura.x.utilities.temperature;
import com.github.bloodshura.x.utilities.eval.exception.EvaluationException;
import com.github.bloodshura.x.worker.StringWorker;
import javax.annotation.Nonnull;
import java.util.function.DoubleFunction;
public enum Temperature {
CELSIUS("C", x -> x - 273.15, x -> x + 273.15),
DELISLE("D", x -> (373.15 - x) * (3 / 2), x -> 373.15 - (x * (2 / 3))),
FAHRENHEIT("F", x -> (x - 273.15) * (9 / 5) + 32, x -> (x - 32) * (5 / 9) + 273.15),
KELVIN("K", x -> x, x -> x),
NEWTON("N", x -> (x - 273.15) * 0.33, x -> (x / 0.33) + 273.15),
RANKINE("Ra", x -> x * (9 / 5), x -> x * (5 / 9)),
REAUMUR("Re", x -> (x - 273.15) * (4 / 5), x -> x * (5 / 4) + 273.15),
ROMER("Rø", x -> (x - 273.15) * (21 / 40) + 7.5, x -> (x - 7.5) * (40 / 21) + 273.15);
private final DoubleFunction fromKelvin;
private final String name;
private final String suffix;
private final DoubleFunction toKelvin;
private Temperature(@Nonnull String suffix, @Nonnull DoubleFunction fromKelvin, @Nonnull DoubleFunction toKelvin) throws EvaluationException {
this.fromKelvin = fromKelvin;
this.name = StringWorker.capitalizeFully(name());
this.suffix = suffix;
this.toKelvin = toKelvin;
}
public double convert(@Nonnull Temperature target, double value) {
double kelvin = toKelvin.apply(value);
return target.fromKelvin.apply(kelvin);
}
@Nonnull
public String getName() {
return name;
}
@Nonnull
public String getSuffix() {
return suffix;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy