homedukeAlgorithmen & Datenstrukturen mit Java: ds.util.Function Prof. Dr. Uwe Schmidt FH Wedel

ds.util.Function

   1package ds.util;
   2
   3abstract public
   4    class Function<X,Y> {
   5
   6    abstract public Y apply(X x);
   7
   8    // create identity functions
   9
  10    public static <X> Function<X,X> id() {
  11        return
  12            new Function<X,X>() {
  13            public X apply(X x) {
  14                return
  15                    x;
  16            }
  17        };
  18    }
  19
  20    // create const functions
  21
  22    public static <X,Y> Function<X,Y> constF(Y c) {
  23        return
  24            new Const<X,Y>(c);
  25    }
  26
  27    private static
  28        class Const<X,Y> extends Function<X,Y> {
  29        private final Y c;
  30
  31        public Const(Y c) { this.c = c}
  32
  33        public Y apply(X x) {
  34            return
  35                c;
  36        }
  37    }
  38}

Die Quelle: Function.java


Letzte Änderung: 15.10.2015
© Prof. Dr. Uwe Schmidt
Prof. Dr. Uwe Schmidt FH Wedel