本文整理了Java中org.apache.commons.lang3.Validate.notEmpty()
方法的一些代码示例,展示了Validate.notEmpty()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Validate.notEmpty()
方法的具体详情如下:
包路径:org.apache.commons.lang3.Validate
类名称:Validate
方法名:notEmpty
[英]Validate that the specified argument character sequence is neither null nor a length of zero (no characters); otherwise throwing an exception with the specified message.
Validate.notEmpty(myString);
The message in the exception is "The validated character sequence is empty".
[中]验证指定的参数字符序列既不是null,也不是长度为零(无字符);否则,将使用指定的消息引发异常。
Validate.notEmpty(myString);
异常中的消息是“已验证的字符序列为空”。
代码示例来源:origin: rest-assured/rest-assured
/**
* Specify the mime-type for this multi-part.
*
* @param mimeType The mime-type
* @return An instance of MultiPartSpecBuilder
*/
public MultiPartSpecBuilder mimeType(String mimeType) {
Validate.notEmpty(mimeType, "Mime-type cannot be empty");
this.mimeType = mimeType;
return this;
}
代码示例来源:origin: rest-assured/rest-assured
private SessionConfig(String sessionIdName, String sessionIdValue, boolean isUserDefined) {
Validate.notEmpty(sessionIdName, "Session id name cannot be empty.");
this.sessionIdName = sessionIdName;
this.sessionIdValue = sessionIdValue;
this.isUserDefined = isUserDefined;
}
代码示例来源:origin: rest-assured/rest-assured
/**
* Specify the control name of this multi-part.
*
* @param controlName The control name to use. Default is <code>file</code>.
* @return An instance of MultiPartSpecBuilder
*/
public MultiPartSpecBuilder controlName(String controlName) {
Validate.notEmpty(controlName, "Control name cannot be empty");
this.controlName = controlName;
this.isControlNameExplicit = true;
return this;
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* <p>Validate that the specified argument map is neither {@code null}
* nor a size of zero (no elements); otherwise throwing an exception.
*
* <pre>Validate.notEmpty(myMap);</pre>
*
* <p>The message in the exception is "The validated map is
* empty".</p>
*
* @param <T> the map type
* @param map the map to check, validated not null by this method
* @return the validated map (never {@code null} method for chaining)
* @throws NullPointerException if the map is {@code null}
* @throws IllegalArgumentException if the map is empty
* @see #notEmpty(Map, String, Object...)
*/
public static <T extends Map<?, ?>> T notEmpty(final T map) {
return notEmpty(map, DEFAULT_NOT_EMPTY_MAP_EX_MESSAGE);
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* <p>Validate that the specified argument character sequence is
* neither {@code null} nor a length of zero (no characters);
* otherwise throwing an exception with the specified message.
*
* <pre>Validate.notEmpty(myString);</pre>
*
* <p>The message in the exception is "The validated
* character sequence is empty".</p>
*
* @param <T> the character sequence type
* @param chars the character sequence to check, validated not null by this method
* @return the validated character sequence (never {@code null} method for chaining)
* @throws NullPointerException if the character sequence is {@code null}
* @throws IllegalArgumentException if the character sequence is empty
* @see #notEmpty(CharSequence, String, Object...)
*/
public static <T extends CharSequence> T notEmpty(final T chars) {
return notEmpty(chars, DEFAULT_NOT_EMPTY_CHAR_SEQUENCE_EX_MESSAGE);
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* <p>Validate that the specified argument array is neither {@code null}
* nor a length of zero (no elements); otherwise throwing an exception.
*
* <pre>Validate.notEmpty(myArray);</pre>
*
* <p>The message in the exception is "The validated array is
* empty".
*
* @param <T> the array type
* @param array the array to check, validated not null by this method
* @return the validated array (never {@code null} method for chaining)
* @throws NullPointerException if the array is {@code null}
* @throws IllegalArgumentException if the array is empty
* @see #notEmpty(Object[], String, Object...)
*/
public static <T> T[] notEmpty(final T[] array) {
return notEmpty(array, DEFAULT_NOT_EMPTY_ARRAY_EX_MESSAGE);
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* <p>Validate that the specified argument collection is neither {@code null}
* nor a size of zero (no elements); otherwise throwing an exception.
*
* <pre>Validate.notEmpty(myCollection);</pre>
*
* <p>The message in the exception is "The validated collection is
* empty".</p>
*
* @param <T> the collection type
* @param collection the collection to check, validated not null by this method
* @return the validated collection (never {@code null} method for chaining)
* @throws NullPointerException if the collection is {@code null}
* @throws IllegalArgumentException if the collection is empty
* @see #notEmpty(Collection, String, Object...)
*/
public static <T extends Collection<?>> T notEmpty(final T collection) {
return notEmpty(collection, DEFAULT_NOT_EMPTY_COLLECTION_EX_MESSAGE);
}
代码示例来源:origin: springside/springside4
/**
* 获取文件名(不包含路径)
*/
public static String getFileName(@NotNull String fullName) {
Validate.notEmpty(fullName);
int last = fullName.lastIndexOf(Platforms.FILE_PATH_SEPARATOR_CHAR);
return fullName.substring(last + 1);
}
代码示例来源:origin: rest-assured/rest-assured
/**
* @param pathToTrustStore The path to the trust store. REST Assured will first look in the classpath and if not found it will look for the JKS in the local file-system
* @param password The store pass
* @return A new SSLConfig instance
*/
public SSLConfig trustStore(String pathToTrustStore, String password) {
Validate.notNull(pathToTrustStore, "Path to trust store on the file system cannot be null");
Validate.notEmpty(password, "Password cannot be empty");
return new SSLConfig(pathToKeyStore, pathToTrustStore, keyStorePassword, password, keyStoreType, trustStoreType, port, keyStore, trustStore, x509HostnameVerifier, sslSocketFactory, true);
}
代码示例来源:origin: rest-assured/rest-assured
/**
* @param pathToJks The path to the JKS. REST Assured will first look in the classpath and if not found it will look for the JKS in the local file-system
* @param password The store pass
* @return A new SSLConfig instance
*/
public SSLConfig keyStore(String pathToJks, String password) {
Validate.notNull(pathToJks, "Path to JKS on the file system cannot be null");
Validate.notEmpty(password, "Password cannot be empty");
return new SSLConfig(pathToJks, pathToTrustStore, password, trustStorePassword, keyStoreType, trustStoreType, port, keyStore, trustStore, x509HostnameVerifier, sslSocketFactory, true);
}
代码示例来源:origin: rest-assured/rest-assured
/**
* Uses the user default keystore stored in <user.home>/.keystore
*
* @param password - Use null for no password
* @return The keystore specification
*/
public SSLConfig keyStore(String password) {
Validate.notEmpty(password, "Password cannot be empty");
return keyStore(System.getProperty("user.home") + File.separatorChar + ".keystore", password);
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* Find the "best guess" middle value among comparables. If there is an even
* number of total values, the lower of the two middle values will be returned.
* @param <T> type of values processed by this method
* @param items to compare
* @return T at middle position
* @throws NullPointerException if items is {@code null}
* @throws IllegalArgumentException if items is empty or contains {@code null} values
* @since 3.0.1
*/
@SafeVarargs
public static <T extends Comparable<? super T>> T median(final T... items) {
Validate.notEmpty(items);
Validate.noNullElements(items);
final TreeSet<T> sort = new TreeSet<>();
Collections.addAll(sort, items);
@SuppressWarnings("unchecked") //we know all items added were T instances
final T result = (T) sort.toArray()[(sort.size() - 1) / 2];
return result;
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* Append {@code types} to {@code buf} with separator {@code sep}.
* @param buf destination
* @param sep separator
* @param types to append
* @return {@code buf}
* @since 3.2
*/
private static <T> StringBuilder appendAllTo(final StringBuilder buf, final String sep, final T... types) {
Validate.notEmpty(Validate.noNullElements(types));
if (types.length > 0) {
buf.append(toString(types[0]));
for (int i = 1; i < types.length; i++) {
buf.append(sep).append(toString(types[i]));
}
}
return buf;
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testNotEmptyCollection1() {
final Collection<Integer> coll = new ArrayList<>();
try {
Validate.notEmpty((Collection<?>) null);
fail("Expecting NullPointerException");
} catch (final NullPointerException ex) {
assertEquals("The validated collection is empty", ex.getMessage());
}
try {
Validate.notEmpty(coll);
fail("Expecting IllegalArgumentException");
} catch (final IllegalArgumentException ex) {
assertEquals("The validated collection is empty", ex.getMessage());
}
coll.add(Integer.valueOf(8));
Validate.notEmpty(coll);
final Collection<Integer> test = Validate.notEmpty(coll);
assertSame(coll, test);
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testNotEmptyMap2() {
final Map<String, Integer> map = new HashMap<>();
try {
Validate.notEmpty((Map<?, ?>) null, "MSG");
fail("Expecting NullPointerException");
} catch (final NullPointerException ex) {
assertEquals("MSG", ex.getMessage());
}
try {
Validate.notEmpty(map, "MSG");
fail("Expecting IllegalArgumentException");
} catch (final IllegalArgumentException ex) {
assertEquals("MSG", ex.getMessage());
}
map.put("ll", Integer.valueOf(8));
Validate.notEmpty(map, "MSG");
final Map<String, Integer> test = Validate.notEmpty(map, "Message");
assertSame(map, test);
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testNotEmptyCollection2() {
final Collection<Integer> coll = new ArrayList<>();
try {
Validate.notEmpty((Collection<?>) null, "MSG");
fail("Expecting NullPointerException");
} catch (final NullPointerException ex) {
assertEquals("MSG", ex.getMessage());
}
try {
Validate.notEmpty(coll, "MSG");
fail("Expecting IllegalArgumentException");
} catch (final IllegalArgumentException ex) {
assertEquals("MSG", ex.getMessage());
}
coll.add(Integer.valueOf(8));
Validate.notEmpty(coll, "MSG");
final Collection<Integer> test = Validate.notEmpty(coll, "Message");
assertSame(coll, test);
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testNotEmptyArray1() {
Validate.notEmpty(new Object[]{null});
try {
Validate.notEmpty((Object[]) null);
fail("Expecting NullPointerException");
} catch (final NullPointerException ex) {
assertEquals("The validated array is empty", ex.getMessage());
}
try {
Validate.notEmpty(new Object[0]);
fail("Expecting IllegalArgumentException");
} catch (final IllegalArgumentException ex) {
assertEquals("The validated array is empty", ex.getMessage());
}
final String[] array = new String[]{"hi"};
final String[] test = Validate.notEmpty(array);
assertSame(array, test);
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testNotEmptyString1() {
Validate.notEmpty("hjl");
try {
Validate.notEmpty((String) null);
fail("Expecting NullPointerException");
} catch (final NullPointerException ex) {
assertEquals("The validated character sequence is empty", ex.getMessage());
}
try {
Validate.notEmpty("");
fail("Expecting IllegalArgumentException");
} catch (final IllegalArgumentException ex) {
assertEquals("The validated character sequence is empty", ex.getMessage());
}
final String str = "Hi";
final String testStr = Validate.notEmpty(str);
assertSame(str, testStr);
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testNotEmptyString2() {
Validate.notEmpty("a", "MSG");
try {
Validate.notEmpty((String) null, "MSG");
fail("Expecting NullPointerException");
} catch (final NullPointerException ex) {
assertEquals("MSG", ex.getMessage());
}
try {
Validate.notEmpty("", "MSG");
fail("Expecting IllegalArgumentException");
} catch (final IllegalArgumentException ex) {
assertEquals("MSG", ex.getMessage());
}
final String str = "Hi";
final String testStr = Validate.notEmpty(str, "Message");
assertSame(str, testStr);
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testNotEmptyArray2() {
Validate.notEmpty(new Object[]{null}, "MSG");
try {
Validate.notEmpty((Object[]) null, "MSG");
fail("Expecting NullPointerException");
} catch (final NullPointerException ex) {
assertEquals("MSG", ex.getMessage());
}
try {
Validate.notEmpty(new Object[0], "MSG");
fail("Expecting IllegalArgumentException");
} catch (final IllegalArgumentException ex) {
assertEquals("MSG", ex.getMessage());
}
final String[] array = new String[]{"hi"};
final String[] test = Validate.notEmpty(array, "Message");
assertSame(array, test);
}
内容来源于网络,如有侵权,请联系作者删除!