< prev index next >

src/java.base/share/classes/sun/text/normalizer/Norm2AllModes.java

Print this page
rev 54996 : 8221431: Support for Unicode 12.1
Reviewed-by:
   1 /*
   2  * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 248     private static Norm2AllModes getInstanceFromSingleton(Norm2AllModesSingleton singleton) {
 249         if(singleton.exception!=null) {
 250             throw singleton.exception;
 251         }
 252         return singleton.allModes;
 253     }
 254 
 255     public static Norm2AllModes getNFCInstance() {
 256         return getInstanceFromSingleton(NFCSingleton.INSTANCE);
 257     }
 258 
 259     public static Norm2AllModes getNFKCInstance() {
 260         return getInstanceFromSingleton(NFKCSingleton.INSTANCE);
 261     }
 262 
 263     public static final NoopNormalizer2 NOOP_NORMALIZER2=new NoopNormalizer2();
 264 
 265     private static final class Norm2AllModesSingleton {
 266         private Norm2AllModesSingleton(String name) {
 267             try {
 268                 String DATA_FILE_NAME = "/sun/text/resources/" + name + ".icu";
 269                 NormalizerImpl impl=new NormalizerImpl().load(DATA_FILE_NAME);
 270                 allModes=new Norm2AllModes(impl);
 271             } catch (RuntimeException e) {
 272                 exception=e;
 273             }
 274         }
 275 
 276         private Norm2AllModes allModes;
 277         private RuntimeException exception;
 278     }
 279 
 280     private static final class NFCSingleton {
 281         private static final Norm2AllModesSingleton INSTANCE=new Norm2AllModesSingleton("nfc");
 282     }
 283 
 284     private static final class NFKCSingleton {
 285         private static final Norm2AllModesSingleton INSTANCE=new Norm2AllModesSingleton("nfkc");
 286     }
 287 }
   1 /*
   2  * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 248     private static Norm2AllModes getInstanceFromSingleton(Norm2AllModesSingleton singleton) {
 249         if(singleton.exception!=null) {
 250             throw singleton.exception;
 251         }
 252         return singleton.allModes;
 253     }
 254 
 255     public static Norm2AllModes getNFCInstance() {
 256         return getInstanceFromSingleton(NFCSingleton.INSTANCE);
 257     }
 258 
 259     public static Norm2AllModes getNFKCInstance() {
 260         return getInstanceFromSingleton(NFKCSingleton.INSTANCE);
 261     }
 262 
 263     public static final NoopNormalizer2 NOOP_NORMALIZER2=new NoopNormalizer2();
 264 
 265     private static final class Norm2AllModesSingleton {
 266         private Norm2AllModesSingleton(String name) {
 267             try {
 268                 String DATA_FILE_NAME = "/sun/text/resources/" + name + ".nrm";
 269                 NormalizerImpl impl=new NormalizerImpl().load(DATA_FILE_NAME);
 270                 allModes=new Norm2AllModes(impl);
 271             } catch (RuntimeException e) {
 272                 exception=e;
 273             }
 274         }
 275 
 276         private Norm2AllModes allModes;
 277         private RuntimeException exception;
 278     }
 279 
 280     private static final class NFCSingleton {
 281         private static final Norm2AllModesSingleton INSTANCE=new Norm2AllModesSingleton("nfc");
 282     }
 283 
 284     private static final class NFKCSingleton {
 285         private static final Norm2AllModesSingleton INSTANCE=new Norm2AllModesSingleton("nfkc");
 286     }
 287 }
< prev index next >