Skip to content

Commit 3766616

Browse files
committed
Reduce dependency to lang3 library
1 parent c588eac commit 3766616

44 files changed

Lines changed: 322 additions & 152 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cloudplatform/cloudplatform-connectivity/src/main/java/com/sap/cloud/sdk/cloudplatform/connectivity/ComplexDestinationPropertyFactory.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@
1111
import javax.annotation.Nonnull;
1212
import javax.annotation.Nullable;
1313

14-
import org.apache.commons.lang3.StringUtils;
15-
1614
import com.google.common.net.HttpHeaders;
1715
import com.sap.cloud.sdk.cloudplatform.connectivity.exception.DestinationAccessException;
1816
import com.sap.cloud.sdk.cloudplatform.security.BasicCredentials;
1917
import com.sap.cloud.sdk.cloudplatform.security.BearerCredentials;
2018
import com.sap.cloud.sdk.cloudplatform.security.Credentials;
2119
import com.sap.cloud.sdk.cloudplatform.security.NoCredentials;
20+
import com.sap.cloud.sdk.cloudplatform.util.StringUtils;
2221

2322
import io.vavr.control.Option;
2423
import lombok.extern.slf4j.Slf4j;

cloudplatform/cloudplatform-connectivity/src/main/java/com/sap/cloud/sdk/cloudplatform/connectivity/DestinationUtility.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import javax.annotation.Nonnull;
66
import javax.annotation.Nullable;
77

8-
import org.apache.commons.lang3.StringUtils;
8+
import com.sap.cloud.sdk.cloudplatform.util.StringUtils;
99

