/** * Copyright (c): Uwe Schmidt, FH Wedel * * You may study, modify and distribute this source code * FOR NON-COMMERCIAL PURPOSES ONLY. * This copyright message has to remain unchanged. * * Note that this document is provided 'as is', * WITHOUT WARRANTY of any kind either expressed or implied. */ package ds.util; abstract public class Function { abstract public Y apply(X x); // create identity functions public static Function id() { return new Function() { public X apply(X x) { return x; } }; } // create const functions public static Function constF(Y c) { return new Const(c); } private static class Const extends Function { private final Y c; public Const(Y c) { this.c = c; } public Y apply(X x) { return c; } } }