unitsofmeasurement / indriya

JSR 385 - Reference Implementation
Other
115 stars 40 forks source link

allow subclasses of SimpleUnitFormat to reuse its labels and aliases #317

Closed andi-huber closed 3 years ago

andi-huber commented 3 years ago

in reference to #316

just a bit of refactoring, not changing any logic or behavior, keeping all side effects

this allows users now to write code like

public abstract class GeoToolsUnitFormat extends SimpleUnitFormat {

    private static BaseGT2Format INSTANCE;

    static {
        INSTANCE = new BaseGT2Format();
    }

    public static BaseGT2Format getInstance() {
        return INSTANCE;
    }

    /**
     * Base class that just copies {@link UnitFormat} default instance contents
     */
    protected static class BaseGT2Format extends DefaultFormat {

        public BaseGT2Format() {
            super.initDefaultFormat(this);
        }

    }
}

I'm also aware of the discussion, that maybe extending SimpleUnitFormat is not the best approach, and we potentially might not encourage people to do so.


This change is Reviewable

jodygarnett commented 3 years ago

This would be great to see released (we have a release candidate of GeoTools scheduled for March 1st.)

keilw commented 3 years ago

Yes, that'll work. At least for proper JavaDoc in the Maven artifacts we expect the API first, as a patch release 2.1.2 that changes nothing else probably by the 12th and the RI follows at most until the 21st.