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

    • Wish
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 4.0-alpha1, 4.0
    • Collection
    • 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

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

            Dates

              Created:
              Updated:
              Resolved: