/
Options.java
68 lines (51 loc) · 1.61 KB
/
Options.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package com.moczul.ok2curl;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
public class Options {
public static final Options EMPTY = new Options(Collections.<String>emptyList());
private final List<String> options;
public static Builder builder() {
return new Builder();
}
private Options(Collection<String> options) {
this.options = new ArrayList<>(options);
}
public List<String> list() {
return options;
}
public static class Builder {
private final Set<String> options = new HashSet<>();
public Builder insecure() {
options.add("--insecure");
return this;
}
public Builder maxTime(int seconds) {
options.add(String.format(Locale.getDefault(), "--max-time %d", seconds));
return this;
}
public Builder connectTimeout(int seconds) {
options.add(String.format(Locale.getDefault(), "--connect-timeout %d", seconds));
return this;
}
public Builder retry(int num) {
options.add(String.format(Locale.getDefault(), "--retry %d", num));
return this;
}
public Builder compressed() {
options.add("--compressed");
return this;
}
public Builder location() {
options.add("--location");
return this;
}
public Options build() {
return new Options(options);
}
}
}