diff options
| author | EVE <EVE@EVE-PC> | 2017-03-14 12:07:14 -0400 |
|---|---|---|
| committer | EVE <EVE@EVE-PC> | 2017-03-14 12:07:14 -0400 |
| commit | 504ca816530efdff06bc202e0432ebd354aec304 (patch) | |
| tree | 4836932fb81d1d625470502c78c94d202c9a7420 /BJC-Utils2/src/main/java/bjc/utils/esodata | |
| parent | 5c1163df17c46f7d3e15b6c7949c38843ec56146 (diff) | |
Cleanup
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/esodata')
10 files changed, 149 insertions, 128 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/esodata/Directory.java b/BJC-Utils2/src/main/java/bjc/utils/esodata/Directory.java index 6fdfe16..79ae031 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/Directory.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/Directory.java @@ -37,17 +37,17 @@ public interface Directory<K, V> { /**
* Insert a sub-directory into the dictionary.
- *
+ *
* @param key
* The name of the new sub-directory
* @param value
* The sub-directory to insert
- *
+ *
* @return The old sub-directory attached to this key, or null if such a
* sub-directory didn't exist
*/
Directory<K, V> putSubdirectory(K key, Directory<K, V> value);
-
+
/**
* Create a new sub-directory.
*
@@ -60,14 +60,12 @@ public interface Directory<K, V> { * exists.
*/
default Directory<K, V> newSubdirectory(K key) {
- if(hasSubdirectory(key)) {
- return null;
- }
-
+ if(hasSubdirectory(key)) return null;
+
Directory<K, V> dir = new SimpleDirectory<>();
-
+
putSubdirectory(key, dir);
-
+
return dir;
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/esodata/DoubleTape.java b/BJC-Utils2/src/main/java/bjc/utils/esodata/DoubleTape.java index 85abbdc..6e256b6 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/DoubleTape.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/DoubleTape.java @@ -16,7 +16,7 @@ package bjc.utils.esodata; * * All operations that refer to the tape refer to the currently active side of * the tape, except for flip. - * + * * Flip refers to the entire tape for 'obvious' reasons. * * @param T @@ -24,8 +24,8 @@ package bjc.utils.esodata; * @author bjculkin */ public class DoubleTape<T> implements Tape<T> { - private Tape<T> front; - private Tape<T> back; + private Tape<T> front; + private Tape<T> back; /** * Create a new empty double-sided tape that doesn't autoextend. @@ -52,6 +52,7 @@ public class DoubleTape<T> implements Tape<T> { * * @return The item the tape is on. */ + @Override public T item() { return front.item(); } @@ -62,6 +63,7 @@ public class DoubleTape<T> implements Tape<T> { * @param itm * The new value for the tape item. */ + @Override public void item(T itm) { front.item(itm); } @@ -71,6 +73,7 @@ public class DoubleTape<T> implements Tape<T> { * * @return The current number of elements in the tape. */ + @Override public int size() { return front.size(); } @@ -81,6 +84,7 @@ public class DoubleTape<T> implements Tape<T> { * @param itm * The item to add. */ + @Override public void insertBefore(T itm) { front.insertBefore(itm); back.insertAfter(null); @@ -89,6 +93,7 @@ public class DoubleTape<T> implements Tape<T> { /** * Insert an element after the current item. */ + @Override public void insertAfter(T itm) { front.insertAfter(itm); back.insertBefore(itm); @@ -96,12 +101,13 @@ public class DoubleTape<T> implements Tape<T> { /** * Remove the current element. - * + * * Also moves the cursor back one step if possible to maintain relative * position, and removes the corresponding item from the non-active side * * @return The removed item from the active side. */ + @Override public T remove() { back.remove(); @@ -111,6 +117,7 @@ public class DoubleTape<T> implements Tape<T> { /** * Move the cursor to the left-most position. */ + @Override public void first() { front.first(); back.last(); @@ -119,6 +126,7 @@ public class DoubleTape<T> implements Tape<T> { /** * Move the cursor the right-most position. */ + @Override public void last() { front.last(); back.first(); @@ -131,6 +139,7 @@ public class DoubleTape<T> implements Tape<T> { * * @return True if the cursor was moved left. */ + @Override public boolean left() { return left(1); } @@ -146,11 +155,13 @@ public class DoubleTape<T> implements Tape<T> { * * @return True if the cursor was moved left. */ + @Override public boolean left(int amt) { boolean succ = front.left(amt); - if (succ) + if(succ) { back.right(amt); + } return succ; } @@ -162,6 +173,7 @@ public class DoubleTape<T> implements Tape<T> { * * @return Whether the cursor was moved right. */ + @Override public boolean right() { return right(1); } @@ -176,11 +188,13 @@ public class DoubleTape<T> implements Tape<T> { * * @return Whether the cursor was moved right. */ + @Override public boolean right(int amt) { boolean succ = front.right(amt); - if (succ) + if(succ) { back.left(amt); + } return succ; } diff --git a/BJC-Utils2/src/main/java/bjc/utils/esodata/SimpleDirectory.java b/BJC-Utils2/src/main/java/bjc/utils/esodata/SimpleDirectory.java index 22a7e56..3c1ced5 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/SimpleDirectory.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/SimpleDirectory.java @@ -5,13 +5,15 @@ import bjc.utils.funcdata.IMap; /** * Simple implementation of {@link Directory}. - * + * * Has a split namespace for data and children. - * + * * @author EVE * - * @param <K> The key type of the directory. - * @param <V> The value type of the directory. + * @param <K> + * The key type of the directory. + * @param <V> + * The value type of the directory. */ public class SimpleDirectory<K, V> implements Directory<K, V> { private IMap<K, Directory<K, V>> children; diff --git a/BJC-Utils2/src/main/java/bjc/utils/esodata/SingleTape.java b/BJC-Utils2/src/main/java/bjc/utils/esodata/SingleTape.java index a323ba4..22b869e 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/SingleTape.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/SingleTape.java @@ -19,8 +19,8 @@ import java.util.ArrayList; * @author bjculkin */ public class SingleTape<T> implements Tape<T> { - protected ArrayList<T> backing; - protected int pos; + protected ArrayList<T> backing; + protected int pos; protected boolean autoExtend; @@ -50,6 +50,7 @@ public class SingleTape<T> implements Tape<T> { * * @return The item the tape is on. */ + @Override public T item() { return backing.get(pos); } @@ -60,6 +61,7 @@ public class SingleTape<T> implements Tape<T> { * @param itm * The new value for the tape item. */ + @Override public void item(T itm) { backing.set(pos, itm); } @@ -69,6 +71,7 @@ public class SingleTape<T> implements Tape<T> { * * @return The current number of elements in the tape. */ + @Override public int size() { return backing.size(); } @@ -79,6 +82,7 @@ public class SingleTape<T> implements Tape<T> { * @param itm * The item to add. */ + @Override public void insertBefore(T itm) { backing.add(pos, itm); } @@ -86,31 +90,36 @@ public class SingleTape<T> implements Tape<T> { /** * Insert an element after the current item. */ + @Override public void insertAfter(T itm) { - if (pos == (backing.size() - 1)) + if(pos == backing.size() - 1) { backing.add(itm); - else + } else { backing.add(pos + 1, itm); + } } /** * Remove the current element. - * + * * Also moves the cursor back one step if possible to maintain relative * position. * * @return The removed item. */ + @Override public T remove() { T res = backing.remove(pos); - if (pos != 0) + if(pos != 0) { pos -= 1; + } return res; } /** * Move the cursor to the left-most position. */ + @Override public void first() { pos = 0; } @@ -118,6 +127,7 @@ public class SingleTape<T> implements Tape<T> { /** * Move the cursor the right-most position. */ + @Override public void last() { pos = backing.size() - 1; } @@ -129,6 +139,7 @@ public class SingleTape<T> implements Tape<T> { * * @return True if the cursor was moved left. */ + @Override public boolean left() { return left(1); } @@ -144,9 +155,9 @@ public class SingleTape<T> implements Tape<T> { * * @return True if the cursor was moved left. */ + @Override public boolean left(int amt) { - if ((pos - amt) < 0) - return false; + if(pos - amt < 0) return false; pos -= amt; return true; @@ -159,6 +170,7 @@ public class SingleTape<T> implements Tape<T> { * * @return Whether the cursor was moved right. */ + @Override public boolean right() { return right(1); } @@ -173,15 +185,15 @@ public class SingleTape<T> implements Tape<T> { * * @return Whether the cursor was moved right. */ + @Override public boolean right(int amt) { - if ((pos + amt) >= (backing.size() - 1)) { - if (autoExtend) { - while ((pos + amt) >= (backing.size() - 1)) { + if(pos + amt >= backing.size() - 1) { + if(autoExtend) { + while(pos + amt >= backing.size() - 1) { backing.add(null); } - } else { + } else return false; - } } pos += amt; diff --git a/BJC-Utils2/src/main/java/bjc/utils/esodata/SpaghettiStack.java b/BJC-Utils2/src/main/java/bjc/utils/esodata/SpaghettiStack.java index c650cdc..c5e338b 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/SpaghettiStack.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/SpaghettiStack.java @@ -31,18 +31,14 @@ class SpaghettiStack<T> extends Stack<T> { @Override public T pop() { - if (backing.empty()) { - return parent.pop(); - } + if(backing.empty()) return parent.pop(); return backing.pop(); } @Override public T top() { - if (backing.empty()) { - return parent.top(); - } + if(backing.empty()) return parent.top(); return backing.top(); } diff --git a/BJC-Utils2/src/main/java/bjc/utils/esodata/Stack.java b/BJC-Utils2/src/main/java/bjc/utils/esodata/Stack.java index 21a922d..5f7be6c 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/Stack.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/Stack.java @@ -65,7 +65,7 @@ public abstract class Stack<T> { * The number of items to drop. */ public void drop(int n) { - for (int i = 0; i < n; i++) { + for(int i = 0; i < n; i++) { pop(); } } @@ -109,12 +109,12 @@ public abstract class Stack<T> { public void multidup(int n, int m) { List<T> lst = new ArrayList<>(n); - for (int i = n; i > 0; i--) { + for(int i = n; i > 0; i--) { lst.set(i - 1, pop()); } - for (int i = 0; i < m; i++) { - for (T elm : lst) { + for(int i = 0; i < m; i++) { + for(T elm : lst) { push(elm); } } @@ -150,17 +150,17 @@ public abstract class Stack<T> { T elm = pop(); - for (int i = n; i > 0; i--) { + for(int i = n; i > 0; i--) { lst.set(i - 1, pop()); } - for (T nelm : lst) { + for(T nelm : lst) { push(nelm); } push(elm); - for (int i = 1; i < m; i++) { - for (T nelm : lst) { + for(int i = 1; i < m; i++) { + for(T nelm : lst) { push(nelm); } } @@ -273,13 +273,13 @@ public abstract class Stack<T> { public void dip(int n, Consumer<Stack<T>> cons) { List<T> elms = new ArrayList<>(n); - for (int i = n; i > 0; i--) { + for(int i = n; i > 0; i--) { elms.set(i - 1, pop()); } cons.accept(this); - for (T elm : elms) { + for(T elm : elms) { push(elm); } } @@ -319,12 +319,12 @@ public abstract class Stack<T> { public void multicleave(int n, List<Consumer<Stack<T>>> conses) { List<T> elms = new ArrayList<>(n); - for (int i = n; i > 0; i--) { + for(int i = n; i > 0; i--) { elms.set(i - 1, pop()); } - for (Consumer<Stack<T>> cons : conses) { - for (T elm : elms) { + for(Consumer<Stack<T>> cons : conses) { + for(T elm : elms) { push(elm); } @@ -353,10 +353,10 @@ public abstract class Stack<T> { public void multispread(int n, List<Consumer<Stack<T>>> conses) { List<List<T>> nelms = new ArrayList<>(conses.size()); - for (int i = conses.size(); i > 0; i--) { + for(int i = conses.size(); i > 0; i--) { List<T> elms = new ArrayList<>(n); - for (int j = n; j > 0; j--) { + for(int j = n; j > 0; j--) { elms.set(j, pop()); } @@ -364,8 +364,8 @@ public abstract class Stack<T> { } int i = 0; - for (List<T> elms : nelms) { - for (T elm : elms) { + for(List<T> elms : nelms) { + for(T elm : elms) { push(elm); } @@ -396,7 +396,7 @@ public abstract class Stack<T> { public void multiapply(int n, int m, Consumer<Stack<T>> cons) { List<Consumer<Stack<T>>> conses = new ArrayList<>(m); - for (int i = 0; i < m; i++) { + for(int i = 0; i < m; i++) { conses.add(cons); } diff --git a/BJC-Utils2/src/main/java/bjc/utils/esodata/Tape.java b/BJC-Utils2/src/main/java/bjc/utils/esodata/Tape.java index 3d4e0b1..3b3a9a7 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/Tape.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/Tape.java @@ -49,7 +49,7 @@ public interface Tape<T> { /** * Remove the current element. - * + * * Also moves the cursor back one step if possible to maintain relative * position. * diff --git a/BJC-Utils2/src/main/java/bjc/utils/esodata/TapeChanger.java b/BJC-Utils2/src/main/java/bjc/utils/esodata/TapeChanger.java index 4030960..fa3e61c 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/TapeChanger.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/TapeChanger.java @@ -5,7 +5,7 @@ package bjc.utils.esodata; * * It has a current tape that you can do operations to, but also operations to * add/remove other tapes. - * + * * If there is no tape currently loaded into the changer, all the methods will * either return null/false. * @@ -13,8 +13,8 @@ package bjc.utils.esodata; * The element type of the tapes. */ public class TapeChanger<T> implements Tape<T> { - private Tape<Tape<T>> tapes; - private Tape<T> currentTape; + private Tape<Tape<T>> tapes; + private Tape<T> currentTape; /** * Create a new empty tape changer. @@ -37,7 +37,7 @@ public class TapeChanger<T> implements Tape<T> { tapes.insertBefore(current); - for (Tape<T> tp : others) { + for(Tape<T> tp : others) { tapes.insertAfter(tp); tapes.right(); } @@ -51,9 +51,9 @@ public class TapeChanger<T> implements Tape<T> { * * @return The item the tape is on. */ + @Override public T item() { - if (currentTape == null) - return null; + if(currentTape == null) return null; return currentTape.item(); } @@ -64,9 +64,9 @@ public class TapeChanger<T> implements Tape<T> { * @param itm * The new value for the tape item. */ + @Override public void item(T itm) { - if (currentTape == null) - return; + if(currentTape == null) return; currentTape.item(itm); } @@ -76,9 +76,9 @@ public class TapeChanger<T> implements Tape<T> { * * @return The current number of elements in the tape. */ + @Override public int size() { - if (currentTape == null) - return 0; + if(currentTape == null) return 0; return currentTape.size(); } @@ -89,9 +89,9 @@ public class TapeChanger<T> implements Tape<T> { * @param itm * The item to add. */ + @Override public void insertBefore(T itm) { - if (currentTape == null) - return; + if(currentTape == null) return; currentTape.insertBefore(itm); } @@ -99,24 +99,24 @@ public class TapeChanger<T> implements Tape<T> { /** * Insert an element after the current item. */ + @Override public void insertAfter(T itm) { - if (currentTape == null) - return; + if(currentTape == null) return; currentTape.insertAfter(itm); } /** * Remove the current element. - * + * * Also moves the cursor back one step if possible to maintain relative * position, and removes the corresponding item from the non-active side * * @return The removed item from the active side. */ + @Override public T remove() { - if (currentTape == null) - return null; + if(currentTape == null) return null; return currentTape.remove(); } @@ -124,9 +124,9 @@ public class TapeChanger<T> implements Tape<T> { /** * Move the cursor to the left-most position. */ + @Override public void first() { - if (currentTape == null) - return; + if(currentTape == null) return; currentTape.first(); } @@ -134,9 +134,9 @@ public class TapeChanger<T> implements Tape<T> { /** * Move the cursor the right-most position. */ + @Override public void last() { - if (currentTape == null) - return; + if(currentTape == null) return; currentTape.last(); } @@ -148,6 +148,7 @@ public class TapeChanger<T> implements Tape<T> { * * @return True if the cursor was moved left. */ + @Override public boolean left() { return left(1); } @@ -163,9 +164,9 @@ public class TapeChanger<T> implements Tape<T> { * * @return True if the cursor was moved left. */ + @Override public boolean left(int amt) { - if (currentTape == null) - return false; + if(currentTape == null) return false; return currentTape.left(amt); } @@ -177,6 +178,7 @@ public class TapeChanger<T> implements Tape<T> { * * @return Whether the cursor was moved right. */ + @Override public boolean right() { return right(1); } @@ -191,9 +193,9 @@ public class TapeChanger<T> implements Tape<T> { * * @return Whether the cursor was moved right. */ + @Override public boolean right(int amt) { - if (currentTape == null) - return false; + if(currentTape == null) return false; return currentTape.right(amt); } @@ -207,18 +209,16 @@ public class TapeChanger<T> implements Tape<T> { * If the current tape is not double-sided, does nothing. */ public void flip() { - if (currentTape == null) - return; + if(currentTape == null) return; - if (currentTape.isDoubleSided()) { + if(currentTape.isDoubleSided()) { ((DoubleTape<T>) currentTape).flip(); } } @Override public boolean isDoubleSided() { - if (currentTape == null) - return false; + if(currentTape == null) return false; return currentTape.isDoubleSided(); } @@ -243,8 +243,9 @@ public class TapeChanger<T> implements Tape<T> { public boolean nextTape() { boolean succ = tapes.right(); - if (succ) + if(succ) { currentTape = tapes.item(); + } return succ; } @@ -260,8 +261,9 @@ public class TapeChanger<T> implements Tape<T> { public boolean prevTape() { boolean succ = tapes.left(); - if (succ) + if(succ) { currentTape = tapes.item(); + } return succ; } @@ -293,8 +295,7 @@ public class TapeChanger<T> implements Tape<T> { * @return The removed tape. */ public Tape<T> removeTape() { - if (currentTape == null) - return null; + if(currentTape == null) return null; Tape<T> tp = tapes.remove(); currentTape = tapes.item(); diff --git a/BJC-Utils2/src/main/java/bjc/utils/esodata/TapeLibrary.java b/BJC-Utils2/src/main/java/bjc/utils/esodata/TapeLibrary.java index 3a49175..732f579 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/TapeLibrary.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/TapeLibrary.java @@ -8,7 +8,7 @@ import java.util.Map; * * It has a current tape that you can do operations to, but also operations to * add/remove other tapes. - * + * * If there is no tape currently loaded into the changer, all the methods will * either return null/false. * @@ -16,8 +16,8 @@ import java.util.Map; * The element type of the tapes. */ public class TapeLibrary<T> implements Tape<T> { - private Map<String, Tape<T>> tapes; - private Tape<T> currentTape; + private Map<String, Tape<T>> tapes; + private Tape<T> currentTape; /** * Create a new empty tape library. @@ -31,9 +31,9 @@ public class TapeLibrary<T> implements Tape<T> { * * @return The item the tape is on. */ + @Override public T item() { - if (currentTape == null) - return null; + if(currentTape == null) return null; return currentTape.item(); } @@ -44,9 +44,9 @@ public class TapeLibrary<T> implements Tape<T> { * @param itm * The new value for the tape item. */ + @Override public void item(T itm) { - if (currentTape == null) - return; + if(currentTape == null) return; currentTape.item(itm); } @@ -56,9 +56,9 @@ public class TapeLibrary<T> implements Tape<T> { * * @return The current number of elements in the tape. */ + @Override public int size() { - if (currentTape == null) - return 0; + if(currentTape == null) return 0; return currentTape.size(); } @@ -69,9 +69,9 @@ public class TapeLibrary<T> implements Tape<T> { * @param itm * The item to add. */ + @Override public void insertBefore(T itm) { - if (currentTape == null) - return; + if(currentTape == null) return; currentTape.insertBefore(itm); } @@ -79,24 +79,24 @@ public class TapeLibrary<T> implements Tape<T> { /** * Insert an element after the current item. */ + @Override public void insertAfter(T itm) { - if (currentTape == null) - return; + if(currentTape == null) return; currentTape.insertAfter(itm); } /** * Remove the current element. - * + * * Also moves the cursor back one step if possible to maintain relative * position, and removes the corresponding item from the non-active side * * @return The removed item from the active side. */ + @Override public T remove() { - if (currentTape == null) - return null; + if(currentTape == null) return null; return currentTape.remove(); } @@ -104,9 +104,9 @@ public class TapeLibrary<T> implements Tape<T> { /** * Move the cursor to the left-most position. */ + @Override public void first() { - if (currentTape == null) - return; + if(currentTape == null) return; currentTape.first(); } @@ -114,9 +114,9 @@ public class TapeLibrary<T> implements Tape<T> { /** * Move the cursor the right-most position. */ + @Override public void last() { - if (currentTape == null) - return; + if(currentTape == null) return; currentTape.last(); } @@ -128,6 +128,7 @@ public class TapeLibrary<T> implements Tape<T> { * * @return True if the cursor was moved left. */ + @Override public boolean left() { return left(1); } @@ -143,9 +144,9 @@ public class TapeLibrary<T> implements Tape<T> { * * @return True if the cursor was moved left. */ + @Override public boolean left(int amt) { - if (currentTape == null) - return false; + if(currentTape == null) return false; return currentTape.left(amt); } @@ -157,6 +158,7 @@ public class TapeLibrary<T> implements Tape<T> { * * @return Whether the cursor was moved right. */ + @Override public boolean right() { return right(1); } @@ -171,9 +173,9 @@ public class TapeLibrary<T> implements Tape<T> { * * @return Whether the cursor was moved right. */ + @Override public boolean right(int amt) { - if (currentTape == null) - return false; + if(currentTape == null) return false; return currentTape.right(amt); } @@ -187,18 +189,16 @@ public class TapeLibrary<T> implements Tape<T> { * If the current tape is not double-sided, does nothing. */ public void flip() { - if (currentTape == null) - return; + if(currentTape == null) return; - if (currentTape.isDoubleSided()) { + if(currentTape.isDoubleSided()) { ((DoubleTape<T>) currentTape).flip(); } } @Override public boolean isDoubleSided() { - if (currentTape == null) - return false; + if(currentTape == null) return false; return currentTape.isDoubleSided(); } @@ -224,7 +224,7 @@ public class TapeLibrary<T> implements Tape<T> { * @return Whether or not the next tape was loaded. */ public boolean switchTape(String label) { - if (tapes.containsKey(label)) { + if(tapes.containsKey(label)) { currentTape = tapes.get(label); return true; } diff --git a/BJC-Utils2/src/main/java/bjc/utils/esodata/UnifiedDirectory.java b/BJC-Utils2/src/main/java/bjc/utils/esodata/UnifiedDirectory.java index 187474c..d4c5081 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/UnifiedDirectory.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/UnifiedDirectory.java @@ -5,9 +5,9 @@ import bjc.utils.funcdata.IMap; /** * Simple implementation of {@link Directory}. - * + * * Has a unified namespace for data and children. - * + * * @author EVE * * @param <K> @@ -40,9 +40,8 @@ public class UnifiedDirectory<K, V> implements Directory<K, V> { @Override public Directory<K, V> putSubdirectory(K key, Directory<K, V> val) { - if(data.containsKey(key)) { + if(data.containsKey(key)) throw new IllegalArgumentException("Key " + key + " is already used for data."); - } return children.put(key, val); } @@ -59,10 +58,9 @@ public class UnifiedDirectory<K, V> implements Directory<K, V> { @Override public V putKey(K key, V val) { - if(children.containsKey(key)) { + if(children.containsKey(key)) throw new IllegalArgumentException("Key " + key + " is already used for sub-directories."); - } - + return data.put(key, val); } }
\ No newline at end of file |
