Uploaded image for project: 'Commons Collections'
  1. Commons Collections
  2. COLLECTIONS-436

Add a method that returns an empty collection if a passed in collection is null

    XMLWordPrintableJSON

    Details

    • Type: Wish
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 4.0-alpha1, 4.0
    • Component/s: Collection
    • Labels:
      None

      Description

      Would it be possible to add methods to CollectionUtils that return an empty collection if given a null? e.g.

          public static <T> List<T> emptyIfNull(List<T> list) {
              return list == null ? Collections.<T>emptyList() : list;
          }
      
          public static <T> Set<T> emptyIfNull(Set<T> set) {
              return set == null ? Collections.<T>emptySet() : set;
          }
      
          public static <K,V> Map<K,V> emptyIfNull(Map<K,V> map) {
              return map == null ? Collections.<K,V>emptyMap() : map;
          }
      

        Attachments

        1. COLLECTIONS-436.patch
          7 kB
          Arman Sharif

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              armandino Arman Sharif
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: