//package edu.wlu.cs.levy.CG; public interface Editor { public T edit(T current) throws KeyDuplicateException; public static abstract class BaseEditor implements Editor { final T val; public BaseEditor(T val) { this.val = val; } public abstract T edit(T current) throws KeyDuplicateException; } public static class Inserter extends BaseEditor { public Inserter(T val) { super(val); } public T edit(T current) throws KeyDuplicateException { if (current == null) { return this.val; } throw new KeyDuplicateException(); } } public static class OptionalInserter extends BaseEditor { public OptionalInserter(T val) { super(val); } public T edit(T current) { return (current == null) ? this.val : current; } } public static class Replacer extends BaseEditor { public Replacer(T val) { super(val); } public T edit(T current) { return this.val; } } }