/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package com.intuism.ui.autocorrection.phonenumber; import com.intuism.core.utility.StringUtility; import com.intuism.ui.autocorrection.Corrector; import com.intuism.ui.form.text.caret.Caret; import java.util.Arrays; import java.util.Iterator; import java.util.List; /** * * @author Randahl Fink Isaksen */ public class GlobalPhoneNumberCorrector implements Corrector { private static GlobalPhoneNumberCorrector instance = new GlobalPhoneNumberCorrector(); private static List nationalCorrectors = Arrays.asList( UsPhoneNumberCorrector.getInstance(), DanishPhoneNumberCorrector.getInstance() ); private GlobalPhoneNumberCorrector() {} public static GlobalPhoneNumberCorrector getInstance() {return instance;} @Override public void correct(Caret caret) { String text = caret.getText(); text = StringUtility.clearWhitespace(text); Iterator i = nationalCorrectors.iterator(); NationalPhoneNumberCorrector corrector = null; while(corrector == null && i.hasNext()) { NationalPhoneNumberCorrector candidate = i.next(); if(text.startsWith(candidate.getCountryCode())) corrector = candidate; } if(corrector != null) corrector.correct(caret); } }