Coverage Summary for Class: JDKTextNormalizer (com.acciente.oacc.normalizer.jdk)

Class Method, % Line, %
JDKTextNormalizer 100% (4/ 4) 100% (5/ 5)
JDKTextNormalizer$LazyInitSingletonHolder 100% (2/ 2) 100% (2/ 2)
total 100% (6/ 6) 100% (7/ 7)


1 /* 2  * Copyright 2009-2018, Acciente LLC 3  * 4  * Acciente LLC licenses this file to you under the 5  * Apache License, Version 2.0 (the "License"); you 6  * may not use this file except in compliance with the 7  * License. You may obtain a copy of the License at 8  * 9  * http://www.apache.org/licenses/LICENSE-2.0 10  * 11  * Unless required by applicable law or agreed to in 12  * writing, software distributed under the License is 13  * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES 14  * OR CONDITIONS OF ANY KIND, either express or implied. 15  * See the License for the specific language governing 16  * permissions and limitations under the License. 17  */ 18  19 package com.acciente.oacc.normalizer.jdk; 20  21 import com.acciente.oacc.normalizer.TextNormalizer; 22  23 import java.nio.CharBuffer; 24 import java.text.Normalizer; 25  26 public class JDKTextNormalizer extends TextNormalizer { 27  // we use the singleton holder pattern to lazy initialize the singleton instance 28  // in a thread safe manner without the need for any explicit locking 29  // (see https://en.wikipedia.org/wiki/Initialization-on-demand_holder_idiom). 30  private static class LazyInitSingletonHolder { 31  private static final TextNormalizer INSTANCE = new JDKTextNormalizer(); 32  } 33  34  private JDKTextNormalizer() { 35  } 36  37  public static TextNormalizer getInstance() { 38  return LazyInitSingletonHolder.INSTANCE; 39  } 40  41  @Override 42  public char[] normalizeToNfc(char[] source) { 43  return Normalizer.normalize(CharBuffer.wrap(source), Normalizer.Form.NFC).toCharArray(); 44  } 45 }