Skip to content
This repository was archived by the owner on Jun 10, 2024. It is now read-only.

Commit e68e564

Browse files
committed
feat: removed guava
1 parent 1a51ecd commit e68e564

File tree

4 files changed

+29
-75
lines changed

4 files changed

+29
-75
lines changed

pom.xml

-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
<maven.compiler.target>1.8</maven.compiler.target>
2828

2929
<spring-boot.version>2.4.5</spring-boot.version>
30-
<guava.version>30.1.1-jre</guava.version>
3130
</properties>
3231

3332
<scm>
@@ -53,11 +52,6 @@
5352
<groupId>org.springframework</groupId>
5453
<artifactId>spring-web</artifactId>
5554
</dependency>
56-
<dependency>
57-
<groupId>com.google.guava</groupId>
58-
<artifactId>guava</artifactId>
59-
<version>${guava.version}</version>
60-
</dependency>
6155
<dependency>
6256
<groupId>com.fasterxml.jackson.core</groupId>
6357
<artifactId>jackson-databind</artifactId>

src/main/java/io/rocketbase/toggl/report/AbstractBaseRequestChain.java

+8-25
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.rocketbase.toggl.report;
22

3-
import com.google.common.base.Joiner;
43
import io.rocketbase.toggl.report.model.Billable;
54
import io.rocketbase.toggl.report.model.DisplayHours;
65
import org.springframework.core.ParameterizedTypeReference;
@@ -75,9 +74,7 @@ public T clientIds(String... ids) {
7574
public T clientIds(List<String> ids) {
7675
super.getUriBuilder()
7776
.addParameter("client_ids",
78-
Joiner.on(",")
79-
.skipNulls()
80-
.join(ids));
77+
String.join(",", ids));
8178
return (T) this;
8279
}
8380

@@ -91,9 +88,7 @@ public T projectIds(String... ids) {
9188
public T projectIds(List<String> ids) {
9289
super.getUriBuilder()
9390
.addParameter("project_ids",
94-
Joiner.on(",")
95-
.skipNulls()
96-
.join(ids));
91+
String.join(",", ids));
9792
return (T) this;
9893
}
9994

@@ -104,9 +99,7 @@ public T userIds(String... ids) {
10499
public T userIds(List<String> ids) {
105100
super.getUriBuilder()
106101
.addParameter("user_ids",
107-
Joiner.on(",")
108-
.skipNulls()
109-
.join(ids));
102+
String.join(",", ids));
110103
return (T) this;
111104
}
112105

@@ -120,9 +113,7 @@ public T membersOfGroupIds(String... ids) {
120113
public T membersOfGroupIds(List<String> ids) {
121114
super.getUriBuilder()
122115
.addParameter("members_of_group_ids",
123-
Joiner.on(",")
124-
.skipNulls()
125-
.join(ids));
116+
String.join(",", ids));
126117
return (T) this;
127118
}
128119

@@ -136,9 +127,7 @@ public T orMembersOfGroupIds(String... ids) {
136127
public T orMembersOfGroupIds(List<String> ids) {
137128
super.getUriBuilder()
138129
.addParameter("or_members_of_group_ids",
139-
Joiner.on(",")
140-
.skipNulls()
141-
.join(ids));
130+
String.join(",", ids));
142131
return (T) this;
143132
}
144133

@@ -152,9 +141,7 @@ public T tagIds(String... ids) {
152141
public T tagIds(List<String> ids) {
153142
super.getUriBuilder()
154143
.addParameter("tag_ids",
155-
Joiner.on(",")
156-
.skipNulls()
157-
.join(ids));
144+
String.join(",", ids));
158145
return (T) this;
159146
}
160147

@@ -168,9 +155,7 @@ public T taskIds(String... ids) {
168155
public T taskIds(List<String> ids) {
169156
super.getUriBuilder()
170157
.addParameter("task_ids",
171-
Joiner.on(",")
172-
.skipNulls()
173-
.join(ids));
158+
String.join(",", ids));
174159
return (T) this;
175160
}
176161

@@ -181,9 +166,7 @@ public T timeEntryIds(String... ids) {
181166
public T timeEntryIds(List<String> ids) {
182167
super.getUriBuilder()
183168
.addParameter("time_entry_ids",
184-
Joiner.on(",")
185-
.skipNulls()
186-
.join(ids));
169+
String.join(",", ids));
187170
return (T) this;
188171
}
189172

src/main/java/io/rocketbase/toggl/report/RequestChain.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.rocketbase.toggl.report;
22

