Skip to content

Commit 6c12753

Browse files
committed
Javadoc
1 parent 345d7df commit 6c12753

File tree

2 files changed

+72
-5
lines changed

2 files changed

+72
-5
lines changed

commons-email2-core/src/main/java/org/apache/commons/mail2/core/EmailException.java

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
1817
package org.apache.commons.mail2.core;
1918

2019
import java.io.OutputStreamWriter;
@@ -36,34 +35,78 @@
3635
* @since 1.0
3736
*/
3837
public class EmailException extends Exception {
39-
4038
/** Serializable version identifier. */
4139
private static final long serialVersionUID = 5550674499282474616L;
4240

41+
/**
42+
* Throws an EmailException if the supplier evaluates to true.
43+
*
44+
* @param <T> the subject type to return if we don't throw.
45+
* @param test test condition.
46+
* @param subject the subject to return if we don't throw.
47+
* @param message the exception message.
48+
* @return the given subject.
49+
* @throws EmailException if the supplier evaluates to true.
50+
*/
4351
public static <T> T check(final Supplier<Boolean> test, final T subject, final Supplier<String> message) throws EmailException {
4452
if (test.get()) {
4553
throw new EmailException(message.get());
4654
}
4755
return subject;
4856
}
4957

58+
/**
59+
* Throws an EmailException if the collection is empty.
60+
*
61+
* @param <T> the type of elements in the collection.
62+
* @param value the value to test.
63+
* @param message the exception message.
64+
* @return the given subject.
65+
* @throws EmailException if the collection is empty.
66+
*/
5067
public static <T> Collection<T> checkNonEmpty(final Collection<T> value, final Supplier<String> message) throws EmailException {
5168
return check(() -> EmailUtils.isEmpty(value), value, message);
5269
}
5370

71+
/**
72+
* Throws an EmailException if the string is empty.
73+
*
74+
* @param message the exception message.
75+
* @param value the value to test.
76+
* @return the given subject.
77+
* @throws EmailException if the string is empty.
78+
*/
5479
public static String checkNonEmpty(final String value, final Supplier<String> message) throws EmailException {
5580
return check(() -> EmailUtils.isEmpty(value), value, message);
5681
}
5782

83+
/**
84+
* Throws an EmailException if the array is empty.
85+
*
86+
* @param <T> the array type.
87+
* @param message the exception message.
88+
* @param value the value to test.
89+
* @return the given subject.
90+
* @throws EmailException if the array is empty.
91+
*/
5892
public static <T> T[] checkNonEmpty(final T[] value, final Supplier<String> message) throws EmailException {
5993
return check(() -> EmailUtils.isEmpty(value), value, message);
6094
}
6195

62-
public static <T> T checkNonNull(final T test, final Supplier<String> message) throws EmailException {
63-
if (test == null) {
96+
/**
97+
* Throws an EmailException if the value is null.
98+
*
99+
* @param <T> the value type.
100+
* @param message the exception message.
101+
* @param value the value to test.
102+
* @return the given subject.
103+
* @throws EmailException if the value is null.
104+
*/
105+
public static <T> T checkNonNull(final T value, final Supplier<String> message) throws EmailException {
106+
if (value == null) {
64107
throw new EmailException(message.get());
65108
}
66-
return test;
109+
return value;
67110
}
68111

69112
/**

commons-email2-core/src/main/java/org/apache/commons/mail2/core/EmailUtils.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,32 @@ public static String encodeUrl(final String input) {
113113
return builder.toString();
114114
}
115115

116+
/**
117+
* Tests whether the given collection is null or empty.
118+
*
119+
* @param collection the collection to test.
120+
* @return whether the given collection is null or empty.
121+
*/
116122
public static boolean isEmpty(final Collection<?> collection) {
117123
return collection == null || collection.isEmpty();
118124
}
119125

126+
/**
127+
* Tests whether the given map is null or empty.
128+
*
129+
* @param map the map to test.
130+
* @return whether the given map is null or empty.
131+
*/
120132
public static boolean isEmpty(final Map<?, ?> map) {
121133
return map == null || map.isEmpty();
122134
}
123135

136+
/**
137+
* Tests whether the given array is null or empty.
138+
*
139+
* @param array the collection to test.
140+
* @return whether the given array is null or empty.
141+
*/
124142
public static boolean isEmpty(final Object[] array) {
125143
return array == null || array.length == 0;
126144
}
@@ -245,6 +263,12 @@ public static String replaceEndOfLineCharactersWithSpaces(final String input) {
245263
return input == null ? null : input.replace('\n', ' ').replace('\r', ' ');
246264
}
247265

266+
/**
267+
* Converts the given string to lower case.
268+
*
269+
* @param value the input string.
270+
* @return a lower case string.
271+
*/
248272
public static String toLower(final String value) {
249273
return value.toLowerCase(Locale.ROOT);
250274
}

0 commit comments

Comments
 (0)