scijava / ui-behaviour

Configurable input handling, via mapped behaviours
Other
4 stars 2 forks source link

Pr behaviours pretty printing #21

Closed xulman closed 4 years ago

xulman commented 4 years ago

HI, here's a util-kind-of PR:

Example use case:

//behaviourMap and config defined outside
behaviourMap.keys().forEach( (s) -> {
                    System.out.print(s+" maps to: ");
                    System.out.println( InputTriggerConfig.prettyPrintInputs( config.getInputs(s,"all") )
} );
tpietzsch commented 4 years ago

I cherry-picked the InputTriggerConfig.prettyPrintInputs commit to master.

I'm not comfortable with the TreeSet keys. Not so much because of performance impact, but because it is an implementation detail that is not obvious through the API. If you call keys() you get a Set<String> and shouldn't make any assumptions. I would suggest that you either just wrap keys() in a new TreeSet<>() where you require it, or make another PR which adds a SortedSet<String> sortedKeys() method.

xulman commented 4 years ago

Thank you considering the PR and accepting the pretty printing commit.

I understand you reasoning w.r.t. TreeSet. Since the sortedKeys() would be building the TreeSet anyway (so we don't save anything performance-wise) and it is one-liner, I would leave it then on the client code to do whatever it wishes.. rather than creating/polluting API with getters in many flavors...