@@ -0,0 +1,1788 @@
+package com.yutax77.java8_ans.chap3;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0Aimport java.util.function.UnaryOperator;%0A%0Aimport javafx.scene.image.Image;%0Aimport javafx.scene.image.WritableImage;%0Aimport javafx.scene.paint.Color;%0A%0Apublic class Ans12 %7B%0A    public static class LatentImage %7B%0A%09private Image in;%0A%09private List%3CColorTransformer%3E pendingOperations;%0A%09%0A%09protected LatentImage(Image image) %7B%0A%09    in = image;%0A%09    pendingOperations = new ArrayList%3C%3E();%0A%09%7D%0A%09%0A%09public LatentImage transform(UnaryOperator%3CColor%3E f) %7B %0A%09    pendingOperations.add(new ColorTransformer() %7B%0A                @Override%0A                public Color apply(int x, int y, Color colorAtXY) %7B%0A                    return f.apply(colorAtXY);%0A                %7D%0A            %7D);%0A%09    return this;%0A%09%7D%0A%09%0A        public LatentImage transform(ColorTransformer transformer) %7B %0A%09    pendingOperations.add(transformer);%0A%09    return this;%0A%09%7D%0A        %0A        public Image toImage() %7B%0A            int width = (int) in.getWidth();%0A            int height = (int) in.getHeight();%0A            WritableImage out = new WritableImage(width, height);%0A            for (int x = 0; x %3C width; x++) %7B%0A                for (int y = 0; y %3C height; y++) %7B%0A                    Color c = in.getPixelReader().getColor(x, y);%0A                    for (ColorTransformer transformer : pendingOperations) %7B%0A                        c = transformer.apply(x, y, c);%0A                    %7D%0A                    out.getPixelWriter().setColor(x, y, c);%0A                %7D%0A            %7D%0A            return out;%0A        %7D%0A        %0A%09public static LatentImage from(Image image) %7B%0A%09    return new LatentImage(image);%0A%09%7D%0A    %7D%0A    %0A    @FunctionalInterface%0A    public interface ColorTransformer %7B%0A        Color apply(int x, int y, Color colorAtXY);%0A    %7D%0A%7D%0A

Answer chap.3-12