Mercurial > hg > Members > shoshi > jungle > jungle-core
changeset 216:9a410eddbfa4 OptionalTreeMap
delete warning
author | tatsuki |
---|---|
date | Tue, 01 Sep 2015 05:04:38 +0900 |
parents | 1b3661be3119 |
children | 3b31dd5e5a28 |
files | src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/treemap/BlackNode.java src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/treemap/DefaultComparator.java src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/treemap/Node.java src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/treemap/RedNode.java src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/treemap/RotateParent.java src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/treemap/TreeMap.java |
diffstat | 6 files changed, 13 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/treemap/BlackNode.java Tue Aug 11 08:16:07 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/treemap/BlackNode.java Tue Sep 01 05:04:38 2015 +0900 @@ -83,8 +83,8 @@ return false; } - @Override + @SuppressWarnings("unchecked") public Node<K, V> replaceNode(Node<K, V> parent, Comparator ctr) throws RotateParent { Node<K, V> newNode; if (!this.left().isNotEmpty() && !this.right().isNotEmpty()) { //自身を削除する @@ -115,7 +115,7 @@ return leftSubTreeNode.deleteBalance(newParent, ctr); } } else { - Node<K, V> leftSubTreeNode = null; + Node<K, V> leftSubTreeNode; try { leftSubTreeNode = this.left().replaceNode(this, ctr);//右の子がいなかった場合、左の子を昇格させるだけで良い。 return createNode(this.left().getKey(), this.left().getValue(), leftSubTreeNode, this.right());
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/treemap/DefaultComparator.java Tue Aug 11 08:16:07 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/treemap/DefaultComparator.java Tue Sep 01 05:04:38 2015 +0900 @@ -2,11 +2,9 @@ import java.util.Comparator; -/** - * Created by e115731 on 15/08/10. - */ public class DefaultComparator<K> implements Comparator<K>{ @Override + @SuppressWarnings("unchecked") public int compare(K key, K compareKey) { return ((Comparable<? super K>)key).compareTo(compareKey); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/treemap/Node.java Tue Aug 11 08:16:07 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/treemap/Node.java Tue Sep 01 05:04:38 2015 +0900 @@ -79,6 +79,7 @@ } + @SuppressWarnings("unchecked") public Node<K, V> delete(K key, Node<K, V> parent, Comparator ctr, Rotate side) throws RotateParent { if (this.isNotEmpty()) { int result = compare(key, ctr); @@ -120,7 +121,7 @@ return null; // no key } - + @SuppressWarnings("unchecked") public Node<K, V> deleteSubTreeMaxNode(Node<K, V> parent, Comparator ctr, Rotate side) throws RotateParent { Node<K, V> node; try {
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/treemap/RedNode.java Tue Aug 11 08:16:07 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/treemap/RedNode.java Tue Sep 01 05:04:38 2015 +0900 @@ -55,6 +55,7 @@ return true; } + @SuppressWarnings("unchecked") @Override public Node<K, V> replaceNode(Node<K, V> parent, Comparator ctr) throws RotateParent { Node<K, V> newNode;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/treemap/RotateParent.java Tue Aug 11 08:16:07 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/treemap/RotateParent.java Tue Sep 01 05:04:38 2015 +0900 @@ -1,5 +1,8 @@ package jp.ac.u_ryukyu.ie.cr.jungle.data.treemap; +/** + * Generic Exception not support + **/ public class RotateParent extends Exception { Node parent; @@ -10,4 +13,4 @@ public Node getParent() { return parent; } -} +} \ No newline at end of file
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/treemap/TreeMap.java Tue Aug 11 08:16:07 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/treemap/TreeMap.java Tue Sep 01 05:04:38 2015 +0900 @@ -11,7 +11,7 @@ public class TreeMap<K, V> { final Node<K, V> root; - Comparator comparator; + final Comparator comparator; public TreeMap() { this.root = new EmptyNode<>(); @@ -33,20 +33,15 @@ } public Optional<V> get(final K key) { - return root.get(key, comparator); + return root.get(key, this.comparator); } public TreeMap<K, V> put(K key, V value) { - - if (key == null || value == null) // null check - throw new NullPointerException(); - if (isEmpty()) { Node<K, V> newRoot = new BlackNode<>(key, value, new EmptyNode<>(), new EmptyNode<>()); return new TreeMap<>(newRoot, this.comparator); } - - Node<K, V> newEntry = root.put(key, value, comparator); + Node<K, V> newEntry = root.put(key, value, this.comparator); Node<K, V> newRoot = new BlackNode<>(newEntry.getKey(), newEntry.getValue(), newEntry.left(), newEntry.right()); return new TreeMap<>(newRoot, this.comparator); }