本文整理了Java中org.springframework.util.Assert.hasLength()
方法的一些代码示例,展示了Assert.hasLength()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Assert.hasLength()
方法的具体详情如下:
包路径:org.springframework.util.Assert
类名称:Assert
方法名:hasLength
[英]Assert that the given String is not empty; that is, it must not be null
and not the empty String.
Assert.hasLength(name);
[中]断言给定的字符串不是空的;也就是说,它不能是null
,也不能是空字符串
Assert.hasLength(name);
代码示例来源:origin: spring-projects/spring-framework
/**
* Set a friendly name for this context.
* Typically done during initialization of concrete context implementations.
* <p>Default is the object id of the context instance.
*/
public void setDisplayName(String displayName) {
Assert.hasLength(displayName, "Display name must not be empty");
this.displayName = displayName;
}
代码示例来源:origin: spring-projects/spring-framework
public HttpCookie(String name, @Nullable String value) {
Assert.hasLength(name, "'name' is required and must not be empty.");
this.name = name;
this.value = (value != null ? value : "");
}
代码示例来源:origin: spring-projects/spring-framework
private static void addToMap(Map<String, Object> map, String name, Object value) {
Assert.hasLength(name, "'name' must not be empty");
Assert.notNull(value, "'value' must not be null");
map.put(name, value);
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public void declareRoles(String... roleNames) {
Assert.notNull(roleNames, "Role names array must not be null");
for (String roleName : roleNames) {
Assert.hasLength(roleName, "Role name must not be empty");
this.declaredRoles.add(roleName);
}
}
代码示例来源:origin: spring-projects/spring-framework
private static <T> void addToMultiValueMap(MultiValueMap<String, T> map, String name, T[] values) {
Assert.hasLength(name, "'name' must not be empty");
Assert.notEmpty(values, "'values' must not be empty");
for (T value : values) {
map.add(name, value);
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Assert that the given String is not empty; that is,
* it must not be {@code null} and not the empty String.
* @deprecated as of 4.3.7, in favor of {@link #hasLength(String, String)}
*/
@Deprecated
public static void hasLength(@Nullable String text) {
hasLength(text,
"[Assertion failed] - this String argument must have length; it must not be null or empty");
}
代码示例来源:origin: spring-projects/spring-framework
public PathResourceLookupFunction(String pattern, Resource location) {
Assert.hasLength(pattern, "'pattern' must not be empty");
Assert.notNull(location, "'location' must not be null");
this.pattern = PATTERN_PARSER.parse(pattern);
this.location = location;
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Constructor for a part with a filename and byte[] content.
* @see #getHeaders()
*/
public MockPart(String name, @Nullable String filename, @Nullable byte[] content) {
Assert.hasLength(name, "'name' must not be empty");
this.name = name;
this.filename = filename;
this.content = (content != null ? content : new byte[0]);
this.headers.setContentDispositionFormData(name, filename);
}
代码示例来源:origin: spring-projects/spring-framework
protected void checkParameters(String attribute, String value) {
Assert.hasLength(attribute, "'attribute' must not be empty");
Assert.hasLength(value, "'value' must not be empty");
checkToken(attribute);
if (PARAM_CHARSET.equals(attribute)) {
value = unquote(value);
Charset.forName(value);
}
else if (!isQuotedString(value)) {
checkToken(value);
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public void declareRoles(String... roleNames) {
Assert.notNull(roleNames, "Role names array must not be null");
for (String roleName : roleNames) {
Assert.hasLength(roleName, "Role name must not be empty");
this.declaredRoles.add(roleName);
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Constructor for a part with a filename and byte[] content.
* @see #getHeaders()
*/
public MockPart(String name, @Nullable String filename, @Nullable byte[] content) {
Assert.hasLength(name, "'name' must not be empty");
this.name = name;
this.filename = filename;
this.content = (content != null ? content : new byte[0]);
this.headers.setContentDispositionFormData(name, filename);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void hasLengthWithMessageSupplier() {
Assert.hasLength("foo", () -> "enigma");
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void hasLength() {
Assert.hasLength("I Heart ...", "enigma");
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void hasLengthWithWhitespaceOnly() {
Assert.hasLength("\t ", "enigma");
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void hasLengthWithWhitespaceOnlyAndMessageSupplier() {
Assert.hasLength("\t", () -> "enigma");
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void hasLengthWithNullAndNullMessageSupplier() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage(equalTo(null));
Assert.hasLength(null, (Supplier<String>) null);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void hasLengthWithNull() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("enigma");
Assert.hasLength(null, "enigma");
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void hasLengthWithNullAndMessageSupplier() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("enigma");
Assert.hasLength(null, () -> "enigma");
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void hasLengthWithEmptyStringAndMessageSupplier() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("enigma");
Assert.hasLength("", () -> "enigma");
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void hasLengthWithEmptyString() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("enigma");
Assert.hasLength("", "enigma");
}
内容来源于网络,如有侵权,请联系作者删除!