public static boolean isNumeric(String str) { return str.matches("-?\\d+(\\.\\d+)?"); //match a number with optional '-' and decimal. }
public ServerInfo(String response, long responseTime) { this.responseTime = responseTime; this.webSocketEnabled = !response.matches(".*[\"']websocket[\"']\\s*:\\s*false.*"); }
private int retryAfter(Response userResponse, int defaultDelay) { String header = userResponse.header("Retry-After"); if (header == null) { return defaultDelay; } // https://tools.ietf.org/html/rfc7231#section-7.1.3 // currently ignores a HTTP-date, and assumes any non int 0 is a delay if (header.matches("\\d+")) { return Integer.valueOf(header); } return Integer.MAX_VALUE; }
@Override public boolean match(String pattern, String path) { return path.matches(pattern); }
@Override public boolean match(String pattern, String path) { return path.matches(pattern); }
public void testToStringHelperLenient_localInnerClass() { class LocalInnerClass {} String toTest = MoreObjects.toStringHelper(new LocalInnerClass()).toString(); assertTrue(toTest, toTest.matches(".*\\{\\}")); }
public void testConstructorLenient_classObject() { String toTest = MoreObjects.toStringHelper(TestClass.class).toString(); assertTrue(toTest, toTest.matches(".*\\{\\}")); }
public void testConstructorLenient_instance() { String toTest = MoreObjects.toStringHelper(this).toString(); assertTrue(toTest, toTest.matches(".*\\{\\}")); }
public void testConstructorLenient_anonymousClass() { String toTest = MoreObjects.toStringHelper(new Object() {}).toString(); assertTrue(toTest, toTest.matches(".*\\{\\}")); }
public void testToStringHelperLenient_moreThanNineAnonymousClasses() { // The nth anonymous class has a name ending like "Outer.$n" Object o1 = new Object() {}; Object o2 = new Object() {}; Object o3 = new Object() {}; Object o4 = new Object() {}; Object o5 = new Object() {}; Object o6 = new Object() {}; Object o7 = new Object() {}; Object o8 = new Object() {}; Object o9 = new Object() {}; Object o10 = new Object() {}; String toTest = MoreObjects.toStringHelper(o10).toString(); assertTrue(toTest, toTest.matches(".*\\{\\}")); }
public void testToStringLenient_oneIntegerField() { String toTest = MoreObjects.toStringHelper(new TestClass()).add("field1", new Integer(42)).toString(); assertTrue(toTest, toTest.matches(".*\\{field1\\=42\\}")); }
public void testToStringLenient_nullInteger() { String toTest = MoreObjects.toStringHelper(new TestClass()).add("field1", (Integer) null).toString(); assertTrue(toTest, toTest.matches(".*\\{field1\\=null\\}")); }
public void testToStringLenient_oneField() { String toTest = MoreObjects.toStringHelper(new TestClass()).add("field1", "Hello").toString(); assertTrue(toTest, toTest.matches(".*\\{field1\\=Hello\\}")); }
public void testToStringLenient_addWithNullValue() { final String result = MoreObjects.toStringHelper(new TestClass()).add("Hello", null).toString(); assertTrue(result, result.matches(".*\\{Hello\\=null\\}")); }
public void testToStringHelperLenient_localInnerNestedClass() { class LocalInnerClass { class LocalInnerNestedClass {} } String toTest = MoreObjects.toStringHelper(new LocalInnerClass().new LocalInnerNestedClass()).toString(); assertTrue(toTest, toTest.matches(".*\\{\\}")); }
/** * Match the primary value of the response header with a regex. * @param name the header name * @param pattern the regex pattern */ public WebTestClient.ResponseSpec valueMatches(String name, String pattern) { String value = getRequiredValue(name); String message = getMessage(name) + "=[" + value + "] does not match [" + pattern + "]"; this.exchangeResult.assertWithDiagnostics(() -> AssertionErrors.assertTrue(message, value.matches(pattern))); return this.responseSpec; }
public void testConstructorLenient_innerClass() { String toTest = MoreObjects.toStringHelper(new TestClass()).toString(); assertTrue(toTest, toTest.matches(".*\\{\\}")); }
public void testToStringLenient_addValue() { String toTest = MoreObjects.toStringHelper(new TestClass()) .add("field1", 1) .addValue("value1") .add("field2", "value2") .addValue(2) .toString(); final String expected = ".*\\{field1\\=1, value1, field2\\=value2, 2\\}"; assertTrue(toTest, toTest.matches(expected)); }
public void testToStringLenient_addValueWithNullValue() { final String result = MoreObjects.toStringHelper(new TestClass()) .addValue(null) .addValue("Hello") .addValue(null) .toString(); final String expected = ".*\\{null, Hello, null\\}"; assertTrue(result, result.matches(expected)); }
@Override public boolean isAutowireCandidate(BeanDefinitionHolder bdHolder, DependencyDescriptor descriptor) { if (!bdHolder.getBeanDefinition().isAutowireCandidate()) { return false; } if (!bdHolder.getBeanName().matches("[a-z-]+")) { return false; } if (bdHolder.getBeanDefinition().getAttribute("priority").equals("1")) { return true; } return false; }