Skip to content

Add conversion support to MeasureUnit #3512

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

younies
Copy link
Member

@younies younies commented Jun 1, 2025

Description

This update introduces the followings

  • The ConversionInfo class to the MeasureUnit, which encapsulates conversion details such as conversion rates and offsets to the base unit.
  • Additionally, a new method, convertFrom, is implemented to facilitate conversions between MeasureUnits, ensuring proper handling of mixed units and convertibility checks.
  • The constructor for MeasureUnit is also updated to accommodate the new conversion information.

TODO: Please describe your changes here.

TODO: Please read the following on ICU Contributing, and then delete these instructions.

Thank you for your pull request!

TODO: Fill out the checklist below.

Checklist

  • Required: Issue filed: ICU-NNNNN
  • Required: The PR title must be prefixed with a JIRA Issue number. Example: "ICU-1234 Fix xyz"
  • Required: Each commit message must be prefixed with a JIRA Issue number. Example: "ICU-1234 Fix xyz"
  • Issue accepted (done by Technical Committee after discussion)
  • Tests included, if applicable
  • API docs and/or User Guide docs changed or added, if applicable

This update introduces the ConversionInfo class to the MeasureUnit, which encapsulates conversion details such as conversion rates and offsets to the base unit. Additionally, a new method, convertFrom, is implemented to facilitate conversions between MeasureUnits, ensuring proper handling of mixed units and convertibility checks. The constructor for MeasureUnit is also updated to accommodate the new conversion information. This enhancement aims to improve the functionality and usability of unit conversions within the ICU library.
Copy link
Member

@macchiati macchiati left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking pretty good

// If the conversionInfo is null, then the conversion info is not set for this
// unit.
private final ConversionInfo conversionInfo;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cache of measure units should use ConcurrentHashMaps, not synchronization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants