Transition the Normalizer class to call ICU4j.

The following benchmarks were obtained by running parts of NormalizerTest
through caliper.
            benchmark    us linear runtime
    ICU4cIsNormalized  5.09 ======
    ICU4jIsNormalized  5.22 ======
       ICU4cNormalize 22.56 ==============================
       ICU4jNormalize 21.97 =============================

NormalizerTest still passes after this change on Shamu. This change also
removes the JNI calls and their associated C++ wrappers.

Change-Id: I9081c899a76fdb3a341ca5ecd54c32cd6e6a0387
diff --git a/luni/src/main/java/java/text/Normalizer.java b/luni/src/main/java/java/text/Normalizer.java
index 2e6647e..5355014 100644
--- a/luni/src/main/java/java/text/Normalizer.java
+++ b/luni/src/main/java/java/text/Normalizer.java
@@ -16,8 +16,6 @@
 
 package java.text;
 
-import libcore.icu.NativeNormalizer;
-
 /**
  * Provides normalization functions according to
  * <a href="http://www.unicode.org/unicode/reports/tr15/tr15-23.html">Unicode Standard Annex #15:
@@ -36,22 +34,32 @@
         /**
          * Normalization Form D - Canonical Decomposition.
          */
-        NFD,
+        NFD(com.ibm.icu.text.Normalizer.NFD),
 
         /**
          * Normalization Form C - Canonical Decomposition, followed by Canonical Composition.
          */
-        NFC,
+        NFC(com.ibm.icu.text.Normalizer.NFC),
 
         /**
          * Normalization Form KD - Compatibility Decomposition.
          */
-        NFKD,
+        NFKD(com.ibm.icu.text.Normalizer.NFKD),
 
         /**
          * Normalization Form KC - Compatibility Decomposition, followed by Canonical Composition.
          */
-        NFKC;
+        NFKC(com.ibm.icu.text.Normalizer.NFKC);
+
+        private final com.ibm.icu.text.Normalizer.Mode icuForm;
+
+        Form(com.ibm.icu.text.Normalizer.Mode icuForm) {
+            this.icuForm = icuForm;
+        }
+
+        com.ibm.icu.text.Normalizer.Mode getIcuForm() {
+            return icuForm;
+        }
     }
 
     /**
@@ -63,7 +71,7 @@
      * @return true if normalized according to <code>form</code>
      */
     public static boolean isNormalized(CharSequence src, Form form) {
-        return NativeNormalizer.isNormalized(src, form);
+        return com.ibm.icu.text.Normalizer.isNormalized(src.toString(), form.getIcuForm(), 0);
     }
 
     /**
@@ -75,7 +83,7 @@
      * @return string normalized according to <code>form</code>
      */
     public static String normalize(CharSequence src, Form form) {
-        return NativeNormalizer.normalize(src, form);
+        return com.ibm.icu.text.Normalizer.normalize(src.toString(), form.getIcuForm());
     }
 
     private Normalizer() {}
diff --git a/luni/src/main/java/libcore/icu/NativeNormalizer.java b/luni/src/main/java/libcore/icu/NativeNormalizer.java
deleted file mode 100644
index a5d8da2..0000000
--- a/luni/src/main/java/libcore/icu/NativeNormalizer.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package libcore.icu;
-
-import java.text.Normalizer.Form;
-
-public final class NativeNormalizer {
-    public static boolean isNormalized(CharSequence src, Form form) {
-        return isNormalizedImpl(src.toString(), toUNormalizationMode(form));
-    }
-
-    public static String normalize(CharSequence src, Form form) {
-        return normalizeImpl(src.toString(), toUNormalizationMode(form));
-    }
-
-    private static int toUNormalizationMode(Form form) {
-        // Translates Java enum constants to ICU int constants.
-        // See UNormalizationMode in "unicode/unorm.h". Stable API since ICU 2.0.
-        switch (form) {
-        case NFC: return 4;
-        case NFD: return 2;
-        case NFKC: return 5;
-        case NFKD: return 3;
-        }
-        throw new AssertionError("unknown Normalizer.Form " + form);
-    }
-
-    private static native String normalizeImpl(String src, int form);
-
-    private static native boolean isNormalizedImpl(String src, int form);
-
-    private NativeNormalizer() {}
-}
diff --git a/luni/src/main/native/Register.cpp b/luni/src/main/native/Register.cpp
index 787a149..c1142aa 100644
--- a/luni/src/main/native/Register.cpp
+++ b/luni/src/main/native/Register.cpp
@@ -61,7 +61,6 @@
     REGISTER(register_libcore_icu_NativeConverter);
     REGISTER(register_libcore_icu_NativeDecimalFormat);
     REGISTER(register_libcore_icu_NativeIDN);
