📄 rbtablebuilder.java
字号:
lastValue += TERTIARYORDERINCREMENT; // record max # of ignorable chars with tertiary difference if (!isOverIgnore) maxTerOrder++; break; } return lastValue; } /** * Adds a character and its designated order into the collation table. */ private final void addOrder(char ch, int anOrder) { // See if the char already has an order in the mapping table int order = mapping.elementAt(ch); if (order >= RBCollationTables.CONTRACTCHARINDEX) { // There's already an entry for this character that points to a contracting // character table. Instead of adding the character directly to the mapping // table, we must add it to the contract table instead. key.setLength(0); key.append(ch); addContractOrder(key.toString(), anOrder); } else { // add the entry to the mapping table, // the same later entry replaces the previous one mapping.setElementAt(ch, anOrder); } } private final void addContractOrder(String groupChars, int anOrder) { addContractOrder(groupChars, anOrder, true); } /** * Adds the contracting string into the collation table. */ private final void addContractOrder(String groupChars, int anOrder, boolean fwd) { if (contractTable == null) { contractTable = new Vector(INITIALTABLESIZE); } // See if the initial character of the string already has a contract table. int entry = mapping.elementAt(groupChars.charAt(0)); Vector entryTable = getContractValues(entry - RBCollationTables.CONTRACTCHARINDEX); if (entryTable == null) { // We need to create a new table of contract entries for this base char int tableIndex = RBCollationTables.CONTRACTCHARINDEX + contractTable.size(); entryTable = new Vector(INITIALTABLESIZE); contractTable.addElement(entryTable); // Add the initial character's current ordering first. then // update its mapping to point to this contract table entryTable.addElement(new EntryPair(groupChars.substring(0,1), entry)); mapping.setElementAt(groupChars.charAt(0), tableIndex); } // Now add (or replace) this string in the table int index = RBCollationTables.getEntry(entryTable, groupChars, fwd); if (index != RBCollationTables.UNMAPPED) { EntryPair pair = (EntryPair) entryTable.elementAt(index); pair.value = anOrder; } else { EntryPair pair = (EntryPair)entryTable.lastElement(); // NOTE: This little bit of logic is here to speed CollationElementIterator // .nextContractChar(). This code ensures that the longest sequence in // this list is always the _last_ one in the list. This keeps // nextContractChar() from having to search the entire list for the longest // sequence. if (groupChars.length() > pair.entryName.length()) { entryTable.addElement(new EntryPair(groupChars, anOrder, fwd)); } else { entryTable.insertElementAt(new EntryPair(groupChars, anOrder, fwd), entryTable.size() - 1); } } // If this was a forward mapping for a contracting string, also add a // reverse mapping for it, so that CollationElementIterator.previous // can work right if (fwd && groupChars.length() > 1) { addContractFlags(groupChars); addContractOrder(new StringBuffer(groupChars).reverse().toString(), anOrder, false); } } /** * If the given string has been specified as a contracting string * in this collation table, return its ordering. * Otherwise return UNMAPPED. */ private int getContractOrder(String groupChars) { int result = RBCollationTables.UNMAPPED; if (contractTable != null) { Vector entryTable = getContractValues(groupChars.charAt(0)); if (entryTable != null) { int index = RBCollationTables.getEntry(entryTable, groupChars, true); if (index != RBCollationTables.UNMAPPED) { EntryPair pair = (EntryPair) entryTable.elementAt(index); result = pair.value; } } } return result; } private final int getCharOrder(char ch) { int order = mapping.elementAt(ch); if (order >= RBCollationTables.CONTRACTCHARINDEX) { Vector groupList = getContractValues(order - RBCollationTables.CONTRACTCHARINDEX); EntryPair pair = (EntryPair)groupList.firstElement(); order = pair.value; } return order; } /** * Get the entry of hash table of the contracting string in the collation * table. * @param ch the starting character of the contracting string */ Vector getContractValues(char ch) { int index = mapping.elementAt(ch); return getContractValues(index - RBCollationTables.CONTRACTCHARINDEX); } Vector getContractValues(int index) { if (index >= 0) { return (Vector)contractTable.elementAt(index); } else // not found { return null; } } /** * Adds the expanding string into the collation table. */ private final void addExpandOrder(String contractChars, String expandChars, int anOrder) throws ParseException { // Create an expansion table entry int tableIndex = addExpansion(anOrder, expandChars); // And add its index into the main mapping table if (contractChars.length() > 1) { addContractOrder(contractChars, tableIndex); } else { addOrder(contractChars.charAt(0), tableIndex); } } /** * Create a new entry in the expansion table that contains the orderings * for the given characers. If anOrder is valid, it is added to the * beginning of the expanded list of orders. */ private int addExpansion(int anOrder, String expandChars) { if (expandTable == null) { expandTable = new Vector(INITIALTABLESIZE); } // If anOrder is valid, we want to add it at the beginning of the list int offset = (anOrder == RBCollationTables.UNMAPPED) ? 0 : 1; int[] valueList = new int[expandChars.length() + offset]; if (offset == 1) { valueList[0] = anOrder; } for (int i = 0; i < expandChars.length(); i++) { char ch = expandChars.charAt(i); int mapValue = getCharOrder(ch); if (mapValue != RBCollationTables.UNMAPPED) { valueList[i+offset] = mapValue; } else { // can't find it in the table, will be filled in by commit(). valueList[i+offset] = CHARINDEX + (int)ch; } } // Add the expanding char list into the expansion table. int tableIndex = RBCollationTables.EXPANDCHARINDEX + expandTable.size(); expandTable.addElement(valueList); return tableIndex; } private void addContractFlags(String chars) { char c; int len = chars.length(); for (int i = 0; i < len; i++) { c = chars.charAt(i); contractFlags.put(c, 1); } } // ============================================================== // constants // ============================================================== final static int CHARINDEX = 0x70000000; // need look up in .commit() private final static int IGNORABLEMASK = 0x0000ffff; private final static int PRIMARYORDERINCREMENT = 0x00010000; private final static int SECONDARYORDERINCREMENT = 0x00000100; private final static int TERTIARYORDERINCREMENT = 0x00000001; private final static int INITIALTABLESIZE = 20; private final static int MAXKEYSIZE = 5; // ============================================================== // instance variables // ============================================================== // variables used by the build process private RBCollationTables.BuildAPI tables = null; private MergeCollation mPattern = null; private boolean isOverIgnore = false; private StringBuffer key = new StringBuffer(MAXKEYSIZE); private IntHashtable contractFlags = new IntHashtable(100); // "shadow" copies of the instance variables in RBCollationTables // (the values in these variables are copied back into RBCollationTables // at the end of the build process) private boolean frenchSec = false; private boolean seAsianSwapping = false; private CompactIntArray mapping = null; private Vector contractTable = null; private Vector expandTable = null; private short maxSecOrder = 0; private short maxTerOrder = 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -