/** * {@link #expression_}から{@link #giFormulae_}を構成します。 戦略<br> * ・一文字ずつ読み込んでアルファベットの大文字がきたら照合<br> * ・ここでキューに文字がある場合はそれを組み合わせて照合する。 ・Propertyに存在しない場合はキューに入れる(キューの上限は1) * ・アルファベット大文字以外の文字がきたらキューをクリアーして表示文字に追加 */ public void setup() { List<GiFormula> giFormulaList = new ArrayList<GiFormula>(); StringBuilder text = new StringBuilder(expression_.length()); char queue = CharacterIterator.DONE; CharacterIterator ip = new StringCharacterIterator(expression_); for (char c = ip.first(); c != CharacterIterator.DONE; c = ip.next()) { if (!Strings.isUppercaseRomanAlphabet(c)) { if (queue != CharacterIterator.DONE) { text.append(queue); queue = CharacterIterator.DONE; } text.append(c); continue; } StringBuilder id = new StringBuilder(2); // IDのサイズは高々2 if (queue != CharacterIterator.DONE) { id.append(queue); } id.append(c); SgfId sgfType = UEnum.find(SgfId.class, id.toString()); if ((sgfType == null) || !PropertyType.GAME_INFO.equals(sgfType.propertyType())) { if (queue != CharacterIterator.DONE) { text.append(queue); } queue = c; continue; } if (text.length() != 0) { giFormulaList.add(new GiLabelFormula(text.toString())); text.delete(0, text.length()); } GiTextFormula giTextFormula = new GiTextFormula(sgfType); String value = emptyMap_.get(sgfType); if (value != null) { giTextFormula.setEmpty(value); } List<GiEnum> giEnums = enumMap_.get(sgfType); if (giEnums != null) { for (GiEnum giEnum : giEnums) { String value2 = giEnum.getValue(); if (value2.startsWith("%")) { // $NON-NLS-1$ String key = value2.substring(1); value2 = messages_s_.get(key); giEnum.setValue(value2); } giTextFormula.addEnum(giEnum); } } giFormulaList.add(giTextFormula); queue = CharacterIterator.DONE; } if (text.length() != 0) { giFormulaList.add(new GiLabelFormula(text.toString())); } giFormulae_ = giFormulaList.toArray(new GiFormula[giFormulaList.size()]); }
/** @param giEnum */ public void addEnum(GiEnum giEnum) { ArgumentChecker.throwIfNull(giEnum); List<GiEnum> list = enumMap_.get(giEnum.getSgfId()); if (list == null) { list = new ArrayList<GiEnum>(); enumMap_.put(giEnum.getSgfId(), list); } list.add(giEnum); }