Remove useless UnsupportedOperationException throws
[yangtools.git] / common / util / src / main / java / org / opendaylight / yangtools / util / LazyCollections.java
index c70fd8c85d7244ab1a54d130de80a86e5a17b662..603039b2ff4ff1ac606f5be3f36585436c907c74 100644 (file)
@@ -12,11 +12,13 @@ import java.util.Collections;
 import java.util.List;
 
 /**
- * Utility methods for lazily instantiated collections. These are useful for
- * situations when we start off with an empty collection (where Collections.empty()
- * can be reused), but need to add more things.
+ * Utility methods for lazily instantiated collections. These are useful for situations when we start off with an empty
+ * collection (where Collections.empty() * can be reused), but need to add more things.
  */
 public final class LazyCollections {
+    private LazyCollections() {
+        // Hidden on purpose
+    }
 
     /**
      * Add an element to a list, potentially transforming the list.
@@ -29,18 +31,17 @@ public final class LazyCollections {
         final List<T> ret;
 
         switch (list.size()) {
-        case 0:
-            return Collections.singletonList(obj);
-        case 1:
-            ret = new ArrayList<>();
-            ret.addAll(list);
-            break;
-        default:
-            ret = list;
+            case 0:
+                return Collections.singletonList(obj);
+            case 1:
+                ret = new ArrayList<>(2);
+                ret.addAll(list);
+                break;
+            default:
+                ret = list;
         }
 
         ret.add(obj);
         return ret;
     }
-
 }