3
@Parameters(index = "0")
private Double min_c_re;

@Parameters(index = "1")
private Double min_c_im;

@Parameters(index = "2")
private Double max_c_re;

@Parameters(index = "3")
private Double max_c_im;

@Parameters(index = "4")
private Integer max_n;

@Parameters(index = "5")
private Integer width;

@Parameters(index = "6")
private Integer height;

@Parameters(index = "7")
private Integer divisions;

@Parameters(index = "8", arity = "1..*")
private List<URL> hosts;

@Override
public void run() {
    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
    List<SubDivider.SubDivision> subDividedImages = new SubDivider(divisions, divisions).divide(image);

    ExecutorService threadPool = Executors.newCachedThreadPool();
    double realRange = max_c_re - min_c_re;
    double imaginaryRange = max_c_im - min_c_im;

    for (int i = 0; i < subDividedImages.size(); i++) {
        SubDivider.SubDivision subDivision = subDividedImages.get(i);
        BufferedImage subDividedImage = subDivision.getImage();
        URL host = hosts.get(i % hosts.size());

        double xPercent = subDivision.getOriginalMinX() / (double) width;
        double yPercent = subDivision.getOriginalMinY() / (double) height;
        double widthPercent = subDividedImage.getWidth() / (double) width;
        double heightPercent = subDividedImage.getHeight() / (double) height;

        String resource = new StringJoiner("/")
                             .add("/mandelbrot")
                             .add(Double.toString(min_c_re + realRange * xPercent))
                             .add(Double.toString(min_c_im + imaginaryRange * yPercent))
                             .add(Double.toString(min_c_re + realRange * xPercent + realRange * widthPercent))
                             .add(Double.toString(min_c_im + imaginaryRange * yPercent + imaginaryRange * heightPercent))
                             .add(Integer.toString(subDividedImage.getWidth()))
                             .add(Integer.toString(subDividedImage.getHeight()))
                             .add(Integer.toString(max_n))
                             .toString();

        URL url;
        try {
            url = new URL(host, resource);
        } catch (MalformedURLException exception) {
            System.err.println("Exception: " +
                               exception.getMessage());
            return;
        }

        threadPool.submit(new SubDivisionGenerator(url, subDividedImage));
    }

    try {
        threadPool.shutdown();
        threadPool.awaitTermination(1, TimeUnit.HOURS);
    } catch (InterruptedException exception) {
        System.err.println("Exception: "
                           + exception.getMessage());
        return;
    }

    File file = new File("output.pgm");
    HashMap<String, Object> params = new HashMap<>();

    try {
        Imaging.writeImage(image, file, ImageFormats.PGM, params);
    } catch (ImageWriteException | IOException exception) {
        System.err.println("Exception: "
                           + exception.getMessage());
        return;
    }
}

当我运行命令时java -jar target/cli-1.0.0.jar -1 -1.5 2 1.5 1024 10000 10000 4 http://localhost:8080

我得到这个例外:

Could not convert 'https://localhost:8080' to Integer for positional parameter at index 6 (<height>): java.lang.NumberFormatException: For input string: "https://localhost:8080"

使用 picocli 版本 2.3.0

4

2 回答 2

5

尝试双破折号https://picocli.info/#_double_dash

java -jar target/cli-1.0.0.jar -- -1 -1.5 2 1.5 1024 10000 10000 4 http://localhost:8080

不能在命令行上直接传递负数。它们未被识别为位置参数,因此表示您的网址位于位置 6

于 2020-04-06T09:33:22.490 回答
3

负数中的破折号使它们看起来像选项。尝试使用标志:

CommandLine.setUnmatchedOptionsArePositionalParams(true)
于 2020-04-06T09:39:29.497 回答