Giter Site home page Giter Site logo

Comments (9)

jhg023 avatar jhg023 commented on May 20, 2024

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.

keilw avatar keilw commented on May 20, 2024

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.

jhg023 avatar jhg023 commented on May 20, 2024

@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.

keilw avatar keilw commented on May 20, 2024

@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.

keilw avatar keilw commented on May 20, 2024

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.

jhg023 avatar jhg023 commented on May 20, 2024

@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.

keilw avatar keilw commented on May 20, 2024

@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.

jhg023 avatar jhg023 commented on May 20, 2024

@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.

keilw avatar keilw commented on May 20, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.