Merge branch 'oc-bridge'
authorMax Medvedev <maxim.medvedev@jetbrains.com>
Sat, 18 Apr 2015 13:08:18 +0000 (16:08 +0300)
committerMax Medvedev <maxim.medvedev@jetbrains.com>
Sat, 18 Apr 2015 13:08:18 +0000 (16:08 +0300)
platform/util/src/com/intellij/util/containers/ContainerUtil.java

index 7bc87c9ae20de7ecdbf9d795fa67966f0aaa9391..3c687a465ef615d23b40102c114a33cfcb0d67c8 100644 (file)
@@ -214,6 +214,22 @@ public class ContainerUtil extends ContainerUtilRt {
     };
   }
 
+  @NotNull
+  @Contract(pure = true)
+  public static <T> List<T> newUnmodifiableList(List<? extends T> originalList) {
+    int size = originalList.size();
+    if (size == 0) {
+      return emptyList();
+    }
+    else if (size == 1) {
+      return Collections.singletonList(originalList.get(0));
+    }
+    else {
+      return Collections.unmodifiableList(newArrayList(originalList));
+    }
+  }
+
+
   @NotNull
   @Contract(pure=true)
   public static <T> List<T> newSmartList() {