import java.util.HashMap; public class Switch { HashMap wtf = new HashMap (); Node tail; Function defawlt; public Switch () { } public Switch (Function def) { defawlt = def; } public Switch qase (T value, Function f) { Node node = new Node (f); wtf.put (value, node); if (tail != null) { tail.next = node; } tail = node; return this; } public void zwitch (T value) { Node node = wtf.get (value); while (node != null) { if (node.func.exec ()) { return; } node = node.next; } if (defawlt != null) { defawlt.exec (); } } static class Node { Function func; Node next; Node (Function f) { func = f; } } public static interface Function { public boolean exec (); } public static void main (String[] args) { String s = args [0]; switch (s) { case "bar": System.out.println ("bar"); break; case "baz": System.out.println ("baz"); case "blah": System.out.println ("blah"); break; default: System.out.println ("no"); break; } new Switch (new Function () { public boolean exec () { System.out.println ("no"); return true; } }).qase ("bar", new Function () { public boolean exec () { System.out.println ("bar"); return true; } }).qase ("baz", new Function () { public boolean exec () { System.out.println ("baz"); return false; } }).qase ("blah", new Function () { public boolean exec () { System.out.println ("blah"); return true; } }).zwitch (s); } }