Returns a new TreeMap with the same mappings, size and comparator as this instance. @return a shallow copy of this instance. @see java.lang.Cloneable
()
| 1047 | * @see java.lang.Cloneable |
| 1048 | */ |
| 1049 | @SuppressWarnings("unchecked") |
| 1050 | @Override |
| 1051 | public Object clone() { |
| 1052 | try { |
| 1053 | TreeMap<K, V> clone = (TreeMap<K, V>) super.clone(); |
| 1054 | clone.entrySet = null; |
| 1055 | if (root != null) { |
| 1056 | clone.root = root.clone(null); |
| 1057 | // restore prev/next chain |
| 1058 | Node<K, V> node = minimum(clone.root); |
| 1059 | while (true) { |
| 1060 | Node<K, V> nxt = successor(node); |
| 1061 | if (nxt == null) { |
| 1062 | break; |
| 1063 | } |
| 1064 | nxt.prev = node; |
| 1065 | node.next = nxt; |
| 1066 | node = nxt; |
| 1067 | } |
| 1068 | } |
| 1069 | return clone; |
| 1070 | } catch (CloneNotSupportedException e) { |
| 1071 | return null; |
| 1072 | } |
| 1073 | } |
| 1074 | |
| 1075 | static private <K, V> Node<K, V> successor(Node<K, V> x) { |
| 1076 | if (x.right != null) { |