Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.63 KB | None | 0 0
  1. // Empty checks
  2. //-----------------------------------------------------------------------
  3. /**
  4. * <p>Checks if a CharSequence is empty ("") or null.</p>
  5. *
  6. * <pre>
  7. * StringUtils.isEmpty(null) = true
  8. * StringUtils.isEmpty("") = true
  9. * StringUtils.isEmpty(" ") = false
  10. * StringUtils.isEmpty("bob") = false
  11. * StringUtils.isEmpty(" bob ") = false
  12. * </pre>
  13. *
  14. * <p>NOTE: This method changed in Lang version 2.0.
  15. * It no longer trims the CharSequence.
  16. * That functionality is available in isBlank().</p>
  17. *
  18. * @param cs the CharSequence to check, may be null
  19. * @return {@code true} if the CharSequence is empty or null
  20. * @since 3.0 Changed signature from isEmpty(String) to isEmpty(CharSequence)
  21. */
  22. public static boolean isEmpty(final CharSequence cs) {
  23. return cs == null || cs.length() == 0;
  24. }
  25.  
  26. /**
  27. * <p>Checks if a CharSequence is not empty ("") and not null.</p>
  28. *
  29. * <pre>
  30. * StringUtils.isNotEmpty(null) = false
  31. * StringUtils.isNotEmpty("") = false
  32. * StringUtils.isNotEmpty(" ") = true
  33. * StringUtils.isNotEmpty("bob") = true
  34. * StringUtils.isNotEmpty(" bob ") = true
  35. * </pre>
  36. *
  37. * @param cs the CharSequence to check, may be null
  38. * @return {@code true} if the CharSequence is not empty and not null
  39. * @since 3.0 Changed signature from isNotEmpty(String) to isNotEmpty(CharSequence)
  40. */
  41. public static boolean isNotEmpty(final CharSequence cs) {
  42. return !isEmpty(cs);
  43. }
  44.  
  45. /**
  46. * <p>Checks if any one of the CharSequences are empty ("") or null.</p>
  47. *
  48. * <pre>
  49. * StringUtils.isAnyEmpty(null) = true
  50. * StringUtils.isAnyEmpty(null, "foo") = true
  51. * StringUtils.isAnyEmpty("", "bar") = true
  52. * StringUtils.isAnyEmpty("bob", "") = true
  53. * StringUtils.isAnyEmpty(" bob ", null) = true
  54. * StringUtils.isAnyEmpty(" ", "bar") = false
  55. * StringUtils.isAnyEmpty("foo", "bar") = false
  56. * </pre>
  57. *
  58. * @param css the CharSequences to check, may be null or empty
  59. * @return {@code true} if any of the CharSequences are empty or null
  60. * @since 3.2
  61. */
  62. public static boolean isAnyEmpty(final CharSequence... css) {
  63. if (ArrayUtils.isEmpty(css)) {
  64. return true;
  65. }
  66. for (final CharSequence cs : css){
  67. if (isEmpty(cs)) {
  68. return true;
  69. }
  70. }
  71. return false;
  72. }
  73.  
  74. /**
  75. * <p>Checks if none of the CharSequences are empty ("") or null.</p>
  76. *
  77. * <pre>
  78. * StringUtils.isNoneEmpty(null) = false
  79. * StringUtils.isNoneEmpty(null, "foo") = false
  80. * StringUtils.isNoneEmpty("", "bar") = false
  81. * StringUtils.isNoneEmpty("bob", "") = false
  82. * StringUtils.isNoneEmpty(" bob ", null) = false
  83. * StringUtils.isNoneEmpty(" ", "bar") = true
  84. * StringUtils.isNoneEmpty("foo", "bar") = true
  85. * </pre>
  86. *
  87. * @param css the CharSequences to check, may be null or empty
  88. * @return {@code true} if none of the CharSequences are empty or null
  89. * @since 3.2
  90. */
  91. public static boolean isNoneEmpty(final CharSequence... css) {
  92. return !isAnyEmpty(css);
  93. }
  94.  
  95.  
  96. // Joining
  97. //-----------------------------------------------------------------------
  98. /**
  99. * <p>Joins the elements of the provided array into a single String
  100. * containing the provided list of elements.</p>
  101. *
  102. * <p>No separator is added to the joined String.
  103. * Null objects or empty strings within the array are represented by
  104. * empty strings.</p>
  105. *
  106. * <pre>
  107. * StringUtils.join(null) = null
  108. * StringUtils.join([]) = ""
  109. * StringUtils.join([null]) = ""
  110. * StringUtils.join(["a", "b", "c"]) = "abc"
  111. * StringUtils.join([null, "", "a"]) = "a"
  112. * </pre>
  113. *
  114. * @param <T> the specific type of values to join together
  115. * @param elements the values to join together, may be null
  116. * @return the joined String, {@code null} if null array input
  117. * @since 2.0
  118. * @since 3.0 Changed signature to use varargs
  119. */
  120. public static <T> String join(final T... elements) {
  121. return join(elements, null);
  122. }
  123.  
  124. /**
  125. * <p>Joins the elements of the provided array into a single String
  126. * containing the provided list of elements.</p>
  127. *
  128. * <p>No delimiter is added before or after the list.
  129. * Null objects or empty strings within the array are represented by
  130. * empty strings.</p>
  131. *
  132. * <pre>
  133. * StringUtils.join(null, *) = null
  134. * StringUtils.join([], *) = ""
  135. * StringUtils.join([null], *) = ""
  136. * StringUtils.join(["a", "b", "c"], ';') = "a;b;c"
  137. * StringUtils.join(["a", "b", "c"], null) = "abc"
  138. * StringUtils.join([null, "", "a"], ';') = ";;a"
  139. * </pre>
  140. *
  141. * @param array the array of values to join together, may be null
  142. * @param separator the separator character to use
  143. * @return the joined String, {@code null} if null array input
  144. * @since 2.0
  145. */
  146. public static String join(final Object[] array, final char separator) {
  147. if (array == null) {
  148. return null;
  149. }
  150. return join(array, separator, 0, array.length);
  151. }
  152.  
  153. /**
  154. * <p>
  155. * Joins the elements of the provided array into a single String containing the provided list of elements.
  156. * </p>
  157. *
  158. * <p>
  159. * No delimiter is added before or after the list. Null objects or empty strings within the array are represented
  160. * by empty strings.
  161. * </p>
  162. *
  163. * <pre>
  164. * StringUtils.join(null, *) = null
  165. * StringUtils.join([], *) = ""
  166. * StringUtils.join([null], *) = ""
  167. * StringUtils.join([1, 2, 3], ';') = "1;2;3"
  168. * StringUtils.join([1, 2, 3], null) = "123"
  169. * </pre>
  170. *
  171. * @param array
  172. * the array of values to join together, may be null
  173. * @param separator
  174. * the separator character to use
  175. * @return the joined String, {@code null} if null array input
  176. * @since 3.2
  177. */
  178. public static String join(final long[] array, final char separator) {
  179. if (array == null) {
  180. return null;
  181. }
  182. return join(array, separator, 0, array.length);
  183. }
  184.  
  185. /**
  186. * <p>
  187. * Joins the elements of the provided array into a single String containing the provided list of elements.
  188. * </p>
  189. *
  190. * <p>
  191. * No delimiter is added before or after the list. Null objects or empty strings within the array are represented
  192. * by empty strings.
  193. * </p>
  194. *
  195. * <pre>
  196. * StringUtils.join(null, *) = null
  197. * StringUtils.join([], *) = ""
  198. * StringUtils.join([null], *) = ""
  199. * StringUtils.join([1, 2, 3], ';') = "1;2;3"
  200. * StringUtils.join([1, 2, 3], null) = "123"
  201. * </pre>
  202. *
  203. * @param array
  204. * the array of values to join together, may be null
  205. * @param separator
  206. * the separator character to use
  207. * @return the joined String, {@code null} if null array input
  208. * @since 3.2
  209. */
  210. public static String join(final int[] array, final char separator) {
  211. if (array == null) {
  212. return null;
  213. }
  214. return join(array, separator, 0, array.length);
  215. }
  216.  
  217. /**
  218. * <p>
  219. * Joins the elements of the provided array into a single String containing the provided list of elements.
  220. * </p>
  221. *
  222. * <p>
  223. * No delimiter is added before or after the list. Null objects or empty strings within the array are represented
  224. * by empty strings.
  225. * </p>
  226. *
  227. * <pre>
  228. * StringUtils.join(null, *) = null
  229. * StringUtils.join([], *) = ""
  230. * StringUtils.join([null], *) = ""
  231. * StringUtils.join([1, 2, 3], ';') = "1;2;3"
  232. * StringUtils.join([1, 2, 3], null) = "123"
  233. * </pre>
  234. *
  235. * @param array
  236. * the array of values to join together, may be null
  237. * @param separator
  238. * the separator character to use
  239. * @return the joined String, {@code null} if null array input
  240. * @since 3.2
  241. */
  242. public static String join(final short[] array, final char separator) {
  243. if (array == null) {
  244. return null;
  245. }
  246. return join(array, separator, 0, array.length);
  247. }
  248.  
  249. /**
  250. * <p>
  251. * Joins the elements of the provided array into a single String containing the provided list of elements.
  252. * </p>
  253. *
  254. * <p>
  255. * No delimiter is added before or after the list. Null objects or empty strings within the array are represented
  256. * by empty strings.
  257. * </p>
  258. *
  259. * <pre>
  260. * StringUtils.join(null, *) = null
  261. * StringUtils.join([], *) = ""
  262. * StringUtils.join([null], *) = ""
  263. * StringUtils.join([1, 2, 3], ';') = "1;2;3"
  264. * StringUtils.join([1, 2, 3], null) = "123"
  265. * </pre>
  266. *
  267. * @param array
  268. * the array of values to join together, may be null
  269. * @param separator
  270. * the separator character to use
  271. * @return the joined String, {@code null} if null array input
  272. * @since 3.2
  273. */
  274. public static String join(final byte[] array, final char separator) {
  275. if (array == null) {
  276. return null;
  277. }
  278. return join(array, separator, 0, array.length);
  279. }
  280.  
  281. /**
  282. * <p>
  283. * Joins the elements of the provided array into a single String containing the provided list of elements.
  284. * </p>
  285. *
  286. * <p>
  287. * No delimiter is added before or after the list. Null objects or empty strings within the array are represented
  288. * by empty strings.
  289. * </p>
  290. *
  291. * <pre>
  292. * StringUtils.join(null, *) = null
  293. * StringUtils.join([], *) = ""
  294. * StringUtils.join([null], *) = ""
  295. * StringUtils.join([1, 2, 3], ';') = "1;2;3"
  296. * StringUtils.join([1, 2, 3], null) = "123"
  297. * </pre>
  298. *
  299. * @param array
  300. * the array of values to join together, may be null
  301. * @param separator
  302. * the separator character to use
  303. * @return the joined String, {@code null} if null array input
  304. * @since 3.2
  305. */
  306. public static String join(final char[] array, final char separator) {
  307. if (array == null) {
  308. return null;
  309. }
  310. return join(array, separator, 0, array.length);
  311. }
  312.  
  313. /**
  314. * <p>
  315. * Joins the elements of the provided array into a single String containing the provided list of elements.
  316. * </p>
  317. *
  318. * <p>
  319. * No delimiter is added before or after the list. Null objects or empty strings within the array are represented
  320. * by empty strings.
  321. * </p>
  322. *
  323. * <pre>
  324. * StringUtils.join(null, *) = null
  325. * StringUtils.join([], *) = ""
  326. * StringUtils.join([null], *) = ""
  327. * StringUtils.join([1, 2, 3], ';') = "1;2;3"
  328. * StringUtils.join([1, 2, 3], null) = "123"
  329. * </pre>
  330. *
  331. * @param array
  332. * the array of values to join together, may be null
  333. * @param separator
  334. * the separator character to use
  335. * @return the joined String, {@code null} if null array input
  336. * @since 3.2
  337. */
  338. public static String join(final float[] array, final char separator) {
  339. if (array == null) {
  340. return null;
  341. }
  342. return join(array, separator, 0, array.length);
  343. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement