27
27
public final class Dependency {
28
28
29
29
/**
30
+ * Returns a {@link DependencyBuilder} instance
30
31
* @return a {@link DependencyBuilder}
31
32
*/
32
33
public static DependencyBuilder builder () {
33
34
return new DependencyBuilder ();
34
35
}
35
36
37
+ /**
38
+ * Returns a {@link DependencyBuilder} based on a GAV - groupId:artifactId:version - parameter
39
+ * @return a {@link DependencyBuilder}
40
+ */
41
+ public static DependencyBuilder ofGav (String gav ) {
42
+ DependencyBuilder builder = builder ();
43
+ var gavValues = Arrays .stream (gav .split (":" ))
44
+ .filter (Objects ::nonNull )
45
+ .filter (item -> !item .isBlank ())
46
+ .map (String ::trim )
47
+ .collect (Collectors .toList ());
48
+ if (gavValues .size () >= 1 )
49
+ builder .withGroupId (gavValues .get (0 ));
50
+ if (gavValues .size () >= 2 )
51
+ builder .withArtifactId (gavValues .get (1 ));
52
+ if (gavValues .size () >= 3 )
53
+ builder .withVersion (gavValues .get (2 ));
54
+ return builder ;
55
+ }
56
+
57
+ /**
58
+ * Dependency builder
59
+ */
60
+ public static class DependencyBuilder {
61
+
62
+ private String groupId ;
63
+ private String artifactId ;
64
+ private String version ;
65
+ private String type ;
66
+ private String classifier ;
67
+ private String scope ;
68
+
69
+ /**
70
+ * @param groupId groupId
71
+ * @return the same {@link DependencyBuilder} instance
72
+ */
73
+ public DependencyBuilder withGroupId (String groupId ) {
74
+ this .groupId = groupId ;
75
+ return this ;
76
+ }
77
+
78
+ /**
79
+ * @param artifactId artifactId
80
+ * @return the same {@link DependencyBuilder} instance
81
+ */
82
+ public DependencyBuilder withArtifactId (String artifactId ) {
83
+ this .artifactId = artifactId ;
84
+ return this ;
85
+ }
86
+
87
+ /**
88
+ * @param version version
89
+ * @return the same {@link DependencyBuilder} instance
90
+ */
91
+ public DependencyBuilder withVersion (String version ) {
92
+ this .version = version ;
93
+ return this ;
94
+ }
95
+
96
+ /**
97
+ * @param type type
98
+ * @return the same {@link DependencyBuilder} instance
99
+ */
100
+ public DependencyBuilder withType (String type ) {
101
+ this .type = type ;
102
+ return this ;
103
+ }
104
+
105
+ /**
106
+ * @param classifier classifier
107
+ * @return the same {@link DependencyBuilder} instance
108
+ */
109
+ public DependencyBuilder withClassifier (String classifier ) {
110
+ this .classifier = classifier ;
111
+ return this ;
112
+ }
113
+
114
+ /**
115
+ * @param scope scope
116
+ * @return the same {@link DependencyBuilder} instance
117
+ */
118
+ public DependencyBuilder withScope (String scope ) {
119
+ this .scope = scope ;
120
+ return this ;
121
+ }
122
+
123
+ /**
124
+ * @return a {@link Dependency} instance
125
+ */
126
+ public Dependency build () {
127
+ return new Dependency (groupId , artifactId , version , type , classifier , scope );
128
+ }
129
+ }
130
+
36
131
private final String groupId ;
37
132
private final String artifactId ;
38
133
private final String version ;
39
134
private final String type ;
40
135
private final String classifier ;
41
136
private final String scope ;
42
137
43
- Dependency (String groupId , String artifactId , String version , String type , String classifier , String scope ) {
138
+ private Dependency (String groupId , String artifactId , String version , String type , String classifier , String scope ) {
44
139
if (groupId == null || groupId .isBlank ())
45
140
throw new IllegalArgumentException ("groupId must be provided" );
46
141
@@ -55,23 +150,6 @@ public static DependencyBuilder builder() {
55
150
this .scope = scope ;
56
151
}
57
152
58
- public static DependencyBuilder ofGav (String gav ) {
59
- DependencyBuilder builder = new DependencyBuilder ();
60
- var gavValues = Arrays .stream (gav .split (":" ))
61
- .filter (Objects ::nonNull )
62
- .filter (item -> !item .isBlank ())
63
- .map (String ::trim )
64
- .collect (Collectors .toList ());
65
- if (gavValues .size () >= 1 )
66
- builder .setGroupId (gavValues .get (0 ));
67
- if (gavValues .size () >= 2 )
68
- builder .setArtifactId (gavValues .get (1 ));
69
- if (gavValues .size () >= 3 )
70
- builder .setVersion (gavValues .get (2 ));
71
- return builder ;
72
- }
73
-
74
-
75
153
/**
76
154
* @return the groupId
77
155
*/
0 commit comments