From 3bff648f7e1b8880cde37073dff1946b943ce0d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pap=20L=C5=91rinc?= Date: Thu, 23 Jun 2016 14:44:27 +0300 Subject: [PATCH] Added a few methods to the public API of collections --- javaslang/src/main/java/javaslang/Lazy.java | 27 ++++++-------- .../main/java/javaslang/collection/Array.java | 12 +++---- .../java/javaslang/collection/CharSeq.java | 20 +++++------ .../javaslang/collection/LinkedHashSet.java | 2 +- .../main/java/javaslang/collection/List.java | 8 ++--- .../javaslang/collection/PriorityQueue.java | 8 ++--- .../main/java/javaslang/collection/Queue.java | 10 +++--- .../java/javaslang/collection/Stream.java | 31 ++++++++-------- .../java/javaslang/collection/TreeMap.java | 11 +++--- .../java/javaslang/collection/Vector.java | 8 ++--- .../src/main/java/javaslang/control/Try.java | 35 ++++++++----------- 11 files changed, 79 insertions(+), 93 deletions(-) diff --git a/javaslang/src/main/java/javaslang/Lazy.java b/javaslang/src/main/java/javaslang/Lazy.java index 689b70e78d..28f5a19053 100644 --- a/javaslang/src/main/java/javaslang/Lazy.java +++ b/javaslang/src/main/java/javaslang/Lazy.java @@ -7,25 +7,18 @@ import javaslang.collection.Iterator; import javaslang.collection.List; -import javaslang.collection.Seq; +import javaslang.collection.*; import javaslang.control.Option; -import java.io.IOException; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Proxy; -import java.util.NoSuchElementException; -import java.util.Objects; -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.function.Predicate; -import java.util.function.Supplier; +import java.io.*; +import java.lang.reflect.*; +import java.util.*; +import java.util.function.*; /** * Represents a lazy evaluated value. Compared to a Supplier, Lazy is memoizing, i.e. it evaluates only once and * therefore is referential transparent. - * + *

*

  * 
  * final Lazy<Double> l = Lazy.of(Math::random);
@@ -35,9 +28,9 @@
  * l.get();         // = 0.123 (memoized)
  * 
  * 
- * + *

* Since 2.0.0 you may also create a real lazy value (works only with interfaces): - * + *

*

final CharSequence chars = Lazy.val(() -> "Yay!", CharSequence.class);
* * @author Daniel Dietrich @@ -68,7 +61,7 @@ private Lazy(Supplier supplier) { * @return the given {@code lazy} instance as narrowed type {@code Lazy}. */ @SuppressWarnings("unchecked") - static Lazy narrow(Lazy lazy) { + public static Lazy narrow(Lazy lazy) { return (Lazy) lazy; } @@ -127,7 +120,7 @@ public static T val(Supplier supplier, Class type) { } public Option filter(Predicate predicate) { - T v = get(); + final T v = get(); return predicate.test(v) ? Option.some(v) : Option.none(); } diff --git a/javaslang/src/main/java/javaslang/collection/Array.java b/javaslang/src/main/java/javaslang/collection/Array.java index df143f944e..1c7ec7fc22 100644 --- a/javaslang/src/main/java/javaslang/collection/Array.java +++ b/javaslang/src/main/java/javaslang/collection/Array.java @@ -127,7 +127,7 @@ public static Array ofAll(Iterable elements) { * @param Component type of the Stream. * @return A Array containing the given elements in the same order. */ - static Array ofAll(java.util.stream.Stream javaStream) { + public static Array ofAll(java.util.stream.Stream javaStream) { Objects.requireNonNull(javaStream, "javaStream is null"); return wrap(javaStream.toArray()); } @@ -482,7 +482,7 @@ public static Array rangeClosedBy(long from, long toInclusive, long step) * @return an Array with the values built up by the iteration * @throws IllegalArgumentException if {@code f} is null */ - static Array unfoldRight(T seed, Function>> f) { + public static Array unfoldRight(T seed, Function>> f) { return Iterator.unfoldRight(seed, f).toArray(); } @@ -509,7 +509,7 @@ static Array unfoldRight(T seed, Function Array unfoldLeft(T seed, Function>> f) { + public static Array unfoldLeft(T seed, Function>> f) { return Iterator.unfoldLeft(seed, f).toArray(); } @@ -536,7 +536,7 @@ static Array unfoldLeft(T seed, Function Array unfold(T seed, Function>> f) { + public static Array unfold(T seed, Function>> f) { return Iterator.unfold(seed, f).toArray(); } @@ -1052,13 +1052,13 @@ public Array scanLeft(U zero, BiFunction(), (c, u) -> { c.add(u); return c; - }, list -> Array. wrap(list.toArray())); + }, list -> Array.wrap(list.toArray())); } @Override public Array scanRight(U zero, BiFunction operation) { Objects.requireNonNull(operation, "operation is null"); - return Collections.scanRight(this, zero, operation, List.empty(), List::prepend, list -> Array. wrap(list.toJavaArray())); + return Collections.scanRight(this, zero, operation, List.empty(), List::prepend, list -> Array.wrap(list.toJavaArray())); } @Override diff --git a/javaslang/src/main/java/javaslang/collection/CharSeq.java b/javaslang/src/main/java/javaslang/collection/CharSeq.java index f4064740d1..d8335fe7a3 100644 --- a/javaslang/src/main/java/javaslang/collection/CharSeq.java +++ b/javaslang/src/main/java/javaslang/collection/CharSeq.java @@ -238,7 +238,7 @@ public static CharSeq rangeClosedBy(char from, char toInclusive, int step) { * @return a CharSeq with the values built up by the iteration * @throws IllegalArgumentException if {@code f} is null */ - static CharSeq unfoldRight(T seed, Function>> f) { + public static CharSeq unfoldRight(T seed, Function>> f) { return CharSeq.ofAll(Iterator.unfoldRight(seed, f)); } @@ -265,7 +265,7 @@ static CharSeq unfoldRight(T seed, Function CharSeq unfoldLeft(T seed, Function>> f) { + public static CharSeq unfoldLeft(T seed, Function>> f) { return CharSeq.ofAll(Iterator.unfoldLeft(seed, f)); } @@ -292,7 +292,7 @@ static CharSeq unfoldLeft(T seed, Function>> f) { + public static CharSeq unfold(Character seed, Function>> f) { return CharSeq.ofAll(Iterator.unfold(seed, f)); } @@ -1839,7 +1839,7 @@ public int lastIndexOf(int ch, int fromIndex) { * @param fromIndex the index to start the search from. * @return {@code Some(index)} or {@code None} if not found. */ - Option lastIndexOfOption(int ch, int fromIndex) { + public Option lastIndexOfOption(int ch, int fromIndex) { return Collections.indexOption(lastIndexOf(ch, fromIndex)); } @@ -1867,7 +1867,7 @@ public int indexOf(CharSeq str) { * @param str the substring to search for. * @return {@code Some(index)} or {@code None} if not found. */ - Option indexOfOption(CharSeq str) { + public Option indexOfOption(CharSeq str) { return Collections.indexOption(indexOf(str)); } @@ -1899,7 +1899,7 @@ public int indexOf(CharSeq str, int fromIndex) { * @param fromIndex the index from which to start the search. * @return {@code Some(index)} or {@code None} if not found. */ - Option indexOfOption(CharSeq str, int fromIndex) { + public Option indexOfOption(CharSeq str, int fromIndex) { return Collections.indexOption(indexOf(str, fromIndex)); } @@ -1928,7 +1928,7 @@ public int lastIndexOf(CharSeq str) { * @param str the substring to search for. * @return {@code Some(index)} or {@code None} if not found. */ - Option lastIndexOfOption(CharSeq str) { + public Option lastIndexOfOption(CharSeq str) { return Collections.indexOption(lastIndexOf(str)); } @@ -1960,7 +1960,7 @@ public int lastIndexOf(CharSeq str, int fromIndex) { * @param fromIndex the index to start the search from. * @return {@code Some(index)} or {@code None} if not found. */ - Option lastIndexOfOption(CharSeq str, int fromIndex) { + public Option lastIndexOfOption(CharSeq str, int fromIndex) { return Collections.indexOption(lastIndexOf(str, fromIndex)); } @@ -2500,12 +2500,12 @@ public char[] toCharArray() { } @FunctionalInterface - interface CharUnaryOperator { + public interface CharUnaryOperator { char apply(char c); } @FunctionalInterface - interface CharFunction { + public interface CharFunction { R apply(char c); } } diff --git a/javaslang/src/main/java/javaslang/collection/LinkedHashSet.java b/javaslang/src/main/java/javaslang/collection/LinkedHashSet.java index 8ab51eb6e3..ffe6a584aa 100644 --- a/javaslang/src/main/java/javaslang/collection/LinkedHashSet.java +++ b/javaslang/src/main/java/javaslang/collection/LinkedHashSet.java @@ -154,7 +154,7 @@ public static LinkedHashSet ofAll(Iterable elements) { * @param Component type of the Stream. * @return A LinkedHashSet containing the given elements in the same order. */ - static LinkedHashSet ofAll(java.util.stream.Stream javaStream) { + public static LinkedHashSet ofAll(java.util.stream.Stream javaStream) { Objects.requireNonNull(javaStream, "javaStream is null"); return ofAll(Iterator.ofAll(javaStream.iterator())); } diff --git a/javaslang/src/main/java/javaslang/collection/List.java b/javaslang/src/main/java/javaslang/collection/List.java index bba054308d..d68c57764b 100644 --- a/javaslang/src/main/java/javaslang/collection/List.java +++ b/javaslang/src/main/java/javaslang/collection/List.java @@ -580,7 +580,7 @@ static List rangeClosedBy(long from, long toInclusive, long step) { * @return a list with the values built up by the iteration * @throws IllegalArgumentException if {@code f} is null */ - static List unfoldRight(T seed, Function>> f) { + static List unfoldRight(T seed, Function>> f) { return Iterator.unfoldRight(seed, f).toList(); } @@ -607,7 +607,7 @@ static List unfoldRight(T seed, Function List unfoldLeft(T seed, Function>> f) { + static List unfoldLeft(T seed, Function>> f) { return Iterator.unfoldLeft(seed, f).toList(); } @@ -634,7 +634,7 @@ static List unfoldLeft(T seed, Function List unfold(T seed, Function>> f) { + static List unfold(T seed, Function>> f) { return Iterator.unfold(seed, f).toList(); } @@ -646,7 +646,7 @@ default List append(T element) { @Override default List appendAll(Iterable elements) { Objects.requireNonNull(elements, "elements is null"); - return List.ofAll(elements).prependAll(this); + return List. ofAll(elements).prependAll(this); } @Override diff --git a/javaslang/src/main/java/javaslang/collection/PriorityQueue.java b/javaslang/src/main/java/javaslang/collection/PriorityQueue.java index 0fb036735f..b052533108 100644 --- a/javaslang/src/main/java/javaslang/collection/PriorityQueue.java +++ b/javaslang/src/main/java/javaslang/collection/PriorityQueue.java @@ -133,7 +133,7 @@ public static PriorityQueue empty(Comparator comparator) { * @param Component type of the {@code PriorityQueue}. * @return A {@code PriorityQueue} Collector. */ - static Collector, PriorityQueue> collector() { + public static Collector, PriorityQueue> collector() { final Supplier> supplier = ArrayList::new; final BiConsumer, T> accumulator = ArrayList::add; final BinaryOperator> combiner = (left, right) -> { @@ -213,7 +213,7 @@ public static PriorityQueue ofAll(Comparator comparator, java. * @throws NullPointerException if {@code function} is null */ @GwtIncompatible - static PriorityQueue tabulate(int size, Function function) { + public static PriorityQueue tabulate(int size, Function function) { Objects.requireNonNull(function, "function is null"); final Comparator comparator = naturalComparator(); return Collections.tabulate(size, function, empty(comparator), values -> ofAll(comparator, List.of(values))); @@ -228,9 +228,9 @@ static PriorityQueue tabulate(int size, Function PriorityQueue fill(int size, Supplier supplier) { + @SuppressWarnings("unchecked") + public static PriorityQueue fill(int size, Supplier supplier) { Objects.requireNonNull(supplier, "supplier is null"); final Comparator comparator = naturalComparator(); return Collections.fill(size, supplier, empty(comparator), values -> ofAll(comparator, List.of(values))); diff --git a/javaslang/src/main/java/javaslang/collection/Queue.java b/javaslang/src/main/java/javaslang/collection/Queue.java index e4132278a7..199859d9c2 100644 --- a/javaslang/src/main/java/javaslang/collection/Queue.java +++ b/javaslang/src/main/java/javaslang/collection/Queue.java @@ -6,7 +6,7 @@ package javaslang.collection; import javaslang.*; -import javaslang.control.*; +import javaslang.control.Option; import java.util.*; import java.util.function.*; @@ -162,7 +162,7 @@ public static Queue ofAll(Iterable elements) { * @param Component type of the Stream. * @return A Queue containing the given elements in the same order. */ - static Queue ofAll(java.util.stream.Stream javaStream) { + public static Queue ofAll(java.util.stream.Stream javaStream) { Objects.requireNonNull(javaStream, "javaStream is null"); return new Queue<>(List.ofAll(javaStream), List.empty()); } @@ -525,7 +525,7 @@ public static Queue rangeClosedBy(long from, long toInclusive, long step) * @return a Queue with the values built up by the iteration * @throws IllegalArgumentException if {@code f} is null */ - static Queue unfoldRight(T seed, Function>> f) { + public static Queue unfoldRight(T seed, Function>> f) { return Iterator.unfoldRight(seed, f).toQueue(); } @@ -552,7 +552,7 @@ static Queue unfoldRight(T seed, Function Queue unfoldLeft(T seed, Function>> f) { + public static Queue unfoldLeft(T seed, Function>> f) { return Iterator.unfoldLeft(seed, f).toQueue(); } @@ -579,7 +579,7 @@ static Queue unfoldLeft(T seed, Function Queue unfold(T seed, Function>> f) { + public static Queue unfold(T seed, Function>> f) { return Iterator.unfold(seed, f).toQueue(); } diff --git a/javaslang/src/main/java/javaslang/collection/Stream.java b/javaslang/src/main/java/javaslang/collection/Stream.java index 36700d0829..4ed500ad7d 100644 --- a/javaslang/src/main/java/javaslang/collection/Stream.java +++ b/javaslang/src/main/java/javaslang/collection/Stream.java @@ -6,8 +6,7 @@ package javaslang.collection; import javaslang.*; -import javaslang.collection.Stream.Cons; -import javaslang.collection.Stream.Empty; +import javaslang.collection.Stream.*; import javaslang.collection.StreamModule.*; import javaslang.control.Option; @@ -48,9 +47,9 @@ * Stream.iterate(Object, Function)// e.g. Stream.iterate(1, i -> i * 2); * * - * + *

* Factory method applications: - * + *

*

  * 
  * Stream<Integer>       s1 = Stream.of(1);
@@ -67,9 +66,9 @@
  * Stream<Integer[]>     s7 = Stream.<Integer[]> of(new Integer[] {1, 2, 3});
  * 
  * 
- * + *

* Example: Generating prime numbers - * + *

*

  * 
  * // = Stream(2L, 3L, 5L, 7L, ...)
@@ -86,7 +85,7 @@
  * }
  * 
  * 
- * + *

* See Okasaki, Chris: Purely Functional Data Structures (p. 34 ff.). Cambridge, 2003. * * @param component type of this Stream @@ -245,7 +244,7 @@ static Stream of(T element) { /** * Creates a Stream of the given elements. - * + *

*

  Stream.of(1, 2, 3, 4)
      * = Nil.instance().prepend(4).prepend(3).prepend(2).prepend(1)
      * = new Cons(1, new Cons(2, new Cons(3, new Cons(4, Nil.instance()))))
@@ -651,7 +650,7 @@ static Stream rangeClosedBy(long from, long toInclusive, long step) { * @return a Stream with the values built up by the iteration * @throws IllegalArgumentException if {@code f} is null */ - static Stream unfoldRight(T seed, Function>> f) { + static Stream unfoldRight(T seed, Function>> f) { return Iterator.unfoldRight(seed, f).toStream(); } @@ -678,7 +677,7 @@ static Stream unfoldRight(T seed, Function Stream unfoldLeft(T seed, Function>> f) { + static Stream unfoldLeft(T seed, Function>> f) { return Iterator.unfoldLeft(seed, f).toStream(); } @@ -705,7 +704,7 @@ static Stream unfoldLeft(T seed, Function Stream unfold(T seed, Function>> f) { + static Stream unfold(T seed, Function>> f) { return Iterator.unfold(seed, f).toStream(); } @@ -1007,7 +1006,7 @@ default Stream insertAll(int index, Iterable elements) { if (index < 0) { throw new IndexOutOfBoundsException("insertAll(" + index + ", elements)"); } else if (index == 0) { - return isEmpty() ? Stream.ofAll(elements) : Stream.ofAll(elements).appendAll(this); + return isEmpty() ? Stream.ofAll(elements) : Stream. ofAll(elements).appendAll(this); } else if (isEmpty()) { throw new IndexOutOfBoundsException("insertAll(" + index + ", elements) on Nil"); } else { @@ -1133,7 +1132,7 @@ default Stream prepend(T element) { @Override default Stream prependAll(Iterable elements) { Objects.requireNonNull(elements, "elements is null"); - return Stream.ofAll(elements).appendAll(this); + return Stream. ofAll(elements).appendAll(this); } @Override @@ -1754,15 +1753,15 @@ public Stream appendAll(Iterable elements) { @Override public Stream tail() { - Stream t = tail.get(); + final Stream t = tail.get(); if (t.isEmpty()) { return Stream.ofAll(queue); } else { if (t instanceof ConsImpl) { - ConsImpl c = (ConsImpl) t; + final ConsImpl c = (ConsImpl) t; return new AppendElements<>(c.head(), queue, c.tail); } else { - AppendElements a = (AppendElements) t; + final AppendElements a = (AppendElements) t; return new AppendElements<>(a.head(), a.queue.appendAll(queue), a.tail); } } diff --git a/javaslang/src/main/java/javaslang/collection/TreeMap.java b/javaslang/src/main/java/javaslang/collection/TreeMap.java index 93d12a0b30..634a908772 100644 --- a/javaslang/src/main/java/javaslang/collection/TreeMap.java +++ b/javaslang/src/main/java/javaslang/collection/TreeMap.java @@ -54,8 +54,8 @@ public static , V> Collector, Array * {@link java.util.stream.Stream#collect(java.util.stream.Collector)} to obtain a * {@link javaslang.collection.TreeMap}. * - * @param The key type - * @param The value type + * @param The key type + * @param The value type * @param keyComparator A key comparator * @return A {@link javaslang.collection.TreeMap} Collector. */ @@ -108,7 +108,7 @@ public static TreeMap empty(Comparator keyComparator) { * @return the given {@code treeMap} instance as narrowed type {@code TreeMap}. */ @SuppressWarnings("unchecked") - static TreeMap narrow(TreeMap treeMap) { + public static TreeMap narrow(TreeMap treeMap) { return (TreeMap) treeMap; } @@ -477,7 +477,6 @@ public SortedSet keySet() { return TreeSet.ofAll(keyComparator(), iterator().map(Tuple2::_1)); } - @Override public TreeMap map(BiFunction> mapper) { return map(naturalComparator(), mapper); @@ -500,7 +499,7 @@ public TreeMap mapKeys(Function keyMapper) @Override public TreeMap mapKeys(Function keyMapper, BiFunction valueMerge) { final Comparator comparator = Comparators.naturalComparator(); - return Collections.mapKeys(this, TreeMap.empty(comparator), keyMapper, valueMerge); + return Collections.mapKeys(this, TreeMap. empty(comparator), keyMapper, valueMerge); } @Override @@ -596,7 +595,7 @@ private static TreeMap createTreeMap(Comparator) entry); } return tree.isEmpty() ? (TreeMap) TreeMap.empty() - : new TreeMap<>(tree); + : new TreeMap<>(tree); } // -- Object diff --git a/javaslang/src/main/java/javaslang/collection/Vector.java b/javaslang/src/main/java/javaslang/collection/Vector.java index e79765dafb..95e5e99f15 100644 --- a/javaslang/src/main/java/javaslang/collection/Vector.java +++ b/javaslang/src/main/java/javaslang/collection/Vector.java @@ -173,7 +173,7 @@ public static Vector ofAll(Iterable elements) { * @param Component type of the Stream. * @return A Vector containing the given elements in the same order. */ - static Vector ofAll(java.util.stream.Stream javaStream) { + public static Vector ofAll(java.util.stream.Stream javaStream) { Objects.requireNonNull(javaStream, "javaStream is null"); return ofAll(Iterator.ofAll(javaStream.iterator())); } @@ -499,7 +499,7 @@ public static Vector rangeClosedBy(long from, long toInclusive, long step) * @return a Vector with the values built up by the iteration * @throws IllegalArgumentException if {@code f} is null */ - static Vector unfoldRight(T seed, Function>> f) { + public static Vector unfoldRight(T seed, Function>> f) { return Iterator.unfoldRight(seed, f).toVector(); } @@ -526,7 +526,7 @@ static Vector unfoldRight(T seed, Function Vector unfoldLeft(T seed, Function>> f) { + public static Vector unfoldLeft(T seed, Function>> f) { return Iterator.unfoldLeft(seed, f).toVector(); } @@ -553,7 +553,7 @@ static Vector unfoldLeft(T seed, Function Vector unfold(T seed, Function>> f) { + public static Vector unfold(T seed, Function>> f) { return Iterator.unfold(seed, f).toVector(); } diff --git a/javaslang/src/main/java/javaslang/control/Try.java b/javaslang/src/main/java/javaslang/control/Try.java index 3e6ee789fd..1267de0333 100644 --- a/javaslang/src/main/java/javaslang/control/Try.java +++ b/javaslang/src/main/java/javaslang/control/Try.java @@ -8,16 +8,11 @@ import javaslang.Value; import javaslang.collection.Iterator; import javaslang.collection.List; -import javaslang.collection.Seq; +import javaslang.collection.*; import java.io.Serializable; -import java.util.Arrays; -import java.util.NoSuchElementException; -import java.util.Objects; -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.function.Predicate; -import java.util.function.Supplier; +import java.util.*; +import java.util.function.*; /** * An implementation similar to Scala's Try control. @@ -136,7 +131,7 @@ default Try andThen(Consumer consumer) { * Passes the result to the given {@code consumer} if this is a {@code Success}. *

* The main use case is chaining checked functions using method references: - * + *

*

      * 
      * Try.of(() -> 100)
@@ -181,15 +176,15 @@ default Try andThen(Runnable runnable) {
      * Runs the given runnable if this is a {@code Success}, otherwise returns this {@code Failure}.
      * 

* The main use case is chaining runnables using method references: - * + *

*

      * 
      * Try.run(A::methodRef).andThen(B::methodRef).andThen(C::methodRef);
      * 
      * 
- * + *

* Please note that these lines are semantically the same: - * + *

*

      * 
      * Try.run(this::doStuff)
@@ -416,9 +411,9 @@ default  Try map(Function mapper) {
      * passing the result of the current expression to it.
      * If this expression is a {@code Failure} then it'll return a new
      * {@code Failure} of type R with the original exception.
-     *
+     * 

* The main use case is chaining checked functions using method references: - * + *

*

      * 
      * Try.of(() -> 0)
@@ -860,7 +855,7 @@ private FatalException(Throwable exception) {
         @Override
         public boolean equals(Object o) {
             return (o == this) || (o instanceof FatalException
-                    && Arrays.deepEquals(getCause().getStackTrace(), ((FatalException) o).getCause().getStackTrace()));
+                                   && Arrays.deepEquals(getCause().getStackTrace(), ((FatalException) o).getCause().getStackTrace()));
         }
 
         @Override
@@ -906,7 +901,7 @@ private NonFatalException(Throwable exception) {
          * @throws Error                if the given exception is fatal, i.e. not recoverable
          * @throws NullPointerException if exception is null
          */
-        static NonFatalException of(Throwable exception) {
+        public static NonFatalException of(Throwable exception) {
             Objects.requireNonNull(exception, "exception is null");
             if (exception instanceof NonFatalException) {
                 return (NonFatalException) exception;
@@ -914,9 +909,9 @@ static NonFatalException of(Throwable exception) {
                 throw (FatalException) exception;
             } else {
                 final boolean isFatal = exception instanceof InterruptedException
-                        || exception instanceof LinkageError
-                        || exception instanceof ThreadDeath
-                        || exception instanceof VirtualMachineError;
+                                        || exception instanceof LinkageError
+                                        || exception instanceof ThreadDeath
+                                        || exception instanceof VirtualMachineError;
                 if (isFatal) {
                     throw new FatalException(exception);
                 } else {
@@ -934,7 +929,7 @@ static NonFatalException of(Throwable exception) {
         @Override
         public boolean equals(Object o) {
             return (o == this) || (o instanceof NonFatalException
-                    && Arrays.deepEquals(getCause().getStackTrace(), ((NonFatalException) o).getCause().getStackTrace()));
+                                   && Arrays.deepEquals(getCause().getStackTrace(), ((NonFatalException) o).getCause().getStackTrace()));
         }
 
         @Override