xSweeTs

ArraysUtil#isEmpty

May 10th, 2021 (edited)
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1. diff --git a/aCis_gameserver/java/net/sf/l2j/commons/util/ArraysUtil.java b/aCis_gameserver/java/net/sf/l2j/commons/util/ArraysUtil.java
  2. index 22ee0bf..124ad9e 100644
  3. --- a/aCis_gameserver/java/net/sf/l2j/commons/util/ArraysUtil.java
  4. +++ b/aCis_gameserver/java/net/sf/l2j/commons/util/ArraysUtil.java
  5. @@ -1,6 +1,10 @@
  6.  package net.sf.l2j.commons.util;
  7.  
  8. +import java.lang.reflect.Array;
  9.  import java.util.Arrays;
  10. +import java.util.Collection;
  11. +import java.util.Map;
  12. +import java.util.Objects;
  13.  
  14.  public class ArraysUtil
  15.  {
  16. @@ -11,9 +15,23 @@
  17.      * @param array : the array to look into.
  18.      * @return {@code true} if the array is empty or null.
  19.      */
  20. -   public static <T> boolean isEmpty(T[] array)
  21. +   public static <T> boolean isEmpty(T array)
  22.     {
  23. -       return array == null || array.length == 0;
  24. +       if (array == null)
  25. +           return true;
  26. +      
  27. +       if (array instanceof Collection)
  28. +           return ((Collection<?>) array).isEmpty();
  29. +       else if (array instanceof Map)
  30. +           return ((Map<?, ?>) array).isEmpty();
  31. +       else if (array instanceof String)
  32. +           return ((String) array).trim().isEmpty();
  33. +       else if (array instanceof CharSequence)
  34. +           return ((CharSequence) array).length() == 0;
  35. +       else if (array.getClass().isArray())
  36. +           return Array.getLength(array) == 0;
  37. +      
  38. +       return Objects.isNull(array);
  39.     }
Add Comment
Please, Sign In to add comment