From 85b14ce6e1dc7ddaa0669ff881a17c5b0e17b9f4 Mon Sep 17 00:00:00 2001
From: Gaetan Boismal <gaetan.boismal@forgerock.com>
Date: Tue, 14 Oct 2014 14:10:51 +0000
Subject: [PATCH] OPENDJ-1550: Replace SDK Function with Function from forgerock-util * org.forgerock.opendj.ldap.Function ** Removed * All impacted classes are now using org.forgerock.util.promise.Function

---
 opendj-core/src/main/java/org/forgerock/opendj/ldap/requests/UnmodifiableModifyRequestImpl.java      |   17 
 opendj-core/src/main/java/com/forgerock/opendj/util/Iterables.java                                   |   48 --
 opendj-core/src/main/java/org/forgerock/opendj/ldap/Entries.java                                     |   19 
 opendj-core/src/main/java/org/forgerock/opendj/ldap/requests/UnmodifiableAddRequestImpl.java         |   16 
 opendj-core/clirr-ignored-api-changes.xml                                                            |   44 ++
 opendj-core/src/main/java/org/forgerock/opendj/ldap/responses/UnmodifiableSearchResultEntryImpl.java |   13 
 opendj-core/src/main/java/org/forgerock/opendj/ldap/Functions.java                                   |  281 ++++----------
 opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/ReferenceAttributeMapper.java          |    7 
 opendj-core/src/main/java/org/forgerock/opendj/ldap/AttributeParser.java                             |   21 
 opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Utils.java                             |  115 ++---
 opendj-core/src/main/java/org/forgerock/opendj/ldap/responses/AbstractUnmodifiableResponseImpl.java  |   23 
 opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/AbstractLDAPAttributeMapper.java       |   10 
 opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/ObjectAttributeMapper.java             |   32 
 /dev/null                                                                                            |   61 ---
 opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/SimpleAttributeMapper.java             |   42 -
 opendj-core/src/main/java/com/forgerock/opendj/util/Collections2.java                                |  215 ++--------
 opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/LDAPCollectionResourceProvider.java    |   11 
 opendj-core/src/main/java/org/forgerock/opendj/ldap/requests/AbstractUnmodifiableRequest.java        |   23 
 opendj-core/src/main/java/com/forgerock/opendj/util/Iterators.java                                   |  128 +-----
 opendj-core/src/main/java/org/forgerock/opendj/ldap/RootDSE.java                                     |    7 
 20 files changed, 390 insertions(+), 743 deletions(-)

diff --git a/opendj-core/clirr-ignored-api-changes.xml b/opendj-core/clirr-ignored-api-changes.xml
index a45b6c7..f074429 100644
--- a/opendj-core/clirr-ignored-api-changes.xml
+++ b/opendj-core/clirr-ignored-api-changes.xml
@@ -339,4 +339,48 @@
     <differenceType>8001</differenceType>
     <justification>OPENDJ-1536 Rename FutureResult and ErrorResultException classes hierarchy in the SDK to enhance code consistency</justification>
   </difference>
+  <difference>
+    <className>org/forgerock/opendj/ldap/Functions</className>
+    <differenceType>7002</differenceType>
+    <method>*composeFirstP(*)</method>
+    <justification>OPENDJ-1550 Replace SDK Function with Function from forgerock-util</justification>
+  </difference>
+  <difference>
+    <className>org/forgerock/opendj/ldap/Functions</className>
+    <differenceType>7002</differenceType>
+    <method>*composeSecondP(*)</method>
+    <justification>OPENDJ-1550 Replace SDK Function with Function from forgerock-util</justification>
+  </difference>
+  <difference>
+    <className>org/forgerock/opendj/ldap/Functions</className>
+    <differenceType>7002</differenceType>
+    <method>*fixedFunction(*)</method>
+    <justification>OPENDJ-1550 Replace SDK Function with Function from forgerock-util</justification>
+  </difference>
+  <difference>
+    <className>org/forgerock/opendj/ldap/Function</className>
+    <differenceType>8001</differenceType>
+    <justification>OPENDJ-1550 Replace SDK Function with Function from forgerock-util</justification>
+  </difference>
+  <difference>
+    <className>org/forgerock/opendj/ldap/AttributeParser</className>
+    <differenceType>7005</differenceType>
+    <method>*as*(org.forgerock.opendj.ldap.Function*)</method>
+    <to>*as*(org.forgerock.util.promise.Function*)</to>
+    <justification>OPENDJ-1550 Replace SDK Function with Function from forgerock-util</justification>
+  </difference>
+  <difference>
+    <className>org/forgerock/opendj/ldap/Functions</className>
+    <differenceType>7005</differenceType>
+    <method>*compose(org.forgerock.opendj.ldap.Function, org.forgerock.opendj.ldap.Function)</method>
+    <to>*compose(org.forgerock.util.promise.Function, org.forgerock.util.promise.Function)</to>
+    <justification>OPENDJ-1550 Replace SDK Function with Function from forgerock-util</justification>
+  </difference>
+  <difference>
+    <className>org/forgerock/opendj/ldap/Functions</className>
+    <differenceType>7006</differenceType>
+    <method>*</method>
+    <to>org.forgerock.util.promise.Function</to>
+    <justification>OPENDJ-1550 Replace SDK Function with Function from forgerock-util</justification>
+  </difference>
 </differences>
diff --git a/opendj-core/src/main/java/com/forgerock/opendj/util/Collections2.java b/opendj-core/src/main/java/com/forgerock/opendj/util/Collections2.java
index b6c8899..fe3086a 100644
--- a/opendj-core/src/main/java/com/forgerock/opendj/util/Collections2.java
+++ b/opendj-core/src/main/java/com/forgerock/opendj/util/Collections2.java
@@ -22,8 +22,8 @@
  *
  *
  *      Copyright 2009-2010 Sun Microsystems, Inc.
+ *      Portions Copyright 2014 ForgeRock AS.
  */
-
 package com.forgerock.opendj.util;
 
 import java.util.AbstractCollection;
@@ -32,87 +32,69 @@
 import java.util.List;
 import java.util.ListIterator;
 