1010
import io.vavr.control.Option;
1111
import lombok.extern.slf4j.Slf4j;
@@ -58,7 +58,7 @@ public static boolean requiresUserTokenExchange( @Nonnull final DestinationPrope
5858
requiresUserTokenExchange( @Nonnull final AuthenticationType authType, @Nullable final String systemUser )
5959
{
6060
// Handle special case for SAML Bearer Assertion and SAP Assertion SSO
61-
if( !StringUtils.isBlank(systemUser)
61+
if( !StringUtils.isBlankOrEmpty(systemUser)
6262
&& (authType == AuthenticationType.OAUTH2_SAML_BEARER_ASSERTION
6363
|| authType == AuthenticationType.SAP_ASSERTION_SSO) ) {
6464
final String msg =

cloudplatform/cloudplatform-connectivity/src/main/java/com/sap/cloud/sdk/cloudplatform/connectivity/UriPathMerger.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.sap.cloud.sdk.cloudplatform.connectivity;
22

3+
import static java.util.function.Predicate.not;
4+
35
import java.net.URI;
46
import java.net.URISyntaxException;
57
import java.util.stream.Collectors;
@@ -8,10 +10,9 @@
810
import javax.annotation.Nonnull;
911
import javax.annotation.Nullable;
1012

11-
import org.apache.commons.lang3.StringUtils;
12-
1313
import com.sap.cloud.sdk.cloudplatform.connectivity.exception.DestinationPathsNotMergeableException;
1414
import com.sap.cloud.sdk.cloudplatform.exception.ShouldNotHappenException;
15+
import com.sap.cloud.sdk.cloudplatform.util.StringUtils;
1516

1617
import io.vavr.control.Option;
1718
import lombok.extern.slf4j.Slf4j;
@@ -33,7 +34,7 @@ public class UriPathMerger
3334
* The secondary {@code URI}, usually identifying the request at runtime.
3435
*
3536
* @throws DestinationPathsNotMergeableException
36-
* If either of the request paths of the the given URIs are {@code null} or the URIs differ in the used
37+
* If either of the request paths of the given URIs are {@code null} or the URIs differ in the used
3738
* schema, host, or port.
3839
*
3940
* @return The merged {@code URI}, representing the given request executed on the given destination.
@@ -66,7 +67,7 @@ public URI merge( @Nonnull final URI primaryUri, @Nullable final URI secondaryUr
6667
final String mergeQuery =
6768
Stream
6869
.of(primaryUri.getRawQuery(), secondaryUri.getRawQuery())
69-
.filter(StringUtils::isNotEmpty)
70+
.filter(not(StringUtils::isBlankOrEmpty))
7071
.collect(Collectors.joining("&"));
7172

7273
try {
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
package com.sap.cloud.sdk.cloudplatform.util;
2+
3+
import java.util.Locale;
4+
5+
import javax.annotation.Nonnull;
6+
import javax.annotation.Nullable;
7+
8+
import com.google.common.annotations.Beta;
9+
10+
/**
11+
* Internal utility class for common String operations.
12+
*
13+
* @since 5.21.0
14+
*/
15+
@Beta
16+
public class StringUtils
17+
{
18+
/**
19+
* Checks if the given string starts with the specified prefix, ignoring case.
20+
*
21+
* @param str
22+
* the string to check
23+
* @param prefix
24+
* the prefix to look for
25+
* @return true if the string starts with the prefix, ignoring case; false otherwise
26+
*/
27+
public static boolean startsWithIgnoreCase( @Nullable final String str, @Nullable final String prefix )
28+
{
29+
if( str == null || prefix == null ) {
30+
return false;
31+
}
32+
if( str.length() < prefix.length() ) {
33+
return false;
34+
}
35+
return str.substring(0, prefix.length()).equalsIgnoreCase(prefix);
36+
}
37+
38+
/**
39+
* Checks if the given string ends with the specified suffix, ignoring case.
40+
*
41+
* @param str
42+
* the string to check
43+
* @param suffix
44+
* the suffix to look for
45+
* @return true if the string ends with the suffix, ignoring case; false otherwise
46+
*/
47+
public static boolean endsWithIgnoreCase( @Nullable final String str, @Nullable final String suffix )
48+
{
49+
if( str == null || suffix == null ) {
50+
return false;
51+
}
52+
if( str.length() < suffix.length() ) {
53+
return false;
54+
}
55+
return str.substring(str.length() - suffix.length()).equalsIgnoreCase(suffix);
56+
}
57+
58+
/**
59+
* Removes the specified prefix from the start of the string, ignoring case.
60+
*
61+
* @param s
62+
* the string to modify
63+
* @param prefix
64+
* the prefix to remove
65+
* @return the modified string with the prefix removed, or the original string if it did not start with the prefix;
66+
*/
67+
68+
@Nullable
69+
public static String removeStartIgnoreCase( @Nullable final String s, @Nullable final String prefix )
70+
{
71+
if( startsWithIgnoreCase(s, prefix) ) {
72+
return s.substring(prefix.length());
73+
}
74+
return s;
75+
}
76+
77+
/**
78+
* Removes the specified suffix from the end of the string, ignoring case.
79+
*
80+
* @param s
81+
* the string to modify
82+
* @param prefix
83+
* the suffix to remove
84+
* @return the modified string with the suffix removed, or the original string if it did not end with the suffix;
85+
*/
86+
@Nonnull
87+
public static String removeEndIgnoreCase( @Nonnull final String s, @Nonnull final String prefix )
88+
{
89+
if( endsWithIgnoreCase(s, prefix) ) {
90+
return s.substring(0, s.length() - prefix.length());
91+
}
92+
return s;
93+
}
94+
95+
/**
96+
* Checks if the given string is blank or empty.
97+
*
98+
* @param s
99+
* the string to check
100+
* @return true if the string is null, empty, or contains only whitespace characters; false otherwise
101+
*/
102+
public static boolean isBlankOrEmpty( @Nullable final String s )
103+
{
104+
return s == null || s.trim().isEmpty();
105+
}
106+
107+
/**
108+
* Checks if the given CharSequence is blank or empty.
109+
*
110+
* @param s
111+
* the CharSequence to check
112+
* @return true if the CharSequence is null, empty, or contains only whitespace characters; false otherwise
113+
*/
114+
public static boolean isBlankOrEmpty( @Nullable final CharSequence s )
115+
{
116+
return s != null && isBlankOrEmpty(s.toString());
117+
}
118+
119+
/**
120+
* Capitalizes the first character of the given string.
121+
*
122+
* @param s
123+
* the string to capitalize
124+
* @return the string with the first character capitalized, or null if the input is null or empty
125+
*/
126+
@Nullable
127+
public static String capitalize( @Nullable final String s )
128+
{
129+
if( s == null || s.isEmpty() ) {
130+
return s;
131+
}
132+
return s.substring(0, 1).toUpperCase(Locale.ROOT) + s.substring(1);
133+
}
134+
135+
/**
136+
* Uncapitalizes the first character of the given string.
137+
*
138+
* @param s
139+
* the string to uncapitalize
140+
* @return the string with the first character uncapitalized, or null if the input is null or empty
141+
*/
142+
@Nonnull
143+
public static String uncapitalize( @Nonnull final String s )
144+
{
145+
if( s.isEmpty() ) {
146+
return s;
147+
}
148+
return s.substring(0, 1).toLowerCase(Locale.ROOT) + s.substring(1);
149+
}
150+
151+
/**
152+
* Trims the given string and returns null if the result is empty.
153+
*
154+
* @param s
155+
* the string to trim
156+
* @return the trimmed string, or null if the input is null or empty after trimming
157+
*/
158+
@Nullable
159+
public static String trimToNull( @Nullable String s )
160+
{
161+
return s == null ? null : (s = s.trim()).isEmpty() ? null : s;
162+
}
163+
164+
/**
165+
* Prepends the specified prefix to the string if it does not already start with that prefix, ignoring case.
166+
*
167+
* @param s
168+
* the string to modify
169+
* @param prefix
170+
* the prefix to prepend
171+
* @return the modified string with the prefix prepended if it was not already present; otherwise, the original
172+
* string
173+
*/
174+
@Nonnull
175+
public static String prependIfMissing( @Nonnull final String s, @Nonnull final String prefix )
176+
{
177+
return startsWithIgnoreCase(s, prefix) ? s : prefix + s;
178+
}
179+
180+
/**
181+
* Returns the substring of the given string before the first occurrence of the specified suffix character.
182+
*
183+
* @param string
184+
* the string to search
185+
* @param suffix
186+
* the character to search for
187+
* @return the substring before the first occurrence of the suffix character, or the original string if the suffix
188+
* is not found;
189+
*/
190+
@Nullable
191+
public static String substringBefore( @Nullable final String string, final char suffix )
192+
{
193+
if( string == null ) {
194+
return string;
195+
}
196+
final int pos = string.indexOf(suffix);
197+
return pos >= 0 ? string.substring(0, pos) : string;
198+
}
199+
}

cloudplatform/connectivity-apache-httpclient4/pom.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,6 @@
9696
</exclusion>
9797
</exclusions>
9898
</dependency>
99-
<dependency>
100-
<groupId>org.apache.commons</groupId>
101-
<artifactId>commons-lang3</artifactId>
102-
</dependency>
10399
<!-- scope "provided" -->
104100
<dependency>
105101
<groupId>org.projectlombok</groupId>

cloudplatform/connectivity-apache-httpclient4/src/main/java/com/sap/cloud/sdk/cloudplatform/connectivity/QueryParamGetter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55

66
import javax.annotation.Nonnull;
77

8-
import org.apache.commons.lang3.StringUtils;
9-
108
import com.google.common.escape.Escaper;
119
import com.google.common.net.PercentEscaper;
10+
import com.sap.cloud.sdk.cloudplatform.util.StringUtils;
1211

1312
import io.vavr.control.Try;
1413
import lombok.extern.slf4j.Slf4j;

cloudplatform/connectivity-apache-httpclient4/src/main/java/com/sap/cloud/sdk/cloudplatform/connectivity/SSLSocketFactoryUtil.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import javax.net.ssl.HostnameVerifier;
99
import javax.net.ssl.SSLContext;
1010

11-
import org.apache.commons.lang3.StringUtils;
1211
import org.apache.http.config.Registry;
1312
import org.apache.http.config.RegistryBuilder;
1413
import org.apache.http.conn.socket.ConnectionSocketFactory;
@@ -18,6 +17,8 @@
1817
import org.apache.http.conn.ssl.NoopHostnameVerifier;
1918
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
2019

20+
import com.sap.cloud.sdk.cloudplatform.util.StringUtils;
21+
2122
import lombok.extern.slf4j.Slf4j;
2223

2324
@Slf4j
@@ -48,7 +49,7 @@ private static boolean supportsTls( @Nullable final HttpDestinationProperties de
4849
return false;
4950
}
5051
final String scheme = destination.getUri().getScheme();
51-
return "https".equalsIgnoreCase(scheme) || StringUtils.isEmpty(scheme);
52+
return "https".equalsIgnoreCase(scheme) || StringUtils.isBlankOrEmpty(scheme);
5253
}
5354

5455
@Nonnull

cloudplatform/connectivity-apache-httpclient5/pom.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@
8484
<groupId>org.apache.httpcomponents.core5</groupId>
8585
<artifactId>httpcore5</artifactId>
8686
</dependency>
87-
<dependency>
88-
<groupId>org.apache.commons</groupId>
89-
<artifactId>commons-lang3</artifactId>
90-
</dependency>
9187
<!-- scope "provided" -->
9288
<dependency>
9389
<groupId>org.projectlombok</groupId>

cloudplatform/connectivity-apache-httpclient5/src/main/java/com/sap/cloud/sdk/cloudplatform/connectivity/DefaultApacheHttpClient5Factory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import javax.net.ssl.HostnameVerifier;
1212
import javax.net.ssl.SSLContext;
1313

14-
import org.apache.commons.lang3.StringUtils;
1514
import org.apache.hc.client5.http.classic.HttpClient;
1615
import org.apache.hc.client5.http.config.ConnectionConfig;
1716
import org.apache.hc.client5.http.config.RequestConfig;
@@ -31,6 +30,7 @@
3130

3231
import com.sap.cloud.sdk.cloudplatform.connectivity.exception.DestinationAccessException;
3332
import com.sap.cloud.sdk.cloudplatform.connectivity.exception.HttpClientInstantiationException;
33+
import com.sap.cloud.sdk.cloudplatform.util.StringUtils;
3434

3535
import io.vavr.control.Option;
3636
import lombok.extern.slf4j.Slf4j;
@@ -149,7 +149,7 @@ private boolean supportsTls( @Nullable final HttpDestinationProperties destinati
149149
return false;
150150
}
151151
final String scheme = destination.getUri().getScheme();
152-
return "https".equalsIgnoreCase(scheme) || StringUtils.isEmpty(scheme);
152+
return "https".equalsIgnoreCase(scheme) || StringUtils.isBlankOrEmpty(scheme);
153153
}
154154

155155
private HostnameVerifier getHostnameVerifier( final HttpDestinationProperties destination )

cloudplatform/connectivity-apache-httpclient5/src/main/java/com/sap/cloud/sdk/cloudplatform/connectivity/QueryParamGetter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55

66
import javax.annotation.Nonnull;
77

8-
import org.apache.commons.lang3.StringUtils;
9-
108
import com.google.common.escape.Escaper;
119
import com.google.common.net.PercentEscaper;
10+
import com.sap.cloud.sdk.cloudplatform.util.StringUtils;
1211

1312
import io.vavr.control.Try;
1413
import lombok.extern.slf4j.Slf4j;

0 commit comments

Comments
 (0)