X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=common%2Futil%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Futil%2FLazyCollections.java;h=603039b2ff4ff1ac606f5be3f36585436c907c74;hb=f429749a59a10820b1bad0e9c3502ceac2ec1d07;hp=c70fd8c85d7244ab1a54d130de80a86e5a17b662;hpb=0eb60011b52e4e56c62b47a36eb334f2c3b3ad6a;p=yangtools.git diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/LazyCollections.java b/common/util/src/main/java/org/opendaylight/yangtools/util/LazyCollections.java index c70fd8c85d..603039b2ff 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/LazyCollections.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/LazyCollections.java @@ -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 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; } - }