@@ -0,0 +1,2758 @@
+package nl.meg.cr.internal;%0A%0Aimport javax.jcr.*;%0Aimport java.util.HashMap;%0Aimport java.util.List;%0Aimport java.util.Map;%0Aimport java.util.Optional;%0Aimport java.util.function.Function;%0Aimport java.util.stream.Stream;%0A%0Aimport static java.util.stream.Collectors.toList;%0A%0Afinal class JcrSupport %7B%0A%0A    static final class V %7B%0A%0A        private static final Map%3CClass%3C?%3E, Function%3CValue, ?%3E%3E VALUE_MAP;%0A%0A        static %7B%0A            VALUE_MAP = new HashMap%3C%3E();%0A            VALUE_MAP.put(String.class, JcrSupport.wrap(Value::getString));%0A        %7D%0A%0A        @SuppressWarnings(%22unchecked%22)%0A        public static %3CT%3E Function%3CValue, T%3E get(Class%3CT%3E type) %7B%0A            return (Function%3CValue, T%3E) VALUE_MAP.get(type);%0A        %7D%0A%0A    %7D%0A%0A    static final class N %7B%0A%0A        static Function%3CNode, Stream%3CNode%3E%3E NODES =%0A                wrap((Node n) -%3E n.getNodes()).andThen(RangeIteratorSupport::stream);%0A%0A        static %3CT%3E Function%3CNode, Optional%3CT%3E%3E single(String propertyName, Function%3CValue, T%3E valueFn) %7B%0A            return property(propertyName)%0A                    .andThen(p -%3E p.flatMap(JcrSupport.P.single(valueFn)));%0A        %7D%0A%0A        static %3CT%3E Function%3CNode, Optional%3CList%3CT%3E%3E%3E multi(String propertyName, Function%3CValue, T%3E valueFn) %7B%0A            return property(propertyName)%0A                    .andThen(p -%3E p.flatMap(JcrSupport.P.multi(valueFn)));%0A        %7D%0A%0A        private static Function%3CNode, Optional%3CProperty%3E%3E property(String propertyName) %7B%0A            return wrapOptional((Node node) -%3E node.getProperty(propertyName));%0A        %7D%0A    %7D%0A%0A    static final class P %7B%0A        private static %3CT%3E Function%3CProperty, Optional%3CT%3E%3E single(Function%3CValue, T%3E valueFn) %7B%0A            return wrapOptional(Property::getValue)%0A                    .andThen(v -%3E v.map(valueFn));%0A        %7D%0A%0A        private static %3CT%3E Function%3CProperty, Optional%3CList%3CT%3E%3E%3E multi(Function%3CValue, T%3E valueFn) %7B%0A            return property -%3E wrapOptional(Property::getValues)%0A                    .apply(property)%0A                    .map(Stream::of)%0A                    .map(valueStream -%3E valueStream.map(valueFn).collect(toList()));%0A        %7D%0A    %7D%0A%0A    private interface JcrFn%3CT, R%3E %7B%0A        R apply(T t) throws RepositoryException;%0A    %7D%0A%0A    private static %3CT, R%3E Function%3CT, R%3E wrap(JcrFn%3CT, R%3E jcrFn) %7B%0A        return t -%3E %7B%0A            try %7B%0A                return jcrFn.apply(t);%0A            %7D catch (ItemNotFoundException %7C PathNotFoundException e) %7B%0A                return null;%0A            %7D catch (RepositoryException e) %7B%0A                throw new nl.meg.cr.RepositoryException(e);%0A            %7D%0A        %7D;%0A    %7D%0A%0A    private static %3CT, R%3E Function%3CT, Optional%3CR%3E%3E wrapOptional(JcrFn%3CT, R%3E jcrFn) %7B%0A        return wrap(jcrFn).andThen(Optional::ofNullable);%0A    %7D%0A%7D%0A

Add JcrSupport class