-import org.forgerock.opendj.ldap.Function;
+import org.forgerock.util.promise.Function;
+import org.forgerock.util.promise.NeverThrowsException;
 
 /**
  * Additional {@code Collection} based utility methods.
  */
 public final class Collections2 {
-    private static class TransformedCollection<M, N, P, C extends Collection<M>> extends
+    private static class TransformedCollection<M, N, C extends Collection<M>> extends
             AbstractCollection<N> implements Collection<N> {
 
         protected final C collection;
 
-        protected final Function<? super M, ? extends N, P> funcMtoN;
+        protected final Function<? super M, ? extends N, NeverThrowsException> funcMtoN;
 
-        protected final Function<? super N, ? extends M, P> funcNtoM;
-
-        protected final P p;
+        protected final Function<? super N, ? extends M, NeverThrowsException> funcNtoM;
 
         protected TransformedCollection(final C collection,
-                final Function<? super M, ? extends N, P> funcMtoN,
-                final Function<? super N, ? extends M, P> funcNtoM, final P p) {
+                final Function<? super M, ? extends N, NeverThrowsException> funcMtoN,
+                final Function<? super N, ? extends M, NeverThrowsException> funcNtoM) {
             this.collection = collection;
             this.funcMtoN = funcMtoN;
             this.funcNtoM = funcNtoM;
-            this.p = p;
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         @Override
         public boolean add(final N e) {
-            return collection.add(funcNtoM.apply(e, p));
+            return collection.add(funcNtoM.apply(e));
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         @Override
         public void clear() {
             collection.clear();
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         @Override
         @SuppressWarnings("unchecked")
         public boolean contains(final Object o) {
-            final N tmp = (N) o;
-            return collection.contains(funcNtoM.apply(tmp, p));
+            return collection.contains(funcNtoM.apply((N) o));
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         @Override
         public boolean isEmpty() {
             return collection.isEmpty();
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         @Override
         public Iterator<N> iterator() {
-            return Iterators.transformedIterator(collection.iterator(), funcMtoN, p);
+            return Iterators.transformedIterator(collection.iterator(), funcMtoN);
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         @Override
         @SuppressWarnings("unchecked")
         public boolean remove(final Object o) {
-            final N tmp = (N) o;
-            return collection.remove(funcNtoM.apply(tmp, p));
+            return collection.remove(funcNtoM.apply((N) o));
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         @Override
         public int size() {
             return collection.size();
@@ -120,26 +102,22 @@
 
     }
 
-    private static final class TransformedList<M, N, P> extends
-            TransformedCollection<M, N, P, List<M>> implements List<N> {
+    private static final class TransformedList<M, N> extends
+            TransformedCollection<M, N, List<M>> implements List<N> {
 
         private TransformedList(final List<M> list,
-                final Function<? super M, ? extends N, P> funcMtoN,
-                final Function<? super N, ? extends M, P> funcNtoM, final P p) {
-            super(list, funcMtoN, funcNtoM, p);
+                final Function<? super M, ? extends N, NeverThrowsException> funcMtoN,
+                final Function<? super N, ? extends M, NeverThrowsException> funcNtoM) {
+            super(list, funcMtoN, funcNtoM);
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         @Override
         public void add(final int index, final N element) {
-            collection.add(index, funcNtoM.apply(element, p));
+            collection.add(index, funcNtoM.apply(element));
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         @Override
         public boolean addAll(final int index, final Collection<? extends N> c) {
             // We cannot transform c here due to type-safety.
@@ -150,45 +128,33 @@
             return result;
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         @Override
         public N get(final int index) {
-            return funcMtoN.apply(collection.get(index), p);
+            return funcMtoN.apply(collection.get(index));
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         @Override
         @SuppressWarnings("unchecked")
         public int indexOf(final Object o) {
-            final N tmp = (N) o;
-            return collection.indexOf(funcNtoM.apply(tmp, p));
+            return collection.indexOf(funcNtoM.apply((N) o));
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         @Override
         @SuppressWarnings("unchecked")
         public int lastIndexOf(final Object o) {
-            final N tmp = (N) o;
-            return collection.lastIndexOf(funcNtoM.apply(tmp, p));
+            return collection.lastIndexOf(funcNtoM.apply((N) o));
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         @Override
         public ListIterator<N> listIterator() {
             return listIterator(0);
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         @Override
         public ListIterator<N> listIterator(final int index) {
             final ListIterator<M> iterator = collection.listIterator(index);
@@ -196,7 +162,7 @@
 
                 @Override
                 public void add(final N e) {
-                    iterator.add(funcNtoM.apply(e, p));
+                    iterator.add(funcNtoM.apply(e));
                 }
 
                 @Override
@@ -211,7 +177,7 @@
 
                 @Override
                 public N next() {
-                    return funcMtoN.apply(iterator.next(), p);
+                    return funcMtoN.apply(iterator.next());
                 }
 
                 @Override
@@ -221,7 +187,7 @@
 
                 @Override
                 public N previous() {
-                    return funcMtoN.apply(iterator.previous(), p);
+                    return funcMtoN.apply(iterator.previous());
                 }
 
                 @Override
@@ -236,36 +202,30 @@
 
                 @Override
                 public void set(final N e) {
-                    iterator.set(funcNtoM.apply(e, p));
+                    iterator.set(funcNtoM.apply(e));
                 }
 
             };
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         @Override
         public N remove(final int index) {
-            return funcMtoN.apply(collection.remove(index), p);
+            return funcMtoN.apply(collection.remove(index));
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         @Override
         public N set(final int index, final N element) {
-            final M result = collection.set(index, funcNtoM.apply(element, p));
-            return funcMtoN.apply(result, p);
+            final M result = collection.set(index, funcNtoM.apply(element));
+            return funcMtoN.apply(result);
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         @Override
         public List<N> subList(final int fromIndex, final int toIndex) {
             final List<M> subList = collection.subList(fromIndex, toIndex);
-            return new TransformedList<M, N, P>(subList, funcMtoN, funcNtoM, p);
+            return new TransformedList<M, N>(subList, funcMtoN, funcNtoM);
         }
 
     }
@@ -279,40 +239,6 @@
      *            The type of elements contained in {@code collection}.
      * @param <N>
      *            The type of elements contained in the returned collection.
-     * @param <P>
-     *            The type of the additional parameter to the function's
-     *            {@code apply} method. Use {@link java.lang.Void} for functions
-     *            that do not need an additional parameter.
-     * @param collection
-     *            The collection to be transformed.
-     * @param funcMtoN
-     *            A function which maps values of type {@code M} to values of
-     *            type {@code N}. This function will be used when retrieving
-     *            values from {@code collection}.
-     * @param funcNtoM
-     *            A function which maps values of type {@code N} to values of
-     *            type {@code M}. This function will be used when performing
-     *            queries and adding values to {@code collection} .
-     * @param p
-     *            A predicate specified parameter.
-     * @return A view of {@code collection} whose values have been mapped to
-     *         elements of type {@code N} using {@code funcMtoN}.
-     */
-    public static <M, N, P> Collection<N> transformedCollection(final Collection<M> collection,
-            final Function<? super M, ? extends N, P> funcMtoN,
-            final Function<? super N, ? extends M, P> funcNtoM, final P p) {
-        return new TransformedCollection<M, N, P, Collection<M>>(collection, funcMtoN, funcNtoM, p);
-    }
-
-    /**
-     * Returns a view of {@code collection} whose values have been mapped to
-     * elements of type {@code N} using {@code funcMtoN}. The returned
-     * collection supports all operations.
-     *
-     * @param <M>
-     *            The type of elements contained in {@code collection}.
-     * @param <N>
-     *            The type of elements contained in the returned collection.
      * @param collection
      *            The collection to be transformed.
      * @param funcMtoN
@@ -327,44 +253,9 @@
      *         elements of type {@code N} using {@code funcMtoN}.
      */
     public static <M, N> Collection<N> transformedCollection(final Collection<M> collection,
-            final Function<? super M, ? extends N, Void> funcMtoN,
-            final Function<? super N, ? extends M, Void> funcNtoM) {
-        return new TransformedCollection<M, N, Void, Collection<M>>(collection, funcMtoN, funcNtoM,
-                null);
-    }
-
-    /**
-     * Returns a view of {@code list} whose values have been mapped to elements
-     * of type {@code N} using {@code funcMtoN}. The returned list supports all
-     * operations.
-     *
-     * @param <M>
-     *            The type of elements contained in {@code list}.
-     * @param <N>
-     *            The type of elements contained in the returned list.
-     * @param <P>
-     *            The type of the additional parameter to the function's
-     *            {@code apply} method. Use {@link java.lang.Void} for functions
-     *            that do not need an additional parameter.
-     * @param list
-     *            The list to be transformed.
-     * @param funcMtoN
-     *            A function which maps values of type {@code M} to values of
-     *            type {@code N}. This function will be used when retrieving
-     *            values from {@code list}.
-     * @param funcNtoM
-     *            A function which maps values of type {@code N} to values of
-     *            type {@code M}. This function will be used when performing
-     *            queries and adding values to {@code list} .
-     * @param p
-     *            A predicate specified parameter.
-     * @return A view of {@code list} whose values have been mapped to elements
-     *         of type {@code N} using {@code funcMtoN}.
-     */
-    public static <M, N, P> List<N> transformedList(final List<M> list,
-            final Function<? super M, ? extends N, P> funcMtoN,
-            final Function<? super N, ? extends M, P> funcNtoM, final P p) {
-        return new TransformedList<M, N, P>(list, funcMtoN, funcNtoM, p);
+            final Function<? super M, ? extends N, NeverThrowsException> funcMtoN,
+            final Function<? super N, ? extends M, NeverThrowsException> funcNtoM) {
+        return new TransformedCollection<M, N, Collection<M>>(collection, funcMtoN, funcNtoM);
     }
 
     /**
@@ -390,12 +281,12 @@
      *         of type {@code N} using {@code funcMtoN}.
      */
     public static <M, N> List<N> transformedList(final List<M> list,
-            final Function<? super M, ? extends N, Void> funcMtoN,
-            final Function<? super N, ? extends M, Void> funcNtoM) {
-        return new TransformedList<M, N, Void>(list, funcMtoN, funcNtoM, null);
+            final Function<? super M, ? extends N, NeverThrowsException> funcMtoN,
+            final Function<? super N, ? extends M, NeverThrowsException> funcNtoM) {
+        return new TransformedList<M, N>(list, funcMtoN, funcNtoM);
     }
 
-    // Prevent instantiation
+    /** Prevent instantiation. */
     private Collections2() {
         // Do nothing.
     }
diff --git a/opendj-core/src/main/java/com/forgerock/opendj/util/Iterables.java b/opendj-core/src/main/java/com/forgerock/opendj/util/Iterables.java
index 72ffab9..e64fa8f 100644
--- a/opendj-core/src/main/java/com/forgerock/opendj/util/Iterables.java
+++ b/opendj-core/src/main/java/com/forgerock/opendj/util/Iterables.java
@@ -22,15 +22,15 @@
  *
  *
  *      Copyright 2009-2010 Sun Microsystems, Inc.
- *      Portions copyright 2013 ForgeRock AS.
+ *      Portions copyright 2013-2014 ForgeRock AS.
  */
-
 package com.forgerock.opendj.util;
 
 import java.util.Collection;
 import java.util.Iterator;
 
-import org.forgerock.opendj.ldap.Function;
+import org.forgerock.util.promise.Function;
+import org.forgerock.util.promise.NeverThrowsException;
 
 /**
  * Utility methods for manipulating {@link Iterable}s.
@@ -97,22 +97,20 @@
         }
     }
 
-    private static final class TransformedIterable<M, N, P> extends AbstractIterable<N> {
-        private final Function<? super M, ? extends N, P> function;
+    private static final class TransformedIterable<M, N> extends AbstractIterable<N> {
+        private final Function<? super M, ? extends N, NeverThrowsException> function;
         private final Iterable<M> iterable;
-        private final P parameter;
 
         // Constructed via factory methods.
         private TransformedIterable(final Iterable<M> iterable,
-                final Function<? super M, ? extends N, P> function, final P p) {
+                final Function<? super M, ? extends N, NeverThrowsException> function) {
             this.iterable = iterable;
             this.function = function;
-            this.parameter = p;
         }
 
         @Override
         public Iterator<N> iterator() {
-            return Iterators.transformedIterator(iterable.iterator(), function, parameter);
+            return Iterators.transformedIterator(iterable.iterator(), function);
         }
     }
 
@@ -300,34 +298,6 @@
      *            The type of elements contained in {@code iterable}.
      * @param <N>
      *            The type of elements contained in the returned iterable.
-     * @param <P>
-     *            The type of the additional parameter to the function's
-     *            {@code apply} method. Use {@link java.lang.Void} for functions
-     *            that do not need an additional parameter.
-     * @param iterable
-     *            The iterable to be transformed.
-     * @param function
-     *            The function.
-     * @param p
-     *            A predicate specified parameter.
-     * @return A view of {@code iterable} whose values have been mapped to
-     *         elements of type {@code N} using {@code function}.
-     */
-    public static <M, N, P> Iterable<N> transformedIterable(final Iterable<M> iterable,
-            final Function<? super M, ? extends N, P> function, final P p) {
-        return new TransformedIterable<M, N, P>(iterable, function, p);
-    }
-
-    /**
-     * Returns a view of {@code iterable} whose values have been mapped to
-     * elements of type {@code N} using {@code function}. The returned
-     * iterable's iterator supports element removal via the {@code remove()}
-     * method subject to any constraints imposed by {@code iterable}.
-     *
-     * @param <M>
-     *            The type of elements contained in {@code iterable}.
-     * @param <N>
-     *            The type of elements contained in the returned iterable.
      * @param iterable
      *            The iterable to be transformed.
      * @param function
@@ -336,8 +306,8 @@
      *         elements of type {@code N} using {@code function}.
      */
     public static <M, N> Iterable<N> transformedIterable(final Iterable<M> iterable,
-            final Function<? super M, ? extends N, Void> function) {
-        return new TransformedIterable<M, N, Void>(iterable, function, null);
+            final Function<? super M, ? extends N, NeverThrowsException> function) {
+        return new TransformedIterable<M, N>(iterable, function);
     }
 
     /**
diff --git a/opendj-core/src/main/java/com/forgerock/opendj/util/Iterators.java b/opendj-core/src/main/java/com/forgerock/opendj/util/Iterators.java
index 23a3fb7..a487ffe 100644
--- a/opendj-core/src/main/java/com/forgerock/opendj/util/Iterators.java
+++ b/opendj-core/src/main/java/com/forgerock/opendj/util/Iterators.java
@@ -22,6 +22,7 @@
  *
  *
  *      Copyright 2009-2010 Sun Microsystems, Inc.
+ *      Portions Copyright 2014 ForgeRock AS.
  */
 
 package com.forgerock.opendj.util;
@@ -29,7 +30,8 @@
 import java.util.Iterator;
 import java.util.NoSuchElementException;
 
-import org.forgerock.opendj.ldap.Function;
+import org.forgerock.util.promise.Function;
+import org.forgerock.util.promise.NeverThrowsException;
 
 /**
  * Utility methods for manipulating {@link Iterator}s.
@@ -39,21 +41,17 @@
         private int i = 0;
         private final M[] a;
 
-        // Constructed via factory methods.
+        /** Constructed via factory methods. */
         private ArrayIterator(final M[] a) {
             this.a = a;
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         public boolean hasNext() {
             return i < a.length;
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         public M next() {
             if (hasNext()) {
                 return a[i++];
@@ -62,9 +60,7 @@
             }
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         public void remove() {
             throw new UnsupportedOperationException();
         }
@@ -72,23 +68,17 @@
     }
 
     private static final class EmptyIterator<M> implements Iterator<M> {
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         public boolean hasNext() {
             return false;
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         public M next() {
             throw new NoSuchElementException();
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         public void remove() {
             throw new UnsupportedOperationException();
         }
@@ -103,7 +93,7 @@
         private final P parameter;
         private final Predicate<? super M, P> predicate;
 
-        // Constructed via factory methods.
+        /** Constructed via factory methods. */
         private FilteredIterator(final Iterator<M> iterator,
                 final Predicate<? super M, P> predicate, final P p) {
             this.iterator = iterator;
@@ -111,9 +101,7 @@
             this.parameter = p;
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         public boolean hasNext() {
             if (hasNextMustIterate) {
                 hasNextMustIterate = false;
@@ -130,9 +118,7 @@
             }
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         public M next() {
             if (!hasNext()) {
                 throw new NoSuchElementException();
@@ -141,9 +127,7 @@
             return next;
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         public void remove() {
             iterator.remove();
         }
@@ -153,21 +137,17 @@
     private static final class SingletonIterator<M> implements Iterator<M> {
         private M value;
 
-        // Constructed via factory methods.
+        /** Constructed via factory methods. */
         private SingletonIterator(final M value) {
             this.value = value;
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         public boolean hasNext() {
             return value != null;
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         public M next() {
             if (value != null) {
                 final M tmp = value;
@@ -178,46 +158,36 @@
             }
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         public void remove() {
             throw new UnsupportedOperationException();
         }
 
     }
 
-    private static final class TransformedIterator<M, N, P> implements Iterator<N> {
+    private static final class TransformedIterator<M, N> implements Iterator<N> {
 
-        private final Function<? super M, ? extends N, P> function;
+        private final Function<? super M, ? extends N, NeverThrowsException> function;
         private final Iterator<M> iterator;
-        private final P parameter;
 
-        // Constructed via factory methods.
+        /** Constructed via factory methods. */
         private TransformedIterator(final Iterator<M> iterator,
-                final Function<? super M, ? extends N, P> function, final P p) {
+                final Function<? super M, ? extends N, NeverThrowsException> function) {
             this.iterator = iterator;
             this.function = function;
-            this.parameter = p;
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         public boolean hasNext() {
             return iterator.hasNext();
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         public N next() {
-            return function.apply(iterator.next(), parameter);
+            return function.apply(iterator.next());
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         public void remove() {
             iterator.remove();
         }
@@ -231,23 +201,17 @@
             this.iterator = iterator;
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         public boolean hasNext() {
             return iterator.hasNext();
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         public M next() {
             return iterator.next();
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         public void remove() {
             throw new UnsupportedOperationException();
         }
@@ -353,34 +317,6 @@
      *            The type of elements contained in {@code iterator}.
      * @param <N>
      *            The type of elements contained in the returned iterator.
-     * @param <P>
-     *            The type of the additional parameter to the function's
-     *            {@code apply} method. Use {@link java.lang.Void} for functions
-     *            that do not need an additional parameter.
-     * @param iterator
-     *            The iterator to be transformed.
-     * @param function
-     *            The function.
-     * @param p
-     *            A predicate specified parameter.
-     * @return A view of {@code iterator} whose values have been mapped to
-     *         elements of type {@code N} using {@code function}.
-     */
-    public static <M, N, P> Iterator<N> transformedIterator(final Iterator<M> iterator,
-            final Function<? super M, ? extends N, P> function, final P p) {
-        return new TransformedIterator<M, N, P>(iterator, function, p);
-    }
-
-    /**
-     * Returns a view of {@code iterator} whose values have been mapped to
-     * elements of type {@code N} using {@code function}. The returned iterator
-     * supports element removal via the {@code remove()} method subject to any
-     * constraints imposed by {@code iterator}.
-     *
-     * @param <M>
-     *            The type of elements contained in {@code iterator}.
-     * @param <N>
-     *            The type of elements contained in the returned iterator.
      * @param iterator
      *            The iterator to be transformed.
      * @param function
@@ -389,8 +325,8 @@
      *         elements of type {@code N} using {@code function}.
      */
     public static <M, N> Iterator<N> transformedIterator(final Iterator<M> iterator,
-            final Function<? super M, ? extends N, Void> function) {
-        return new TransformedIterator<M, N, Void>(iterator, function, null);
+            final Function<? super M, ? extends N, NeverThrowsException> function) {
+        return new TransformedIterator<M, N>(iterator, function);
     }
 
     /**
@@ -410,7 +346,7 @@
         return new UnmodifiableIterator<M>(iterator);
     }
 
-    // Prevent instantiation
+    /** Prevent instantiation. */
     private Iterators() {
         // Do nothing.
     }
diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldap/AttributeParser.java b/opendj-core/src/main/java/org/forgerock/opendj/ldap/AttributeParser.java
index 81088d0..f1fc973 100644
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldap/AttributeParser.java
+++ b/opendj-core/src/main/java/org/forgerock/opendj/ldap/AttributeParser.java
@@ -21,13 +21,10 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2012 ForgeRock AS.
+ *      Copyright 2012-2014 ForgeRock AS.
  */
-
 package org.forgerock.opendj.ldap;
 
-import static com.forgerock.opendj.util.Collections2.transformedCollection;
-
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
@@ -36,6 +33,10 @@
 import java.util.Set;
 
 import org.forgerock.opendj.ldap.schema.Schema;
+import org.forgerock.util.promise.Function;
+import org.forgerock.util.promise.NeverThrowsException;
+
+import static com.forgerock.opendj.util.Collections2.*;
 
 /**
  * A fluent API for parsing attributes as different types of object. An
@@ -105,7 +106,7 @@
      *            The function which should be used to decode the value.
      * @return The first value decoded as a {@code T}.
      */
-    public <T> T as(final Function<ByteString, ? extends T, Void> f) {
+    public <T> T as(final Function<ByteString, ? extends T, NeverThrowsException> f) {
         return as(f, null);
     }
 
@@ -122,9 +123,9 @@
      *            The default value to return if the attribute is empty.
      * @return The first value decoded as a {@code T}.
      */
-    public <T> T as(final Function<ByteString, ? extends T, Void> f, final T defaultValue) {
+    public <T> T as(final Function<ByteString, ? extends T, NeverThrowsException> f, final T defaultValue) {
         if (!isEmpty(attribute)) {
-            return f.apply(attribute.firstValue(), null);
+            return f.apply(attribute.firstValue());
         } else {
             return defaultValue;
         }
@@ -329,12 +330,12 @@
      *            The default values to return if the attribute is empty.
      * @return The values decoded as a set of {@code T}s.
      */
-    public <T> Set<T> asSetOf(final Function<ByteString, ? extends T, Void> f,
+    public <T> Set<T> asSetOf(final Function<ByteString, ? extends T, NeverThrowsException> f,
             final Collection<? extends T> defaultValues) {
         if (!isEmpty(attribute)) {
             final LinkedHashSet<T> result = new LinkedHashSet<T>(attribute.size());
             for (final ByteString b : attribute) {
-                result.add(f.apply(b, null));
+                result.add(f.apply(b));
             }
             return result;
         } else if (defaultValues != null) {
@@ -357,7 +358,7 @@
      *            The default values to return if the attribute is empty.
      * @return The values decoded as a set of {@code T}s.
      */
-    public <T> Set<T> asSetOf(final Function<ByteString, ? extends T, Void> f,
+    public <T> Set<T> asSetOf(final Function<ByteString, ? extends T, NeverThrowsException> f,
             final T... defaultValues) {
         return asSetOf(f, Arrays.asList(defaultValues));
     }
diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldap/Entries.java b/opendj-core/src/main/java/org/forgerock/opendj/ldap/Entries.java
index c15ada6..dd5751d 100644
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldap/Entries.java
+++ b/opendj-core/src/main/java/org/forgerock/opendj/ldap/Entries.java
@@ -24,13 +24,8 @@
  *      Copyright 2010 Sun Microsystems, Inc.
  *      Portions Copyright 2011-2014 ForgeRock AS
  */
-
 package org.forgerock.opendj.ldap;
 
-import static com.forgerock.opendj.ldap.CoreMessages.*;
-import static org.forgerock.opendj.ldap.AttributeDescription.objectClass;
-import static org.forgerock.opendj.ldap.LdapException.newLdapException;
-
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -53,9 +48,16 @@
 import org.forgerock.opendj.ldap.schema.UnknownSchemaElementException;
 import org.forgerock.opendj.ldif.LDIF;
 import org.forgerock.util.Reject;
+import org.forgerock.util.promise.Function;
+import org.forgerock.util.promise.NeverThrowsException;
 
 import com.forgerock.opendj.util.Iterables;
 
+import static org.forgerock.opendj.ldap.AttributeDescription.*;
+import static org.forgerock.opendj.ldap.LdapException.*;
+
+import static com.forgerock.opendj.ldap.CoreMessages.*;
+
 /**
  * This class contains methods for creating and manipulating entries.
  *
@@ -407,11 +409,10 @@
     private static final AttributeFilter USER_ATTRIBUTES_ONLY_FILTER = new AttributeFilter();
     private static final DiffOptions DEFAULT_DIFF_OPTIONS = new DiffOptions();
 
-    private static final Function<Attribute, Attribute, Void> UNMODIFIABLE_ATTRIBUTE_FUNCTION =
-            new Function<Attribute, Attribute, Void>() {
-
+    private static final Function<Attribute, Attribute, NeverThrowsException> UNMODIFIABLE_ATTRIBUTE_FUNCTION =
+            new Function<Attribute, Attribute, NeverThrowsException>() {
                 @Override
-                public Attribute apply(final Attribute value, final Void p) {
+                public Attribute apply(final Attribute value) {
                     return Attributes.unmodifiableAttribute(value);
                 }
 
diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldap/Function.java b/opendj-core/src/main/java/org/forgerock/opendj/ldap/Function.java
deleted file mode 100644
index fc30ceb..0000000
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldap/Function.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
- * or http://forgerock.org/license/CDDLv1.0.html.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at legal-notices/CDDLv1_0.txt.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information:
- *      Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- *      Copyright 2009 Sun Microsystems, Inc.
- *      Portions copyright 2012 ForgeRock AS.
- */
-
-package org.forgerock.opendj.ldap;
-
-/**
- * Functions transform input values of type {@code M} to output values of type
- * {@code N}.
- * <p>
- * A {@code Function} can be passed to an {@link AttributeParser} in order to
- * facilitate parsing of attributes. Common implementations can be found in the
- * {@link Functions} class.
- *
- * @param <M>
- *            The type of input values transformed by this function.
- * @param <N>
- *            The type of output values return by this function.
- * @param <P>
- *            The type of the additional parameter to this function's
- *            {@code apply} method. Use {@link java.lang.Void} for functions
- *            that do not need an additional parameter.
- * @see Functions
- * @see AttributeParser
- */
-public interface Function<M, N, P> {
-    /**
-     * Applies this function to the provided input value of type {@code M} ,
-     * returning an output value of type {@code N}.
-     *
-     * @param value
-     *            The value to be transformed.
-     * @param p
-     *            A function specified parameter.
-     * @return The result of the transformation.
-     */
-    N apply(M value, P p);
-}
diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldap/Functions.java b/opendj-core/src/main/java/org/forgerock/opendj/ldap/Functions.java
index 40d35e7..304391b 100644
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldap/Functions.java
+++ b/opendj-core/src/main/java/org/forgerock/opendj/ldap/Functions.java
@@ -22,21 +22,22 @@
  *
  *
  *      Copyright 2009-2010 Sun Microsystems, Inc.
- *      Portions copyright 2012 ForgeRock AS.
+ *      Portions copyright 2012-2014 ForgeRock AS.
  */
-
 package org.forgerock.opendj.ldap;
 
-import static com.forgerock.opendj.ldap.CoreMessages.FUNCTIONS_TO_INTEGER_FAIL;
-import static com.forgerock.opendj.ldap.CoreMessages.FUNCTIONS_TO_LONG_FAIL;
-import static com.forgerock.opendj.ldap.CoreMessages.WARN_ATTR_SYNTAX_ILLEGAL_BOOLEAN;
-
 import org.forgerock.i18n.LocalizableMessage;
 import org.forgerock.i18n.LocalizedIllegalArgumentException;
 import org.forgerock.opendj.ldap.schema.Schema;
+import org.forgerock.util.promise.Function;
+import org.forgerock.util.promise.NeverThrowsException;
 
 import com.forgerock.opendj.util.StaticUtils;
 
+import static org.forgerock.opendj.ldap.schema.Schema.*;
+
+import static com.forgerock.opendj.ldap.CoreMessages.*;
+
 /**
  * Common {@link Function} implementations which may be used when parsing
  * attributes.
@@ -47,63 +48,37 @@
  */
 public final class Functions {
 
-    private static final class FixedFunction<M, N, P> implements Function<M, N, Void> {
-        private final Function<M, N, P> function;
-
-        private final P parameter;
-
-        private FixedFunction(final Function<M, N, P> function, final P p) {
-            this.function = function;
-            this.parameter = p;
-        }
-
-        /**
-         * {@inheritDoc}
-         */
-        public N apply(final M value, final Void p) {
-            return function.apply(value, parameter);
-        }
-
-    }
-
-    private static final Function<ByteString, String, Void> BYTESTRING_TO_STRING =
-            new Function<ByteString, String, Void>() {
-                public String apply(final ByteString value, final Void p) {
+    private static final Function<ByteString, String, NeverThrowsException> BYTESTRING_TO_STRING =
+            new Function<ByteString, String, NeverThrowsException>() {
+                public String apply(final ByteString value) {
                     return value.toString();
                 }
             };
 
-    private static final Function<Object, Object, Void> IDENTITY =
-            new Function<Object, Object, Void>() {
-                public Object apply(final Object value, final Void p) {
+    private static final Function<Object, Object, NeverThrowsException> IDENTITY =
+            new Function<Object, Object, NeverThrowsException>() {
+                public Object apply(final Object value) {
                     return value;
                 }
             };
 
-    private static final Function<String, String, Void> NORMALIZE_STRING =
-            new Function<String, String, Void>() {
-                public String apply(final String value, final Void p) {
+    private static final Function<String, String, NeverThrowsException> NORMALIZE_STRING =
+            new Function<String, String, NeverThrowsException>() {
+                public String apply(final String value) {
                     return StaticUtils.toLowerCase(value).trim();
                 }
             };
 
-    private static final Function<Object, ByteString, Void> OBJECT_TO_BYTESTRING =
-            new Function<Object, ByteString, Void>() {
-                public ByteString apply(final Object value, final Void p) {
+    private static final Function<Object, ByteString, NeverThrowsException> OBJECT_TO_BYTESTRING =
+            new Function<Object, ByteString, NeverThrowsException>() {
+                public ByteString apply(final Object value) {
                     return ByteString.valueOf(value);
                 }
             };
 
-    private static final Function<String, AttributeDescription, Schema> STRING_TO_ATTRIBUTE_DESCRIPTION =
-            new Function<String, AttributeDescription, Schema>() {
-                public AttributeDescription apply(final String value, final Schema p) {
-                    return AttributeDescription.valueOf(value, p);
-                }
-            };
-
-    private static final Function<String, Boolean, Void> STRING_TO_BOOLEAN =
-            new Function<String, Boolean, Void>() {
-                public Boolean apply(final String value, final Void p) {
+    private static final Function<String, Boolean, NeverThrowsException> STRING_TO_BOOLEAN =
+            new Function<String, Boolean, NeverThrowsException>() {
+                public Boolean apply(final String value) {
                     final String valueString = StaticUtils.toLowerCase(value);
 
                     if (valueString.equals("true") || valueString.equals("yes")
@@ -120,23 +95,16 @@
                 }
             };
 
-    private static final Function<String, DN, Schema> STRING_TO_DN =
-            new Function<String, DN, Schema>() {
-                public DN apply(final String value, final Schema p) {
-                    return DN.valueOf(value, p);
-                }
-            };
-
-    private static final Function<String, GeneralizedTime, Void> STRING_TO_GENERALIZED_TIME =
-            new Function<String, GeneralizedTime, Void>() {
-                public GeneralizedTime apply(final String value, final Void p) {
+    private static final Function<String, GeneralizedTime, NeverThrowsException> STRING_TO_GENERALIZED_TIME =
+            new Function<String, GeneralizedTime, NeverThrowsException>() {
+                public GeneralizedTime apply(final String value) {
                     return GeneralizedTime.valueOf(value);
                 }
             };
 
-    private static final Function<String, Integer, Void> STRING_TO_INTEGER =
-            new Function<String, Integer, Void>() {
-                public Integer apply(final String value, final Void p) {
+    private static final Function<String, Integer, NeverThrowsException> STRING_TO_INTEGER =
+            new Function<String, Integer, NeverThrowsException>() {
+                public Integer apply(final String value) {
                     try {
                         return Integer.valueOf(value);
                     } catch (final NumberFormatException e) {
@@ -146,9 +114,9 @@
                 }
             };
 
-    private static final Function<String, Long, Void> STRING_TO_LONG =
-            new Function<String, Long, Void>() {
-                public Long apply(final String value, final Void p) {
+    private static final Function<String, Long, NeverThrowsException> STRING_TO_LONG =
+            new Function<String, Long, NeverThrowsException>() {
+                public Long apply(final String value) {
                     try {
                         return Long.valueOf(value);
                     } catch (final NumberFormatException e) {
@@ -158,22 +126,16 @@
                 }
             };
 
-    private static final Function<ByteString, AttributeDescription, Schema> BYTESTRING_TO_ATTRIBUTE_DESCRIPTION =
-            composeSecondP(byteStringToString(), STRING_TO_ATTRIBUTE_DESCRIPTION);
-
-    private static final Function<ByteString, Boolean, Void> BYTESTRING_TO_BOOLEAN = compose(
+    private static final Function<ByteString, Boolean, NeverThrowsException> BYTESTRING_TO_BOOLEAN = compose(
             byteStringToString(), STRING_TO_BOOLEAN);
 
-    private static final Function<ByteString, DN, Schema> BYTESTRING_TO_DN = composeSecondP(
-            byteStringToString(), STRING_TO_DN);
-
-    private static final Function<ByteString, GeneralizedTime, Void> BYTESTRING_TO_GENERALIZED_TIME =
+    private static final Function<ByteString, GeneralizedTime, NeverThrowsException> BYTESTRING_TO_GENERALIZED_TIME =
             compose(byteStringToString(), STRING_TO_GENERALIZED_TIME);
 
-    private static final Function<ByteString, Integer, Void> BYTESTRING_TO_INTEGER = compose(
+    private static final Function<ByteString, Integer, NeverThrowsException> BYTESTRING_TO_INTEGER = compose(
             byteStringToString(), STRING_TO_INTEGER);
 
-    private static final Function<ByteString, Long, Void> BYTESTRING_TO_LONG = compose(
+    private static final Function<ByteString, Long, NeverThrowsException> BYTESTRING_TO_LONG = compose(
             byteStringToString(), STRING_TO_LONG);
 
     /**
@@ -193,105 +155,16 @@
      *            The second function which will produce the result.
      * @return The composition.
      */
-    public static <M, X, N> Function<M, N, Void> compose(final Function<M, X, Void> first,
-            final Function<X, N, Void> second) {
-        return new Function<M, N, Void>() {
-            public N apply(final M value, final Void p) {
-                final X tmp = first.apply(value, p);
-                return second.apply(tmp, p);
+    public static <M, X, N> Function<M, N, NeverThrowsException> compose(
+            final Function<M, X, NeverThrowsException> first, final Function<X, N, NeverThrowsException> second) {
+        return new Function<M, N, NeverThrowsException>() {
+            public N apply(final M value) {
+                return second.apply(first.apply(value));
             }
         };
     }
 
     /**
-     * Returns the composition of two functions. The result of the first
-     * function will be passed to the second. The first function will be passed
-     * an additional parameter.
-     *
-     * @param <M>
-     *            The type of input values transformed by this function.
-     * @param <N>
-     *            The type of output values returned by this function.
-     * @param <X>
-     *            The type of intermediate values passed between the two
-     *            functions.
-     * @param <P>
-     *            The type of the additional parameter to the first function's
-     *            {@code apply} method. Use {@link java.lang.Void} for functions
-     *            that do not need an additional parameter.
-     * @param first
-     *            The first function which will consume the input.
-     * @param second
-     *            The second function which will produce the result.
-     * @return The composition.
-     */
-    public static <M, X, N, P> Function<M, N, P> composeFirstP(final Function<M, X, P> first,
-            final Function<X, N, Void> second) {
-        return new Function<M, N, P>() {
-            public N apply(final M value, final P p) {
-                final X tmp = first.apply(value, p);
-                return second.apply(tmp, null);
-            }
-        };
-    }
-
-    /**
-     * Returns the composition of two functions. The result of the first
-     * function will be passed to the second. The second function will be passed
-     * an additional parameter.
-     *
-     * @param <M>
-     *            The type of input values transformed by this function.
-     * @param <N>
-     *            The type of output values returned by this function.
-     * @param <X>
-     *            The type of intermediate values passed between the two
-     *            functions.
-     * @param <P>
-     *            The type of the additional parameter to the second function's
-     *            {@code apply} method. Use {@link java.lang.Void} for functions
-     *            that do not need an additional parameter.
-     * @param first
-     *            The first function which will consume the input.
-     * @param second
-     *            The second function which will produce the result.
-     * @return The composition.
-     */
-    public static <M, X, N, P> Function<M, N, P> composeSecondP(final Function<M, X, Void> first,
-            final Function<X, N, P> second) {
-        return new Function<M, N, P>() {
-            public N apply(final M value, final P p) {
-                final X tmp = first.apply(value, null);
-                return second.apply(tmp, p);
-            }
-        };
-    }
-
-    /**
-     * Returns a function which which always invokes {@code function} with
-     * {@code p}.
-     *
-     * @param <M>
-     *            The type of input values transformed by this function.
-     * @param <N>
-     *            The type of output values return by this function.
-     * @param <P>
-     *            The type of the additional parameter to this function's
-     *            {@code apply} method. Use {@link java.lang.Void} for functions
-     *            that do not need an additional parameter.
-     * @param function
-     *            The function to wrap.
-     * @param p
-     *            The parameter which will always be passed to {@code function}.
-     * @return A function which which always invokes {@code function} with
-     *         {@code p}.
-     */
-    public static <M, N, P> Function<M, N, Void> fixedFunction(final Function<M, N, P> function,
-            final P p) {
-        return new FixedFunction<M, N, P>(function, p);
-    }
-
-    /**
      * Returns a function which always returns the value that it was provided
      * with.
      *
@@ -301,8 +174,8 @@
      *         with.
      */
     @SuppressWarnings("unchecked")
-    public static <M> Function<M, M, Void> identityFunction() {
-        return (Function<M, M, Void>) IDENTITY;
+    public static <M> Function<M, M, NeverThrowsException> identityFunction() {
+        return (Function<M, M, NeverThrowsException>) IDENTITY;
     }
 
     /**
@@ -312,7 +185,7 @@
      * @return A function which converts a {@code String} to lower case using
      *         {@link StaticUtils#toLowerCase} and then trims it.
      */
-    public static Function<String, String, Void> normalizeString() {
+    public static Function<String, String, NeverThrowsException> normalizeString() {
         return NORMALIZE_STRING;
     }
 
@@ -323,7 +196,7 @@
      * @return A function which converts an {@code Object} to a
      *         {@code ByteString} .
      */
-    public static Function<Object, ByteString, Void> objectToByteString() {
+    public static Function<Object, ByteString, NeverThrowsException> objectToByteString() {
         return OBJECT_TO_BYTESTRING;
     }
 
@@ -334,8 +207,8 @@
      *
      * @return A function which parses {@code AttributeDescription}s.
      */
-    public static Function<String, AttributeDescription, Void> stringToAttributeDescription() {
-        return fixedFunction(STRING_TO_ATTRIBUTE_DESCRIPTION, Schema.getDefaultSchema());
+    public static Function<String, AttributeDescription, NeverThrowsException> stringToAttributeDescription() {
+        return stringToAttributeDescription(getDefaultSchema());
     }
 
     /**
@@ -347,9 +220,13 @@
      *            The schema to use for decoding attribute descriptions.
      * @return A function which parses {@code AttributeDescription}s.
      */
-    public static Function<String, AttributeDescription, Void> stringToAttributeDescription(
+    public static Function<String, AttributeDescription, NeverThrowsException> stringToAttributeDescription(
             final Schema schema) {
-        return fixedFunction(STRING_TO_ATTRIBUTE_DESCRIPTION, schema);
+        return new Function<String, AttributeDescription, NeverThrowsException>() {
+            public AttributeDescription apply(final String value) {
+                return AttributeDescription.valueOf(value, schema);
+            }
+        };
     }
 
     /**
@@ -360,7 +237,7 @@
      *
      * @return A function which parses {@code Boolean} values.
      */
-    public static Function<String, Boolean, Void> stringToBoolean() {
+    public static Function<String, Boolean, NeverThrowsException> stringToBoolean() {
         return STRING_TO_BOOLEAN;
     }
 
@@ -371,8 +248,8 @@
      *
      * @return A function which parses {@code DN}s.
      */
-    public static Function<String, DN, Void> stringToDN() {
-        return fixedFunction(STRING_TO_DN, Schema.getDefaultSchema());
+    public static Function<String, DN, NeverThrowsException> stringToDN() {
+        return stringToDN(getDefaultSchema());
     }
 
     /**
@@ -384,8 +261,12 @@
      *            The schema to use for decoding DNs.
      * @return A function which parses {@code DN}s.
      */
-    public static Function<String, DN, Void> stringToDN(final Schema schema) {
-        return fixedFunction(STRING_TO_DN, schema);
+    public static Function<String, DN, NeverThrowsException> stringToDN(final Schema schema) {
+        return new Function<String, DN, NeverThrowsException>() {
+            public DN apply(final String value) {
+                return DN.valueOf(value, schema);
+            }
+        };
     }
 
     /**
@@ -394,7 +275,7 @@
      *
      * @return A function which parses generalized time strings.
      */
-    public static Function<String, GeneralizedTime, Void> stringToGeneralizedTime() {
+    public static Function<String, GeneralizedTime, NeverThrowsException> stringToGeneralizedTime() {
         return STRING_TO_GENERALIZED_TIME;
     }
 
@@ -404,7 +285,7 @@
      *
      * @return A function which parses {@code Integer} string values.
      */
-    public static Function<String, Integer, Void> stringToInteger() {
+    public static Function<String, Integer, NeverThrowsException> stringToInteger() {
         return STRING_TO_INTEGER;
     }
 
@@ -414,7 +295,7 @@
      *
      * @return A function which parses {@code Long} string values.
      */
-    public static Function<String, Long, Void> stringToLong() {
+    public static Function<String, Long, NeverThrowsException> stringToLong() {
         return STRING_TO_LONG;
     }
 
@@ -425,8 +306,8 @@
      *
      * @return A function which parses {@code AttributeDescription}s.
      */
-    public static Function<ByteString, AttributeDescription, Void> byteStringToAttributeDescription() {
-        return fixedFunction(BYTESTRING_TO_ATTRIBUTE_DESCRIPTION, Schema.getDefaultSchema());
+    public static Function<ByteString, AttributeDescription, NeverThrowsException> byteStringToAttributeDescription() {
+        return byteStringToAttributeDescription(getDefaultSchema());
     }
 
     /**
@@ -438,9 +319,13 @@
      *            The schema to use for decoding attribute descriptions.
      * @return A function which parses {@code AttributeDescription}s.
      */
-    public static Function<ByteString, AttributeDescription, Void> byteStringToAttributeDescription(
+    public static Function<ByteString, AttributeDescription, NeverThrowsException> byteStringToAttributeDescription(
             final Schema schema) {
-        return fixedFunction(BYTESTRING_TO_ATTRIBUTE_DESCRIPTION, schema);
+        return compose(byteStringToString(), new Function<String, AttributeDescription, NeverThrowsException>() {
+            public AttributeDescription apply(final String value) {
+                return AttributeDescription.valueOf(value, schema);
+            }
+        });
     }
 
     /**
@@ -451,7 +336,7 @@
      *
      * @return A function which parses {@code Boolean} values.
      */
-    public static Function<ByteString, Boolean, Void> byteStringToBoolean() {
+    public static Function<ByteString, Boolean, NeverThrowsException> byteStringToBoolean() {
         return BYTESTRING_TO_BOOLEAN;
     }
 
@@ -462,8 +347,8 @@
      *
      * @return A function which parses {@code DN}s.
      */
-    public static Function<ByteString, DN, Void> byteStringToDN() {
-        return fixedFunction(BYTESTRING_TO_DN, Schema.getDefaultSchema());
+    public static Function<ByteString, DN, NeverThrowsException> byteStringToDN() {
+        return byteStringToDN(getDefaultSchema());
     }
 
     /**
@@ -475,8 +360,12 @@
      *            The schema to use for decoding DNs.
      * @return A function which parses {@code DN}s.
      */
-    public static Function<ByteString, DN, Void> byteStringToDN(final Schema schema) {
-        return fixedFunction(BYTESTRING_TO_DN, schema);
+    public static Function<ByteString, DN, NeverThrowsException> byteStringToDN(final Schema schema) {
+        return compose(byteStringToString(), new Function<String, DN, NeverThrowsException>() {
+            public DN apply(final String value) {
+                return DN.valueOf(value, schema);
+            }
+        });
     }
 
     /**
@@ -485,7 +374,7 @@
      *
      * @return A function which parses generalized time strings.
      */
-    public static Function<ByteString, GeneralizedTime, Void> byteStringToGeneralizedTime() {
+    public static Function<ByteString, GeneralizedTime, NeverThrowsException> byteStringToGeneralizedTime() {
         return BYTESTRING_TO_GENERALIZED_TIME;
     }
 
@@ -495,7 +384,7 @@
      *
      * @return A function which parses {@code Integer} string values.
      */
-    public static Function<ByteString, Integer, Void> byteStringToInteger() {
+    public static Function<ByteString, Integer, NeverThrowsException> byteStringToInteger() {
         return BYTESTRING_TO_INTEGER;
     }
 
@@ -505,7 +394,7 @@
      *
      * @return A function which parses {@code Long} string values.
      */
-    public static Function<ByteString, Long, Void> byteStringToLong() {
+    public static Function<ByteString, Long, NeverThrowsException> byteStringToLong() {
         return BYTESTRING_TO_LONG;
     }
 
@@ -516,7 +405,7 @@
      * @return A function which parses the string representation of a
      *         {@code ByteString} as a UTF-8 encoded {@code String}.
      */
-    public static Function<ByteString, String, Void> byteStringToString() {
+    public static Function<ByteString, String, NeverThrowsException> byteStringToString() {
         return BYTESTRING_TO_STRING;
     }
 
diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldap/RootDSE.java b/opendj-core/src/main/java/org/forgerock/opendj/ldap/RootDSE.java
index bc1a3fb..4975ada 100644
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldap/RootDSE.java
+++ b/opendj-core/src/main/java/org/forgerock/opendj/ldap/RootDSE.java
@@ -35,6 +35,7 @@
 import org.forgerock.opendj.ldap.schema.CoreSchema;
 import org.forgerock.util.Reject;
 import org.forgerock.util.promise.Function;
+import org.forgerock.util.promise.NeverThrowsException;
 
 import com.forgerock.opendj.util.Collections2;
 
@@ -413,7 +414,7 @@
 
     private <N> Collection<N> getMultiValuedAttribute(
             final AttributeDescription attributeDescription,
-        final org.forgerock.opendj.ldap.Function<ByteString, N, Void> function) {
+        final Function<ByteString, N, NeverThrowsException> function) {
         // The returned collection is unmodifiable because we may need to
         // return an empty collection if the attribute does not exist in the
         // underlying entry. If a value is then added to the returned empty
@@ -429,12 +430,12 @@
     }
 
     private <N> N getSingleValuedAttribute(final AttributeDescription attributeDescription,
-        final org.forgerock.opendj.ldap.Function<ByteString, N, Void> function) {
+        final Function<ByteString, N, NeverThrowsException> function) {
         final Attribute attr = entry.getAttribute(attributeDescription);
         if (attr == null || attr.isEmpty()) {
             return null;
         } else {
-            return function.apply(attr.firstValue(), null);
+            return function.apply(attr.firstValue());
         }
     }
 
diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldap/requests/AbstractUnmodifiableRequest.java b/opendj-core/src/main/java/org/forgerock/opendj/ldap/requests/AbstractUnmodifiableRequest.java
index 64d23c6..701c0eb 100644
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldap/requests/AbstractUnmodifiableRequest.java
+++ b/opendj-core/src/main/java/org/forgerock/opendj/ldap/requests/AbstractUnmodifiableRequest.java
@@ -22,9 +22,8 @@
  *
  *
  *      Copyright 2010 Sun Microsystems, Inc.
- *      Portions copyright 2012-2013 ForgeRock AS.
+ *      Portions copyright 2012-2014 ForgeRock AS.
  */
-
 package org.forgerock.opendj.ldap.requests;
 
 import java.util.Collections;
@@ -32,12 +31,13 @@
 
 import org.forgerock.opendj.ldap.DecodeException;
 import org.forgerock.opendj.ldap.DecodeOptions;
-import org.forgerock.opendj.ldap.Function;
 import org.forgerock.opendj.ldap.Functions;
 import org.forgerock.opendj.ldap.controls.Control;
 import org.forgerock.opendj.ldap.controls.ControlDecoder;
 import org.forgerock.opendj.ldap.controls.GenericControl;
 import org.forgerock.util.Reject;
+import org.forgerock.util.promise.Function;
+import org.forgerock.util.promise.NeverThrowsException;
 
 import com.forgerock.opendj.util.Collections2;
 
@@ -96,15 +96,14 @@
     public final List<Control> getControls() {
         // We need to make all controls unmodifiable as well, which implies
         // making defensive copies where necessary.
-        final Function<Control, Control, Void> function = new Function<Control, Control, Void>() {
-
-            @Override
-            public Control apply(final Control value, final Void p) {
-                // Return defensive copy.
-                return GenericControl.newControl(value);
-            }
-
-        };
+        final Function<Control, Control, NeverThrowsException> function =
+                new Function<Control, Control, NeverThrowsException>() {
+                    @Override
+                    public Control apply(final Control value) {
+                        // Return defensive copy.
+                        return GenericControl.newControl(value);
+                    }
+                };
 
         final List<Control> unmodifiableControls =
                 Collections2.transformedList(impl.getControls(), function, Functions
diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldap/requests/UnmodifiableAddRequestImpl.java b/opendj-core/src/main/java/org/forgerock/opendj/ldap/requests/UnmodifiableAddRequestImpl.java
index 39ebd16..e72f264 100644
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldap/requests/UnmodifiableAddRequestImpl.java
+++ b/opendj-core/src/main/java/org/forgerock/opendj/ldap/requests/UnmodifiableAddRequestImpl.java
@@ -22,9 +22,8 @@
  *
  *
  *      Copyright 2010 Sun Microsystems, Inc.
- *      Portions copyright 2012 ForgeRock AS.
+ *      Portions copyright 2012-2014 ForgeRock AS.
  */
-
 package org.forgerock.opendj.ldap.requests;
 
 import java.util.Collection;
@@ -35,9 +34,10 @@
 import org.forgerock.opendj.ldap.Attributes;
 import org.forgerock.opendj.ldap.ByteString;
 import org.forgerock.opendj.ldap.DN;
-import org.forgerock.opendj.ldap.Function;
-import org.forgerock.opendj.ldif.ChangeRecordVisitor;
 
+import org.forgerock.opendj.ldif.ChangeRecordVisitor;
+import org.forgerock.util.promise.Function;
+import org.forgerock.util.promise.NeverThrowsException;
 import com.forgerock.opendj.util.Iterables;
 
 /**
@@ -45,14 +45,12 @@
  */
 final class UnmodifiableAddRequestImpl extends AbstractUnmodifiableRequest<AddRequest> implements
         AddRequest {
-    private static final Function<Attribute, Attribute, Void> UNMODIFIABLE_ATTRIBUTE_FUNCTION =
-            new Function<Attribute, Attribute, Void>() {
-
+    private static final Function<Attribute, Attribute, NeverThrowsException> UNMODIFIABLE_ATTRIBUTE_FUNCTION =
+            new Function<Attribute, Attribute, NeverThrowsException>() {
                 @Override
-                public Attribute apply(final Attribute value, final Void p) {
+                public Attribute apply(final Attribute value) {
                     return Attributes.unmodifiableAttribute(value);
                 }
-
             };
 
     UnmodifiableAddRequestImpl(final AddRequest impl) {
diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldap/requests/UnmodifiableModifyRequestImpl.java b/opendj-core/src/main/java/org/forgerock/opendj/ldap/requests/UnmodifiableModifyRequestImpl.java
index 7cef834..06c730e 100644
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldap/requests/UnmodifiableModifyRequestImpl.java
+++ b/opendj-core/src/main/java/org/forgerock/opendj/ldap/requests/UnmodifiableModifyRequestImpl.java
@@ -22,9 +22,8 @@
  *
  *
  *      Copyright 2010 Sun Microsystems, Inc.
- *      Portions copyright 2012 ForgeRock AS.
+ *      Portions copyright 2012-2014 ForgeRock AS.
  */
-
 package org.forgerock.opendj.ldap.requests;
 
 import java.util.Collections;
@@ -33,11 +32,12 @@
 import org.forgerock.opendj.ldap.Attribute;
 import org.forgerock.opendj.ldap.Attributes;
 import org.forgerock.opendj.ldap.DN;
-import org.forgerock.opendj.ldap.Function;
 import org.forgerock.opendj.ldap.Functions;
 import org.forgerock.opendj.ldap.Modification;
 import org.forgerock.opendj.ldap.ModificationType;
 import org.forgerock.opendj.ldif.ChangeRecordVisitor;
+import org.forgerock.util.promise.Function;
+import org.forgerock.util.promise.NeverThrowsException;
 
 import com.forgerock.opendj.util.Collections2;
 
@@ -69,17 +69,14 @@
     @Override
     public List<Modification> getModifications() {
         // We need to make all attributes unmodifiable as well.
-        final Function<Modification, Modification, Void> function =
-                new Function<Modification, Modification, Void>() {
-
+        final Function<Modification, Modification, NeverThrowsException> function =
+                new Function<Modification, Modification, NeverThrowsException>() {
                     @Override
-                    public Modification apply(final Modification value, final Void p) {
+                    public Modification apply(final Modification value) {
                         final ModificationType type = value.getModificationType();
-                        final Attribute attribute =
-                                Attributes.unmodifiableAttribute(value.getAttribute());
+                        final Attribute attribute = Attributes.unmodifiableAttribute(value.getAttribute());
                         return new Modification(type, attribute);
                     }
-
                 };
 
         final List<Modification> unmodifiableModifications =
diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldap/responses/AbstractUnmodifiableResponseImpl.java b/opendj-core/src/main/java/org/forgerock/opendj/ldap/responses/AbstractUnmodifiableResponseImpl.java
index 4a47f78..ba729c2 100644
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldap/responses/AbstractUnmodifiableResponseImpl.java
+++ b/opendj-core/src/main/java/org/forgerock/opendj/ldap/responses/AbstractUnmodifiableResponseImpl.java
@@ -22,9 +22,8 @@
  *
  *
  *      Copyright 2010 Sun Microsystems, Inc.
- *      Portions copyright 2012-2013 ForgeRock AS.
+ *      Portions copyright 2012-2014 ForgeRock AS.
  */
-
 package org.forgerock.opendj.ldap.responses;
 
 import java.util.Collections;
@@ -32,12 +31,13 @@
 
 import org.forgerock.opendj.ldap.DecodeException;
 import org.forgerock.opendj.ldap.DecodeOptions;
-import org.forgerock.opendj.ldap.Function;
 import org.forgerock.opendj.ldap.Functions;
 import org.forgerock.opendj.ldap.controls.Control;
 import org.forgerock.opendj.ldap.controls.ControlDecoder;
 import org.forgerock.opendj.ldap.controls.GenericControl;
 import org.forgerock.util.Reject;
+import org.forgerock.util.promise.Function;
+import org.forgerock.util.promise.NeverThrowsException;
 
 import com.forgerock.opendj.util.Collections2;
 
@@ -100,15 +100,14 @@
          * We need to make all controls unmodifiable as well, which implies
          * making defensive copies where necessary.
          */
-        final Function<Control, Control, Void> function = new Function<Control, Control, Void>() {
-
-            @Override
-            public Control apply(final Control value, final Void p) {
-                // Return defensive copy.
-                return GenericControl.newControl(value);
-            }
-
-        };
+        final Function<Control, Control, NeverThrowsException> function =
+                new Function<Control, Control, NeverThrowsException>() {
+                    @Override
+                    public Control apply(final Control value) {
+                        // Return defensive copy.
+                        return GenericControl.newControl(value);
+                    }
+                };
 
         final List<Control> unmodifiableControls =
                 Collections2.transformedList(impl.getControls(), function, Functions
diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldap/responses/UnmodifiableSearchResultEntryImpl.java b/opendj-core/src/main/java/org/forgerock/opendj/ldap/responses/UnmodifiableSearchResultEntryImpl.java
index 0dbba31..20dbe8d 100644
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldap/responses/UnmodifiableSearchResultEntryImpl.java
+++ b/opendj-core/src/main/java/org/forgerock/opendj/ldap/responses/UnmodifiableSearchResultEntryImpl.java
@@ -22,7 +22,7 @@
  *
  *
  *      Copyright 2010 Sun Microsystems, Inc.
- *      Portions copyright 2012 ForgeRock AS.
+ *      Portions copyright 2012-2014 ForgeRock AS.
  */
 
 package org.forgerock.opendj.ldap.responses;
@@ -35,7 +35,8 @@
 import org.forgerock.opendj.ldap.Attributes;
 import org.forgerock.opendj.ldap.ByteString;
 import org.forgerock.opendj.ldap.DN;
-import org.forgerock.opendj.ldap.Function;
+import org.forgerock.util.promise.Function;
+import org.forgerock.util.promise.NeverThrowsException;
 
 import com.forgerock.opendj.util.Iterables;
 
@@ -44,14 +45,12 @@
  */
 class UnmodifiableSearchResultEntryImpl extends AbstractUnmodifiableResponseImpl<SearchResultEntry>
         implements SearchResultEntry {
-    private static final Function<Attribute, Attribute, Void> UNMODIFIABLE_ATTRIBUTE_FUNCTION =
-            new Function<Attribute, Attribute, Void>() {
-
+    private static final Function<Attribute, Attribute, NeverThrowsException> UNMODIFIABLE_ATTRIBUTE_FUNCTION =
+            new Function<Attribute, Attribute, NeverThrowsException>() {
                 @Override
-                public Attribute apply(final Attribute value, final Void p) {
+                public Attribute apply(final Attribute value) {
                     return Attributes.unmodifiableAttribute(value);
                 }
-
             };
 
     UnmodifiableSearchResultEntryImpl(final SearchResultEntry impl) {
diff --git a/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/AbstractLDAPAttributeMapper.java b/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/AbstractLDAPAttributeMapper.java
index d065b1f..917796f 100644
--- a/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/AbstractLDAPAttributeMapper.java
+++ b/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/AbstractLDAPAttributeMapper.java
@@ -11,7 +11,7 @@
  * Header, with the fields enclosed by brackets [] replaced by your own identifying
  * information: "Portions Copyright [year] [name of copyright owner]".
  *
- * Copyright 2013 ForgeRock AS.
+ * Copyright 2013-2014 ForgeRock AS.
  */
 package org.forgerock.opendj.rest2ldap;
 
@@ -39,11 +39,11 @@
 import org.forgerock.opendj.ldap.Attribute;
 import org.forgerock.opendj.ldap.AttributeDescription;
 import org.forgerock.opendj.ldap.Entry;
-import org.forgerock.opendj.ldap.Function;
 import org.forgerock.opendj.ldap.LinkedAttribute;
 import org.forgerock.opendj.ldap.Modification;
 import org.forgerock.opendj.ldap.ModificationType;
-
+import org.forgerock.util.promise.Function;
+import org.forgerock.util.promise.NeverThrowsException;
 /**
  * An abstract LDAP attribute mapper which provides a simple mapping from a JSON
  * value to a single LDAP attribute.
@@ -243,9 +243,9 @@
                 }
             } else {
                 getNewLDAPAttributes(c, path, newValues, transform(
-                        new Function<Attribute, List<Modification>, Void>() {
+                        new Function<Attribute, List<Modification>, NeverThrowsException>() {
                             @Override
-                            public List<Modification> apply(final Attribute value, final Void p) {
+                            public List<Modification> apply(final Attribute value) {
                                 return singletonList(new Modification(modType, value));
                             }
                         }, h));
diff --git a/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/LDAPCollectionResourceProvider.java b/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/LDAPCollectionResourceProvider.java
index 0a0521a..32d91f2 100644
--- a/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/LDAPCollectionResourceProvider.java
+++ b/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/LDAPCollectionResourceProvider.java
@@ -54,7 +54,6 @@
 import org.forgerock.opendj.ldap.Entry;
 import org.forgerock.opendj.ldap.LdapException;
 import org.forgerock.opendj.ldap.Filter;
-import org.forgerock.opendj.ldap.Function;
 import org.forgerock.opendj.ldap.Modification;
 import org.forgerock.opendj.ldap.SearchResultHandler;
 import org.forgerock.opendj.ldap.SearchScope;
@@ -74,6 +73,8 @@
 import org.forgerock.opendj.ldap.responses.SearchResultReference;
 import org.forgerock.opendj.ldif.ChangeRecord;
 import org.forgerock.util.promise.FailureHandler;
+import org.forgerock.util.promise.Function;
+import org.forgerock.util.promise.NeverThrowsException;
 import org.forgerock.util.promise.Promise;
 import org.forgerock.util.promise.PromiseImpl;
 import org.forgerock.util.promise.Promises;
@@ -635,9 +636,9 @@
         final String actualResourceId = nameStrategy.getResourceId(c, entry);
         final String revision = getRevisionFromEntry(entry);
         attributeMapper.read(c, new JsonPointer(), entry, transform(
-                new Function<JsonValue, Resource, Void>() {
+                new Function<JsonValue, Resource, NeverThrowsException>() {
                     @Override
-                    public Resource apply(final JsonValue value, final Void p) {
+                    public Resource apply(final JsonValue value) {
                         return new Resource(actualResourceId, revision, new JsonValue(value));
                     }
                 }, handler));
@@ -873,9 +874,9 @@
                     @Override
                     public Void visitNotFilter(final ResultHandler<Filter> p,
                             final QueryFilter subFilter) {
-                        subFilter.accept(this, transform(new Function<Filter, Filter, Void>() {
+                        subFilter.accept(this, transform(new Function<Filter, Filter, NeverThrowsException>() {
                             @Override
-                            public Filter apply(final Filter value, final Void p) {
+                            public Filter apply(final Filter value) {
                                 if (value == null || value == alwaysFalse()) {
                                     return alwaysTrue();
                                 } else if (value == alwaysTrue()) {
diff --git a/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/ObjectAttributeMapper.java b/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/ObjectAttributeMapper.java
index ee22625..214b66d 100644
--- a/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/ObjectAttributeMapper.java
+++ b/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/ObjectAttributeMapper.java
@@ -11,18 +11,10 @@
  * Header, with the fields enclosed by brackets [] replaced by your own identifying
  * information: "Portions Copyright [year] [name of copyright owner]".
  *
- * Copyright 2012-2013 ForgeRock AS.
+ * Copyright 2012-2014 ForgeRock AS.
  */
 package org.forgerock.opendj.rest2ldap;
 
-import static org.forgerock.json.resource.PatchOperation.operation;
-import static org.forgerock.opendj.ldap.Filter.alwaysFalse;
-import static org.forgerock.opendj.rest2ldap.Rest2LDAP.asResourceException;
-import static org.forgerock.opendj.rest2ldap.Utils.accumulate;
-import static org.forgerock.opendj.rest2ldap.Utils.i18n;
-import static org.forgerock.opendj.rest2ldap.Utils.toLowerCase;
-import static org.forgerock.opendj.rest2ldap.Utils.transform;
-
 import java.util.AbstractMap.SimpleImmutableEntry;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -40,8 +32,14 @@
 import org.forgerock.opendj.ldap.Attribute;
 import org.forgerock.opendj.ldap.Entry;
 import org.forgerock.opendj.ldap.Filter;
-import org.forgerock.opendj.ldap.Function;
 import org.forgerock.opendj.ldap.Modification;
+import org.forgerock.util.promise.Function;
+import org.forgerock.util.promise.NeverThrowsException;
+
+import static org.forgerock.json.resource.PatchOperation.*;
+import static org.forgerock.opendj.ldap.Filter.*;
+import static org.forgerock.opendj.rest2ldap.Rest2LDAP.*;
+import static org.forgerock.opendj.rest2ldap.Utils.*;
 
 /**
  * An attribute mapper which maps JSON objects to LDAP attributes.
@@ -218,10 +216,9 @@
          */
         final ResultHandler<Map.Entry<String, JsonValue>> handler =
                 accumulate(mappings.size(), transform(
-                        new Function<List<Map.Entry<String, JsonValue>>, JsonValue, Void>() {
+                        new Function<List<Map.Entry<String, JsonValue>>, JsonValue, NeverThrowsException>() {
                             @Override
-                            public JsonValue apply(final List<Map.Entry<String, JsonValue>> value,
-                                    final Void p) {
+                            public JsonValue apply(final List<Map.Entry<String, JsonValue>> value) {
                                 if (value.isEmpty()) {
                                     /*
                                      * No subordinate attributes, so omit the
@@ -245,10 +242,9 @@
 
         for (final Mapping mapping : mappings.values()) {
             mapping.mapper.read(c, path.child(mapping.name), e, transform(
-                    new Function<JsonValue, Map.Entry<String, JsonValue>, Void>() {
+                    new Function<JsonValue, Map.Entry<String, JsonValue>, NeverThrowsException>() {
                         @Override
-                        public Map.Entry<String, JsonValue> apply(final JsonValue value,
-                                final Void p) {
+                        public Map.Entry<String, JsonValue> apply(final JsonValue value) {
                             return value != null ? new SimpleImmutableEntry<String, JsonValue>(
                                     mapping.name, value) : null;
                         }
@@ -292,9 +288,9 @@
     }
 
     private <T> ResultHandler<List<T>> accumulator(final int size, final ResultHandler<List<T>> h) {
-        return accumulate(size, transform(new Function<List<List<T>>, List<T>, Void>() {
+        return accumulate(size, transform(new Function<List<List<T>>, List<T>, NeverThrowsException>() {
             @Override
-            public List<T> apply(final List<List<T>> value, final Void p) {
+            public List<T> apply(final List<List<T>> value) {
                 switch (value.size()) {
                 case 0:
                     return Collections.emptyList();
diff --git a/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/ReferenceAttributeMapper.java b/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/ReferenceAttributeMapper.java
index 9169b5f..c39afda 100644
--- a/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/ReferenceAttributeMapper.java
+++ b/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/ReferenceAttributeMapper.java
@@ -36,7 +36,6 @@
 import org.forgerock.opendj.ldap.EntryNotFoundException;
 import org.forgerock.opendj.ldap.LdapException;
 import org.forgerock.opendj.ldap.Filter;
-import org.forgerock.opendj.ldap.Function;
 import org.forgerock.opendj.ldap.LinkedAttribute;
 import org.forgerock.opendj.ldap.MultipleEntriesFoundException;
 import org.forgerock.opendj.ldap.ResultCode;
@@ -46,6 +45,8 @@
 import org.forgerock.opendj.ldap.responses.Result;
 import org.forgerock.opendj.ldap.responses.SearchResultEntry;
 import org.forgerock.opendj.ldap.responses.SearchResultReference;
+import org.forgerock.util.promise.Function;
+import org.forgerock.util.promise.NeverThrowsException;
 import org.forgerock.util.promise.FailureHandler;
 import org.forgerock.util.promise.SuccessHandler;
 
@@ -298,9 +299,9 @@
             try {
                 final Set<DN> dns = attribute.parse().usingSchema(c.getConfig().schema()).asSetOfDN();
                 final ResultHandler<JsonValue> handler =
-                    accumulate(dns.size(), transform(new Function<List<JsonValue>, JsonValue, Void>() {
+                    accumulate(dns.size(), transform(new Function<List<JsonValue>, JsonValue, NeverThrowsException>() {
                         @Override
-                        public JsonValue apply(final List<JsonValue> value, final Void p) {
+                        public JsonValue apply(final List<JsonValue> value) {
                             if (value.isEmpty()) {
                                 /*
                                  * No values, so omit the entire JSON object
diff --git a/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/SimpleAttributeMapper.java b/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/SimpleAttributeMapper.java
index a22bd61..bbb43a9 100644
--- a/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/SimpleAttributeMapper.java
+++ b/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/SimpleAttributeMapper.java
@@ -11,23 +11,10 @@
  * Header, with the fields enclosed by brackets [] replaced by your own identifying
  * information: "Portions Copyright [year] [name of copyright owner]".
  *
- * Copyright 2012-2013 ForgeRock AS.
+ * Copyright 2012-2014 ForgeRock AS.
  */
 package org.forgerock.opendj.rest2ldap;
 
-import static java.util.Collections.emptyList;
-import static java.util.Collections.singletonList;
-import static org.forgerock.opendj.ldap.Filter.alwaysFalse;
-import static org.forgerock.opendj.ldap.Functions.fixedFunction;
-import static org.forgerock.opendj.rest2ldap.Rest2LDAP.asResourceException;
-import static org.forgerock.opendj.rest2ldap.Utils.base64ToByteString;
-import static org.forgerock.opendj.rest2ldap.Utils.byteStringToBase64;
-import static org.forgerock.opendj.rest2ldap.Utils.byteStringToJson;
-import static org.forgerock.opendj.rest2ldap.Utils.i18n;
-import static org.forgerock.opendj.rest2ldap.Utils.jsonToAttribute;
-import static org.forgerock.opendj.rest2ldap.Utils.jsonToByteString;
-import static org.forgerock.opendj.rest2ldap.Utils.toFilter;
-
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Set;
@@ -41,15 +28,22 @@
 import org.forgerock.opendj.ldap.ByteString;
 import org.forgerock.opendj.ldap.Entry;
 import org.forgerock.opendj.ldap.Filter;
-import org.forgerock.opendj.ldap.Function;
+import org.forgerock.util.promise.Function;
+import org.forgerock.util.promise.NeverThrowsException;
+
+import static java.util.Collections.*;
+
+import static org.forgerock.opendj.ldap.Filter.*;
+import static org.forgerock.opendj.rest2ldap.Rest2LDAP.*;
+import static org.forgerock.opendj.rest2ldap.Utils.*;
 
 /**
  * An attribute mapper which provides a simple mapping from a JSON value to a
  * single LDAP attribute.
  */
 public final class SimpleAttributeMapper extends AbstractLDAPAttributeMapper<SimpleAttributeMapper> {
-    private Function<ByteString, ?, Void> decoder = null;
-    private Function<Object, ByteString, Void> encoder = null;
+    private Function<ByteString, ?, NeverThrowsException> decoder;
+    private Function<Object, ByteString, NeverThrowsException> encoder;
 
     SimpleAttributeMapper(final AttributeDescription ldapAttributeName) {
         super(ldapAttributeName);
@@ -63,7 +57,7 @@
      *            The function to use for decoding LDAP attribute values.
      * @return This attribute mapper.
      */
-    public SimpleAttributeMapper decoder(final Function<ByteString, ?, Void> f) {
+    public SimpleAttributeMapper decoder(final Function<ByteString, ?, NeverThrowsException> f) {
         this.decoder = f;
         return this;
     }
@@ -89,7 +83,7 @@
      *            The function to use for encoding LDAP attribute values.
      * @return This attribute mapper.
      */
-    public SimpleAttributeMapper encoder(final Function<Object, ByteString, Void> f) {
+    public SimpleAttributeMapper encoder(final Function<Object, ByteString, NeverThrowsException> f) {
         this.encoder = f;
         return this;
     }
@@ -123,7 +117,7 @@
         if (subPath.isEmpty()) {
             try {
                 final ByteString va =
-                        valueAssertion != null ? encoder().apply(valueAssertion, null) : null;
+                        valueAssertion != null ? encoder().apply(valueAssertion) : null;
                 h.handleResult(toFilter(c, type, ldapAttributeName.toString(), va));
             } catch (final Exception e) {
                 // Invalid assertion value - bad request.
@@ -176,12 +170,12 @@
         }
     }
 
-    private Function<ByteString, ? extends Object, Void> decoder() {
-        return decoder == null ? fixedFunction(byteStringToJson(), ldapAttributeName) : decoder;
+    private Function<ByteString, ? extends Object, NeverThrowsException> decoder() {
+        return decoder == null ? byteStringToJson(ldapAttributeName) : decoder;
     }
 
-    private Function<Object, ByteString, Void> encoder() {
-        return encoder == null ? fixedFunction(jsonToByteString(), ldapAttributeName) : encoder;
+    private Function<Object, ByteString, NeverThrowsException> encoder() {
+        return encoder == null ? jsonToByteString(ldapAttributeName) : encoder;
     }
 
 }
diff --git a/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Utils.java b/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Utils.java
index 987edf2..c67cba4 100644
--- a/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Utils.java
+++ b/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Utils.java
@@ -11,7 +11,7 @@
  * Header, with the fields enclosed by brackets [] replaced by your own identifying
  * information: "Portions Copyright [year] [name of copyright owner]".
  *
- * Copyright 2012-2013 ForgeRock AS.
+ * Copyright 2012-2014 ForgeRock AS.
  */
 package org.forgerock.opendj.rest2ldap;
 
@@ -22,7 +22,6 @@
 import static org.forgerock.opendj.ldap.Functions.byteStringToGeneralizedTime;
 import static org.forgerock.opendj.ldap.Functions.byteStringToLong;
 import static org.forgerock.opendj.ldap.Functions.byteStringToString;
-import static org.forgerock.opendj.ldap.Functions.fixedFunction;
 import static org.forgerock.opendj.ldap.schema.CoreSchema.getBooleanSyntax;
 import static org.forgerock.opendj.ldap.schema.CoreSchema.getGeneralizedTimeSyntax;
 import static org.forgerock.opendj.ldap.schema.CoreSchema.getIntegerSyntax;
@@ -42,10 +41,11 @@
 import org.forgerock.opendj.ldap.AttributeDescription;
 import org.forgerock.opendj.ldap.ByteString;
 import org.forgerock.opendj.ldap.Filter;
-import org.forgerock.opendj.ldap.Function;
 import org.forgerock.opendj.ldap.GeneralizedTime;
 import org.forgerock.opendj.ldap.LinkedAttribute;
 import org.forgerock.opendj.ldap.schema.Syntax;
+import org.forgerock.util.promise.Function;
+import org.forgerock.util.promise.NeverThrowsException;
 
 /**
  * Internal utility methods.
@@ -109,59 +109,22 @@
         }
     }
 
-    private static final Function<Object, ByteString, Void> BASE64_TO_BYTESTRING =
-            new Function<Object, ByteString, Void>() {
+    private static final Function<Object, ByteString, NeverThrowsException> BASE64_TO_BYTESTRING =
+            new Function<Object, ByteString, NeverThrowsException>() {
                 @Override
-                public ByteString apply(final Object value, final Void p) {
+                public ByteString apply(final Object value) {
                     return ByteString.valueOfBase64(String.valueOf(value));
                 }
             };
 
-    private static final Function<ByteString, String, Void> BYTESTRING_TO_BASE64 =
-            new Function<ByteString, String, Void>() {
+    private static final Function<ByteString, String, NeverThrowsException> BYTESTRING_TO_BASE64 =
+            new Function<ByteString, String, NeverThrowsException>() {
                 @Override
-                public String apply(final ByteString value, final Void p) {
+                public String apply(final ByteString value) {
                     return value.toBase64String();
                 }
             };
 
-    private static final Function<ByteString, Object, AttributeDescription> BYTESTRING_TO_JSON =
-            new Function<ByteString, Object, AttributeDescription>() {
-                @Override
-                public Object apply(final ByteString value, final AttributeDescription ad) {
-                    final Syntax syntax = ad.getAttributeType().getSyntax();
-                    if (syntax.equals(getBooleanSyntax())) {
-                        return byteStringToBoolean().apply(value, null);
-                    } else if (syntax.equals(getIntegerSyntax())) {
-                        return byteStringToLong().apply(value, null);
-                    } else if (syntax.equals(getGeneralizedTimeSyntax())) {
-                        return printDateTime(byteStringToGeneralizedTime().apply(value, null)
-                                .toCalendar());
-                    } else {
-                        return byteStringToString().apply(value, null);
-                    }
-                }
-            };
-
-    private static final Function<Object, ByteString, AttributeDescription> JSON_TO_BYTESTRING =
-            new Function<Object, ByteString, AttributeDescription>() {
-                @Override
-                public ByteString apply(final Object value, final AttributeDescription ad) {
-                    if (isJSONPrimitive(value)) {
-                        final Syntax syntax = ad.getAttributeType().getSyntax();
-                        if (syntax.equals(getGeneralizedTimeSyntax())) {
-                            return ByteString.valueOf(GeneralizedTime.valueOf(parseDateTime(value
-                                    .toString())));
-                        } else {
-                            return ByteString.valueOf(value);
-                        }
-                    } else {
-                        throw new IllegalArgumentException("Unrecognized type of JSON value: "
-                                + value.getClass().getName());
-                    }
-                }
-            };
-
     /**
      * Returns a result handler which can be used to collect the results of
      * {@code size} asynchronous operations. Once all results have been received
@@ -188,23 +151,36 @@
     }
 
     static Object attributeToJson(final Attribute a) {
-        final Function<ByteString, Object, Void> f =
-                fixedFunction(BYTESTRING_TO_JSON, a.getAttributeDescription());
-        final boolean isSingleValued =
-                a.getAttributeDescription().getAttributeType().isSingleValue();
+        final Function<ByteString, Object, NeverThrowsException> f = byteStringToJson(a.getAttributeDescription());
+        final boolean isSingleValued = a.getAttributeDescription().getAttributeType().isSingleValue();
         return isSingleValued ? a.parse().as(f) : asList(a.parse().asSetOf(f));
     }
 
-    static Function<Object, ByteString, Void> base64ToByteString() {
+    static Function<Object, ByteString, NeverThrowsException> base64ToByteString() {
         return BASE64_TO_BYTESTRING;
     }
 
-    static Function<ByteString, String, Void> byteStringToBase64() {
+    static Function<ByteString, String, NeverThrowsException> byteStringToBase64() {
         return BYTESTRING_TO_BASE64;
     }
 
-    static Function<ByteString, Object, AttributeDescription> byteStringToJson() {
-        return BYTESTRING_TO_JSON;
+    static Function<ByteString, Object, NeverThrowsException> byteStringToJson(final AttributeDescription ad) {
+        return new Function<ByteString, Object, NeverThrowsException>() {
+            @Override
+            public Object apply(final ByteString value) {
+                final Syntax syntax = ad.getAttributeType().getSyntax();
+                if (syntax.equals(getBooleanSyntax())) {
+                    return byteStringToBoolean().apply(value);
+                } else if (syntax.equals(getIntegerSyntax())) {
+                    return byteStringToLong().apply(value);
+                } else if (syntax.equals(getGeneralizedTimeSyntax())) {
+                    return printDateTime(byteStringToGeneralizedTime().apply(value)
+                            .toCalendar());
+                } else {
+                    return byteStringToString().apply(value);
+                }
+            }
+        };
     }
 
     static <T> T ensureNotNull(final T object) {
@@ -247,17 +223,17 @@
     }
 
     static Attribute jsonToAttribute(final Object value, final AttributeDescription ad) {
-        return jsonToAttribute(value, ad, fixedFunction(jsonToByteString(), ad));
+        return jsonToAttribute(value, ad, jsonToByteString(ad));
     }
 
     static Attribute jsonToAttribute(final Object value, final AttributeDescription ad,
-            final Function<Object, ByteString, Void> f) {
+            final Function<Object, ByteString, NeverThrowsException> f) {
         if (isJSONPrimitive(value)) {
-            return new LinkedAttribute(ad, f.apply(value, null));
+            return new LinkedAttribute(ad, f.apply(value));
         } else if (value instanceof Collection<?>) {
             final Attribute a = new LinkedAttribute(ad);
             for (final Object o : (Collection<?>) value) {
-                a.add(f.apply(o, null));
+                a.add(f.apply(o));
             }
             return a;
         } else {
@@ -266,8 +242,23 @@
         }
     }
 
-    static Function<Object, ByteString, AttributeDescription> jsonToByteString() {
-        return JSON_TO_BYTESTRING;
+    static Function<Object, ByteString, NeverThrowsException> jsonToByteString(final AttributeDescription ad) {
+        return new Function<Object, ByteString, NeverThrowsException>() {
+            @Override
+            public ByteString apply(final Object value) {
+                if (isJSONPrimitive(value)) {
+                    final Syntax syntax = ad.getAttributeType().getSyntax();
+                    if (syntax.equals(getGeneralizedTimeSyntax())) {
+                        return ByteString.valueOf(GeneralizedTime.valueOf(parseDateTime(value.toString())));
+                    } else {
+                        return ByteString.valueOf(value);
+                    }
+                } else {
+                    throw new IllegalArgumentException("Unrecognized type of JSON value: "
+                            + value.getClass().getName());
+                }
+            }
+        };
     }
 
     static Filter toFilter(final boolean value) {
@@ -335,7 +326,7 @@
      *            A result handler which accepts results of type {@code N}.
      * @return A result handler which accepts results of type {@code M}.
      */
-    static <M, N> ResultHandler<M> transform(final Function<M, N, Void> f,
+    static <M, N> ResultHandler<M> transform(final Function<M, N, NeverThrowsException> f,
             final ResultHandler<N> handler) {
         return new ResultHandler<M>() {
             @Override
@@ -346,7 +337,7 @@
             @Override
             public void handleResult(final M result) {
                 try {
-                    handler.handleResult(f.apply(result, null));
+                    handler.handleResult(f.apply(result));
                 } catch (final Throwable t) {
                     handler.handleError(asResourceException(t));
                 }

--
Gitblit v1.10.0