]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-52_1/main/tests/framework/src/com/ibm/icu/dev/util/UnicodeTransform.java
Upgrade ICU4J.
[Dictionary.git] / jars / icu4j-52_1 / main / tests / framework / src / com / ibm / icu / dev / util / UnicodeTransform.java
1 /*
2  *******************************************************************************
3  * Copyright (C) 2011-2012, Google, International Business Machines Corporation and         *
4  * others. All Rights Reserved.                                                *
5  *******************************************************************************
6  */
7 package com.ibm.icu.dev.util;
8
9 import com.ibm.icu.text.Transform;
10 import com.ibm.icu.text.UTF16;
11
12 /**
13  * Simple wrapping for normalizer that allows for both the standard ICU normalizer, and one built directly from the UCD.
14  */
15 public abstract class UnicodeTransform implements Transform<String,String> {
16     public enum Type {
17         NFD, NFC, NFKD, NFKC, CASEFOLD
18     }
19     
20     public interface Factory {
21         public UnicodeTransform getInstance(Type type);
22     }
23     
24     private static Factory factory = new IcuUnicodeNormalizerFactory();
25     
26     public static synchronized Factory getFactory() {
27         return factory;
28     }
29
30     public static synchronized void setFactory(Factory factory) {
31         UnicodeTransform.factory = factory;
32     }
33
34     public static synchronized UnicodeTransform getInstance(Type type) {
35         return factory.getInstance(type);
36     }
37     
38     public abstract String transform(String source);
39     
40     /**
41      * Can be overridden for performance.
42      */
43     public boolean isTransformed(String source) {
44         return source.equals(transform(source));
45     }
46     /**
47      * Can be overridden for performance.
48      */
49     public String transform(int source) {
50         return transform(UTF16.valueOf(source));
51     }
52     /**
53      * Can be overridden for performance.
54      */
55     public boolean isTransformed(int source) {
56         return isTransformed(UTF16.valueOf(source));
57     }
58 }
59