1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.linecorp.centraldogma.client.updater;
18
19 import static com.linecorp.centraldogma.internal.Util.validateFilePath;
20 import static java.util.Objects.requireNonNull;
21
22 import javax.annotation.Nullable;
23
24 import com.google.common.base.Strings;
25
26
27
28
29 public final class CentralDogmaBeanConfigBuilder {
30
31 @Nullable
32 private String project;
33 @Nullable
34 private String repository;
35 @Nullable
36 private String path;
37 @Nullable
38 private String jsonPath;
39
40
41
42
43 public CentralDogmaBeanConfigBuilder() {}
44
45
46
47
48
49 public CentralDogmaBeanConfigBuilder(CentralDogmaBeanConfig config) {
50 merge(config);
51 }
52
53
54
55
56 public CentralDogmaBeanConfigBuilder(CentralDogmaBean config) {
57 project = Strings.emptyToNull(config.project());
58 repository = Strings.emptyToNull(config.repository());
59 path = Strings.emptyToNull(config.path());
60 jsonPath = Strings.emptyToNull(config.jsonPath());
61 }
62
63
64
65
66 public CentralDogmaBeanConfigBuilder merge(CentralDogmaBeanConfig config) {
67 config.project().ifPresent(this::project);
68 config.repository().ifPresent(this::repository);
69 config.path().ifPresent(this::path);
70 config.jsonPath().ifPresent(this::jsonPath);
71 return this;
72 }
73
74
75
76
77 public CentralDogmaBeanConfigBuilder project(String project) {
78 this.project = requireNonNull(project, "project");
79 return this;
80 }
81
82
83
84
85 public CentralDogmaBeanConfigBuilder repository(String repository) {
86 this.repository = requireNonNull(repository, "repository");
87 return this;
88 }
89
90
91
92
93 public CentralDogmaBeanConfigBuilder path(String path) {
94 this.path = validateFilePath(path, "path");
95 return this;
96 }
97
98
99
100
101 public CentralDogmaBeanConfigBuilder jsonPath(String jsonPath) {
102 this.jsonPath = requireNonNull(jsonPath, "jsonPath");
103 return this;
104 }
105
106
107
108
109 public CentralDogmaBeanConfig build() {
110 return new CentralDogmaBeanConfig(project, repository, path, jsonPath);
111 }
112 }