Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8247542

Utility-Method for collections to check not null and not empty

XMLWordPrintable

      A DESCRIPTION OF THE PROBLEM :
      Just as there is the method java.util.Objects.requireNonNull (..), it would be great if there is a similar method for collections that checks whether the collection is not null or empty.

      Java pseudocode:

      class java.util.Collections {

      public static <T extends java.util.Collection<?>> T getNotEmpty( T collection) {
      // Check if collection is null. If so, throw NullPointerException
      java.util.Objects.requireNonNull(collection);

      // Check if collection is empty. If so, throw Exception
      if (collection.isEmpty()) {
      throw new Exception("Collection is empty");
      }
      return collection;
      }

      }


            smarks Stuart Marks
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: