Comments (9)
Depending on the quantity of units, would it be viable to map a unit's String
representation to itself (either via hashing or with some immutable radix tree implementation) for potentially faster access (if that method were to be added)?
Also, if a getUnit(String)
method is added, then I assume an appropriate UnitNotFoundException
or UnitDoesNotExistException
must be added with it.
If opinions from the community are taken into consideration, then I'm all for it 👍
from unit-api.
Thanks for the quick response. Community input is very welcome. Those who wish to contribute further e.g. via a PR must either join the JCP as Full or Associate member, depending if they want to join as Expert or Contributor (PR is usually fine for either) You are right, that if the string does not match available units either null
could be returned (that's the usual Map
behavior) or an exception thrown. If we need a special exception, an existing one like MeasurementException
or e.g. IllegalArgumentException
, etc. could be discussed. And of course from Java 8 there is also Optional
. We did not use it in another situation because it caused problems with the vital generic type safety, but it would be worth exploring if it could be used in this case.
from unit-api.
@keilw Thanks for the quick response as well! Luckily I'm already a Full Member of the JCP and would love to contribute to the JSR in any way that I can. I do agree that Optional
would be a good contender for this case and should be taken advantage of. However, there's still the case of someone passing null
to the function, and Optional.of(null)
throws a NullPointerException
.
from unit-api.
@jhg023 Thanks for the confirmation. If you are a full member and would like to help the API, please nominate yourself to join the JSR https://jcp.org/en/jsr/egnom?id=385. Full Members can chose between EG and Associate, too, I would say, if somebody is ready to do more than an occasional contribution or PR feel free to join the EG, Either way we welcome members of the Community. You are right about null
being passed, that is already caught in most other cases, e.g. UnitFormat.label()
etc. and we should handle it in a similar way.
P.s.: If you have a preference on unitsofmeasurement/indriya#17 please feel free to vote there with thumb up/down at any time. We still have not received too many preferences to make a final decision.
from unit-api.
Right now, SystemOfUnits
does not strictly specify, what to return in most cases. SystemOfUnitsService
however states for the getter, it "Returns the system of units having the specified name or null
if none." This could be a possible pattern to use.
from unit-api.
@keilw Thanks for the suggestion; I'd be happy to nominate myself! Also, seeing as you're currently compiling with Java 7, returning null
would suffice. If the minimum Java version ever changes, then I suppose it could be looked at further.
from unit-api.
@jhg023 Happy if you joined the EG. Indriya (or prior implementations) also would sometimes return null
e.g. if a Dimension
is passed that has no unit, but there or in uom-se we already apply Lambdas and Streams
. Even with Java 8 as minimal version (the 2.0 API might do that as most other JSRs also require it now) we must remain backward-compatible so where SystemOfUnitsService
returned null now, we have to be very careful not to break that, but in places where it has not been strictly specified, we can do so now.
from unit-api.
@keilw I just did! I also understand how important backwards compatibility is for a JSR. I'll make sure to keep any modifications to Java 7 standards for now. Also, I apologize for getting off-topic, but should a suggestion be submitted as a PR or as an issue (before a PR is made for discussion)?
from unit-api.
In SystemOfUnitsService
the getSystemOfUnits(String name)
method is specified
Returns the system of units having the specified name or null if none.
So I think returning null
is OK here as well, if a wrong or non-existent string was passed.
from unit-api.
Related Issues (20)
- Improve code coverage of ServiceProvider HOT 3
- Fix problem with maven-javadoc-plugin
- MR 1 Spec Review
- Could Quantity use a symbol, too? HOT 1
- Upgrade JDK to Java 11 or higher
- Replace Bintray/JCenter in API build settings
- Enable discovery of prefix classes via SPI HOT 1
- Improve the JavaDoc of UnitFormat
- Remove unnecessary OSGI imports
- Convert Quantity to most fitting Prefix HOT 7
- improve interoperability of Quantity with Hibernate JPA HOT 7
- Should not cache the ServiceProvider implementation HOT 8
- Incorporate the new SI Prefixes
- Upgrade CI JDK to Java 17 or higher
- Update module-info
- Replace tabulations by 4 spaces HOT 2
- Should we deprecate MetricPrefix.DEKA()? HOT 4
- Update Spec Document for MR2 HOT 5
- enum missing in javax.measure.MetricPrefix HOT 2
- Units can have non-integer Dimension HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unit-api.