-    REGISTER(register_libcore_icu_NativeNormalizer);
     REGISTER(register_libcore_icu_NativePluralRules);
     REGISTER(register_libcore_icu_TimeZoneNames);
     REGISTER(register_libcore_icu_Transliterator);
diff --git a/luni/src/main/native/libcore_icu_NativeNormalizer.cpp b/luni/src/main/native/libcore_icu_NativeNormalizer.cpp
deleted file mode 100644
index 2d5e282..0000000
--- a/luni/src/main/native/libcore_icu_NativeNormalizer.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define LOG_TAG "NativeNormalizer"
-
-#include "IcuUtilities.h"
-#include "JNIHelp.h"
-#include "JniConstants.h"
-#include "JniException.h"
-#include "ScopedJavaUnicodeString.h"
-#include "unicode/normlzr.h"
-
-static jstring NativeNormalizer_normalizeImpl(JNIEnv* env, jclass, jstring s, jint intMode) {
-  ScopedJavaUnicodeString src(env, s);
-  if (!src.valid()) {
-    return NULL;
-  }
-  UNormalizationMode mode = static_cast<UNormalizationMode>(intMode);
-  UErrorCode status = U_ZERO_ERROR;
-  icu::UnicodeString dst;
-  icu::Normalizer::normalize(src.unicodeString(), mode, 0, dst, status);
-  maybeThrowIcuException(env, "Normalizer::normalize", status);
-  return dst.isBogus() ? NULL : env->NewString(dst.getBuffer(), dst.length());
-}
-
-static jboolean NativeNormalizer_isNormalizedImpl(JNIEnv* env, jclass, jstring s, jint intMode) {
-  ScopedJavaUnicodeString src(env, s);
-  if (!src.valid()) {
-    return JNI_FALSE;
-  }
-  UNormalizationMode mode = static_cast<UNormalizationMode>(intMode);
-  UErrorCode status = U_ZERO_ERROR;
-  UBool result = icu::Normalizer::isNormalized(src.unicodeString(), mode, status);
-  maybeThrowIcuException(env, "Normalizer::isNormalized", status);
-  return result;
-}
-
-static JNINativeMethod gMethods[] = {
-  NATIVE_METHOD(NativeNormalizer, normalizeImpl, "(Ljava/lang/String;I)Ljava/lang/String;"),
-  NATIVE_METHOD(NativeNormalizer, isNormalizedImpl, "(Ljava/lang/String;I)Z"),
-};
-void register_libcore_icu_NativeNormalizer(JNIEnv* env) {
-  jniRegisterNativeMethods(env, "libcore/icu/NativeNormalizer", gMethods, NELEM(gMethods));
-}
diff --git a/luni/src/main/native/sub.mk b/luni/src/main/native/sub.mk
index 78ec37a..84141db 100644
--- a/luni/src/main/native/sub.mk
+++ b/luni/src/main/native/sub.mk
@@ -41,7 +41,6 @@
     libcore_icu_NativeConverter.cpp \
     libcore_icu_NativeDecimalFormat.cpp \
     libcore_icu_NativeIDN.cpp \
-    libcore_icu_NativeNormalizer.cpp \
     libcore_icu_NativePluralRules.cpp \
     libcore_icu_TimeZoneNames.cpp \
     libcore_icu_Transliterator.cpp \