Skip to content

refactor: Enhance docs in UnitConversions #5945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,47 @@
import java.util.Map;
import org.apache.commons.lang3.tuple.Pair;

/**
* A utility class to perform unit conversions between different measurement systems.
*
* <p>Currently, the class supports temperature conversions between several scales:
* Celsius, Fahrenheit, Kelvin, Réaumur, Delisle, and Rankine.
*
* <h2>Example Usage</h2>
* <pre>
* double result = UnitConversions.TEMPERATURE.convert("Celsius", "Fahrenheit", 100.0);
* // Output: 212.0 (Celsius to Fahrenheit conversion of 100°C)
* </pre>
*
* <p>This class makes use of an {@link UnitsConverter} that handles the conversion logic
* based on predefined affine transformations. These transformations include scaling factors
* and offsets for temperature conversions.
*
* <h2>Temperature Scales Supported</h2>
* <ul>
* <li>Celsius</li>
* <li>Fahrenheit</li>
* <li>Kelvin</li>
* <li>Réaumur</li>
* <li>Delisle</li>
* <li>Rankine</li>
* </ul>
*/
public final class UnitConversions {
private UnitConversions() {
}

/**
* A preconfigured instance of {@link UnitsConverter} for temperature conversions.
* The converter handles conversions between the following temperature units:
* <ul>
* <li>Kelvin to Celsius</li>
* <li>Celsius to Fahrenheit</li>
* <li>Réaumur to Celsius</li>
* <li>Delisle to Celsius</li>
* <li>Rankine to Kelvin</li>
* </ul>
*/
public static final UnitsConverter TEMPERATURE = new UnitsConverter(Map.ofEntries(entry(Pair.of("Kelvin", "Celsius"), new AffineConverter(1.0, -273.15)), entry(Pair.of("Celsius", "Fahrenheit"), new AffineConverter(9.0 / 5.0, 32.0)),
entry(Pair.of("Réaumur", "Celsius"), new AffineConverter(5.0 / 4.0, 0.0)), entry(Pair.of("Delisle", "Celsius"), new AffineConverter(-2.0 / 3.0, 100.0)), entry(Pair.of("Rankine", "Kelvin"), new AffineConverter(5.0 / 9.0, 0.0))));
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

public class UnitConversionsTest {
private static void addData(Stream.Builder<Arguments> builder, Map<String, Double> values) {
for (final var first : values.entrySet()) {
for (final var second : values.entrySet()) {
for (var first : values.entrySet()) {
for (var second : values.entrySet()) {
if (!first.getKey().equals(second.getKey())) {
builder.add(Arguments.of(first.getKey(), second.getKey(), first.getValue(), second.getValue()));
}
Expand Down