Skip to content

Add support for n-ary converterΒ #1305

@martlin2cz

Description

@martlin2cz

Hello,

I would like to get following command created:

set-position 41 43

I have prepared the Command class with the parameters declaration as follows:

@Command(name = "set-position")
public class SetPositionCommand implements Runnable {
	@Parameters(arity = "2")
	private List<Integer> coords;

	// ... 
}

However, I would like to get the coords list automatically converted to my data class. Currently, I have to do it by hand:

	Point position = new Point(coords.get(0), coords.get(1));

I was thinking about utilizing the ITypeConverter, like so:

	@Parameters(arity = "2", converter = PointConverter.class)
	private Point position;

looking like:

public class PointConverter implements ITypeConverter<Point> {
	@Override
	public abstract T convert(List<String> values) throws Exception {
		return Point(Integer.parseInt(values.get(0)), Integer.parseInt(values.get(1)));
	}

But, the ITypeConverter maps 1 parameter to 1 object, not all of them into one.

Quite obviously, there would be new converter interface needed to be created (something like IMultiTypeConverter).

BTW is there any other workaround?

Thanks,
Martin

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions