public Tree(String key, String value, TreeDisplay display) { this.left = null; this.right = null; this.key = key; this.value = value; this.display = display; display.displayMessage("[" + key + "] Created with value " + value, java.awt.Color.blue); }
public ObjectWrapper search(String key) { display.displayMessage("[" + this.key + "] Searching for " + key); if (key == null) { return new ObjectWrapper("null"); } ; int res = key.compareTo(this.key); if (res == 0) { display.displayMessage("[" + this.key + "] Found " + key); return new ObjectWrapper(value); } if (res < 0) { return (left != null) ? left.search(key) : new ObjectWrapper("null"); } else { return (right != null) ? right.search(key) : new ObjectWrapper("null"); } }
public void insert(String key, String value, boolean AC) { int res = key.compareTo(this.key); if (res == 0) { // Same key --> Modify the current value display.displayMessage("[" + key + "] Replacing " + this.value + " with " + value); this.value = value; } else if (res < 0) { display.displayMessage("[" + key + "] trying left"); // key < this.key --> store left if (left != null) { left.insert(key, value, AC); } else { display.displayMessage("[" + key + "] Creating left"); // Create the new node try { left = org.objectweb.proactive.api.PAActiveObject.newActive( this.getClass(), new Object[] {key, value, display}); } catch (Exception e) { e.printStackTrace(); } // Enabled Automatic Continuations if (AC) { try { org.objectweb.proactive.api.PAActiveObject.enableAC( org.objectweb.proactive.api.PAActiveObject.getStubOnThis()); } catch (java.io.IOException e) { display.displayMessage("Automatic Continuations error!!!", java.awt.Color.red); } } } } else { display.displayMessage("[" + key + "] trying right"); if (right != null) { right.insert(key, value, AC); } else { display.displayMessage("[" + key + "] Creating right"); try { right = org.objectweb.proactive.api.PAActiveObject.newActive( this.getClass(), new Object[] {key, value, display}); } catch (Exception e) { e.printStackTrace(); } // Enabled Automatic Continuations if (AC) { try { org.objectweb.proactive.api.PAActiveObject.enableAC( org.objectweb.proactive.api.PAActiveObject.getStubOnThis()); } catch (java.io.IOException e) { display.displayMessage("Automatic Continuations error!!!", java.awt.Color.red); } } } } }
public void disableAC() { try { org.objectweb.proactive.api.PAActiveObject.disableAC( org.objectweb.proactive.api.PAActiveObject.getStubOnThis()); if (right != null) { right.disableAC(); } if (left != null) { left.disableAC(); } } catch (java.io.IOException e) { display.displayMessage("Automatic Continuations error!!!", java.awt.Color.red); } }