Make all tags comparisons case-insensitive in Cloud Foundry connector.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package org.springframework.cloud.cloudfoundry;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Tags {
|
||||
@@ -17,8 +16,10 @@ public class Tags {
|
||||
public boolean containsOne(List<String> tags) {
|
||||
if (tags != null) {
|
||||
for (String value : values) {
|
||||
if (tags.contains(value)) {
|
||||
return true;
|
||||
for (String tag : tags) {
|
||||
if (tag.equalsIgnoreCase(value)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,17 +27,28 @@ public class Tags {
|
||||
}
|
||||
|
||||
public boolean contains(String tag) {
|
||||
return tag != null && Arrays.asList(values).contains(tag);
|
||||
}
|
||||
|
||||
public boolean startsWith(String tag) {
|
||||
if (tag != null) {
|
||||
for (String value : values) {
|
||||
if (tag.startsWith(value)) {
|
||||
if (tag.equalsIgnoreCase(value)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean startsWith(String tag) {
|
||||
if (tag != null) {
|
||||
for (String value : values) {
|
||||
if (startsWithIgnoreCase(tag, value)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean startsWithIgnoreCase(String string, String prefix) {
|
||||
return string.regionMatches(true, 0, prefix, 0, prefix.length());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ public class TagsTest {
|
||||
Tags tags = new Tags("test1", "test2");
|
||||
assertTrue(tags.containsOne(Arrays.asList("test1", "testx")));
|
||||
assertTrue(tags.containsOne(Arrays.asList("testx", "test2")));
|
||||
assertTrue(tags.containsOne(Arrays.asList("TESTX", "TEST2")));
|
||||
assertFalse(tags.containsOne(Arrays.asList("testx", "testy")));
|
||||
}
|
||||
|
||||
@@ -29,6 +30,7 @@ public class TagsTest {
|
||||
Tags tags = new Tags("test1", "test2");
|
||||
assertTrue(tags.contains("test1"));
|
||||
assertTrue(tags.contains("test2"));
|
||||
assertTrue(tags.contains("TEST2"));
|
||||
assertFalse(tags.contains("testx"));
|
||||
}
|
||||
|
||||
@@ -41,6 +43,7 @@ public class TagsTest {
|
||||
public void startsWith() {
|
||||
Tags tags = new Tags("test");
|
||||
assertTrue(tags.startsWith("test-123"));
|
||||
assertTrue(tags.startsWith("TEST-123"));
|
||||
assertFalse(tags.startsWith("abcd"));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user