Skip to content

Commit 29aae07

Browse files
committed
Replace Strings.startsWithIgnoreCase()
`Strings.startsWithIgnoreCase()` has been removed in elasticsearch 1.4 ans master. See #7428 Closes #35.
1 parent f5d3500 commit 29aae07

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/test/java/org/elasticsearch/repositories/azure/AzureStorageServiceMock.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import org.elasticsearch.ElasticsearchException;
2323
import org.elasticsearch.cloud.azure.AzureStorageService;
24-
import org.elasticsearch.common.Strings;
2524
import org.elasticsearch.common.blobstore.BlobMetaData;
2625
import org.elasticsearch.common.blobstore.support.PlainBlobMetaData;
2726
import org.elasticsearch.common.collect.ImmutableMap;
@@ -33,6 +32,7 @@
3332
import java.io.ByteArrayOutputStream;
3433
import java.io.IOException;
3534
import java.io.InputStream;
35+
import java.util.Locale;
3636
import java.util.Map;
3737
import java.util.concurrent.ConcurrentHashMap;
3838

@@ -85,7 +85,7 @@ public InputStream getInputStream(String container, String blob) {
8585
public ImmutableMap<String, BlobMetaData> listBlobsByPrefix(String container, String keyPath, String prefix) {
8686
ImmutableMap.Builder<String, BlobMetaData> blobsBuilder = ImmutableMap.builder();
8787
for (String blobName : blobs.keySet()) {
88-
if (Strings.startsWithIgnoreCase(blobName, prefix)) {
88+
if (startsWithIgnoreCase(blobName, prefix)) {
8989
blobsBuilder.put(blobName, new PlainBlobMetaData(blobName, blobs.get(blobName).length));
9090
}
9191
}
@@ -123,4 +123,27 @@ protected void doStop() throws ElasticsearchException {
123123
@Override
124124
protected void doClose() throws ElasticsearchException {
125125
}
126+
127+
/**
128+
* Test if the given String starts with the specified prefix,
129+
* ignoring upper/lower case.
130+
*
131+
* @param str the String to check
132+
* @param prefix the prefix to look for
133+
* @see java.lang.String#startsWith
134+
*/
135+
public static boolean startsWithIgnoreCase(String str, String prefix) {
136+
if (str == null || prefix == null) {
137+
return false;
138+
}
139+
if (str.startsWith(prefix)) {
140+
return true;
141+
}
142+
if (str.length() < prefix.length()) {
143+
return false;
144+
}
145+
String lcStr = str.substring(0, prefix.length()).toLowerCase(Locale.ROOT);
146+
String lcPrefix = prefix.toLowerCase(Locale.ROOT);
147+
return lcStr.equals(lcPrefix);
148+
}
126149
}

0 commit comments

Comments
 (0)