3-
import com.google.common.base.Optional;
4-
import com.google.common.base.Preconditions;
3+
import java.util.Objects;
4+
import java.util.Optional;
55

66
class RequestChain {
77

@@ -12,14 +12,14 @@ class RequestChain {
1212
private final String path;
1313

1414
public RequestChain(RequestContext context, String path) {
15-
Preconditions.checkNotNull(context);
15+
Objects.nonNull(context);
1616
this.context = context;
1717
this.path = path;
18-
this.parent = Optional.absent();
18+
this.parent = Optional.empty();
1919
}
2020

2121
public RequestChain(RequestChain parent, String path) {
22-
Preconditions.checkNotNull(parent);
22+
Objects.nonNull(parent);
2323
this.context = parent.getContext();
2424
this.parent = Optional.of(parent);
2525
this.path = path;
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
package io.rocketbase.toggl.report;
22

3-
import com.google.common.base.Function;
4-
import com.google.common.base.Joiner;
5-
import com.google.common.base.Preconditions;
6-
import com.google.common.collect.Iterables;
7-
import com.google.common.collect.Lists;
3+
import org.springframework.web.util.UriComponentsBuilder;
84

95
import java.util.*;
106

@@ -13,29 +9,29 @@ public class RestUriBuilder {
139
private String host;
1410
private String protocol = "https";
1511
private StringBuilder path;
16-
private Map<String, List<String>> parameters = new HashMap<String, List<String>>();
12+
private Map<String, Collection> parameters = new HashMap<>();
1713

1814
public RestUriBuilder host(String host) {
19-
Preconditions.checkNotNull(host);
15+
Objects.nonNull(host);
2016
this.host = host;
2117
return this;
2218
}
2319

2420
public RestUriBuilder protocol(String protocol) {
25-
Preconditions.checkNotNull(protocol);
21+
Objects.nonNull(protocol);
2622
this.protocol = protocol;
2723
return this;
2824
}
2925

3026
public RestUriBuilder path(String path) {
31-
Preconditions.checkNotNull(path);
27+
Objects.nonNull(path);
3228
this.path = new StringBuilder();
3329
this.path.append(path);
3430
return this;
3531
}
3632

3733
public RestUriBuilder appendPath(String path) {
38-
Preconditions.checkNotNull(path);
34+
Objects.nonNull(path);
3935
this.path.append(path);
4036
return this;
4137
}
@@ -44,40 +40,21 @@ public RestUriBuilder addParameter(String key, Object value) {
4440
return addParameters(key, Collections.singletonList(value));
4541
}
4642

47-
public RestUriBuilder addParameters(String key, Collection<?> value) {
48-
Preconditions.checkNotNull(key);
49-
Preconditions.checkNotNull(value);
50-
Iterable<String> stringValues = Iterables.transform(value, new Function<Object, String>() {
51-
public String apply(Object o) {
52-
return String.valueOf(o);
53-
}
54-
});
55-
this.parameters.put(key, Lists.newArrayList(stringValues));
43+
public RestUriBuilder addParameters(String key, Collection<? extends Object> value) {
44+
Objects.nonNull(key);
45+
Objects.nonNull(value);
46+
this.parameters.putIfAbsent(key, new ArrayList<>());
47+
this.parameters.get(key).addAll(value);
5648
return this;
5749
}
5850

5951
public String build() {
60-
StringBuilder builder = new StringBuilder();
61-
builder.append(protocol);
62-
builder.append("://");
63-
Preconditions.checkNotNull(host);
64-
Preconditions.checkNotNull(path);
65-
builder.append(host);
66-
builder.append(path);
52+
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(protocol + "://" + host + path);
6753
if (!parameters.isEmpty()) {
68-
builder.append("?");
69-
Joiner.on("&")
70-
.appendTo(builder, Iterables.transform(parameters.entrySet(), new Function<Map.Entry<String, List<String>>, String>() {
71-
public String apply(final Map.Entry<String, List<String>> stringStringEntry) {
72-
return Joiner.on("&")
73-
.join(Lists.transform(stringStringEntry.getValue(), new Function<String, String>() {
74-
public String apply(String s) {
75-
return stringStringEntry.getKey() + "=" + s;
76-
}
77-
}));
78-
}
79-
}));
54+
for (Map.Entry<String, Collection> entry : parameters.entrySet()) {
55+
builder.queryParam(entry.getKey(), entry.getValue());
56+
}
8057
}
81-
return builder.toString();
58+
return builder.toUriString();
8259
}
8360
}

0 commit comments

Comments
 (0)