/** * @param searchedInfos 已搜出的结果集合 * @param start 着色操作在结果集合中的起始位置 * @param limit 着色操作的数量限定 * @param keyText 搜索时使用的KeyWord * @param dyeStr 结果使用的着色编码 eg.{<font color=#D64206>} * @author ZhangZhuo * @description 此方法针对全部数据进行着色,使用SearchInfo内建的MATCHTYPE进行区分 */ public void javaGetHighLights( SearchInfo<T>[] searchedInfos, int start, int limit, String keyText, String dyeStr, boolean isT9) { if (searchedInfos.length == 0) throw new IllegalArgumentException("No searched!"); if (start >= searchedInfos.length || start < 0) throw new ArrayIndexOutOfBoundsException(); if (start + limit >= searchedInfos.length) limit = searchedInfos.length - start; int[] lastSearchedIndex = new int[limit]; for (int i = 0; i < limit; i++) lastSearchedIndex[i] = (searchedInfos[start + i].index << 8) | (searchedInfos[start + i].matchPhoneID & 0xFF); String[] resultArray = getHightLights(domainAdr, lastSearchedIndex, keyText, dyeStr, isT9); for (int i = 0; i < limit; i++) { SearchInfo<T> info = searchedInfos[start + i]; if (info.matchType.equals(MATCH_TYPE.NameMatch)) { info.dyeName = resultArray[i]; info.dyePhone = info.phoneNum; } else { info.dyePhone = resultArray[i]; info.dyeName = info.name; } } }
/** * @param key 搜索使用的KeyWord * @param lastSearched 上次已搜索到的结果 * @param start 在搜索结果集中进行搜索时起始的id default:0 * @param limit 搜索集合的结果数量限制 default:0 无限制 * @param filter 过滤器 default:0 当前未使用 * @param isT9 搜索时是否使用T9映射 * @return SearchInfo[][] result[0] 姓名搜索集合,result[1] 号码搜索集合 */ @SuppressWarnings("unchecked") public SearchInfo<T>[][] javaSearch( String key, int[] lastSearched, int start, int limit, long filter, boolean isT9) { if (ReadLock) return null; if (lastSearched != null && lastSearched.length > 0 && (start < 0 || start + limit > lastSearched.length)) throw new IllegalArgumentException("<start>/<limit> is invaild"); int[] resultArray = search(domainAdr, key, lastSearched, start, limit, filter, isT9); if (resultArray == null) return null; SearchInfo<T>[] resultName, resultPhone; int nameArrayLength = 0, phoneArrayLength = 0; MATCH_TYPE matchType = MATCH_TYPE.NameMatch; for (int j = 0, primaryKey = -1; j < resultArray.length; j++) // primaryKey // =-1时用来隔开姓名匹配结果和号码匹配结果 { primaryKey = resultArray[j]; if (primaryKey < 0) { matchType = MATCH_TYPE.PhoneMatch; continue; } if (matchType.equals(MATCH_TYPE.PhoneMatch)) phoneArrayLength++; else nameArrayLength++; } resultName = nameArrayLength > 0 ? new SearchInfo[nameArrayLength] : null; resultPhone = phoneArrayLength > 0 ? new SearchInfo[phoneArrayLength] : null; SearchInfo<T>[][] result = new SearchInfo[2][]; result[Result.FOR_NAME.ordinal()] = resultName; result[Result.FOR_PHONE.ordinal()] = resultPhone; matchType = MATCH_TYPE.NameMatch; for (int i = 0, j = 0, m = 0, n = 0, primaryKey = -1, phoneIndex = -1; j < resultArray.length; j++) // primaryKey // =-1时用来隔开姓名匹配结果和号码匹配结果 { primaryKey = resultArray[j]; if (primaryKey < 0) { matchType = MATCH_TYPE.PhoneMatch; continue; } if (matchType.equals(MATCH_TYPE.PhoneMatch)) { phoneIndex = primaryKey & 0xFF; primaryKey >>>= 8; } SearchInfo<T> info = srcInfos[primaryKey].clone(); info.cOrder = i; info.matchType = matchType; info.matchPhoneID = phoneIndex; i++; if (matchType.equals(MATCH_TYPE.PhoneMatch)) resultPhone[n++] = info; else resultName[m++] = info; } return result; }
/** Returns the path for passed in row. If row is not visible null is returned. */ public TreePath getPathForRow(int row) { if (row >= 0 && row < getRowCount()) { if (root.getPathForRow(row, getRowCount(), info)) { return info.getPath(); } } return null; }
public SearchInfo<T>[] getPrimaryPyIndex(long filter, Map<String, Integer> indexMap) { char[] chars = "abcdefghijklmnopqrstuvwxyz#".toUpperCase().toCharArray(); int[] index = getFirstPyPrimaryKeys(domainAdr, filter); int[] primaryKeys = getInfosPrimaryKeys(domainAdr, filter); if (primaryKeys == null) return null; @SuppressWarnings("unchecked") SearchInfo<T>[] infos = new SearchInfo[primaryKeys.length]; for (int i = 0; i < primaryKeys.length; i++) { infos[i] = srcInfos[primaryKeys[i]].clone(); infos[i].indexInGroup = i; } for (int i = 0, j = -1; i < index.length; i++) { j = index[i]; if (j < 0) continue; SearchInfo<T> info = infos[j]; info.indexTitle = "" + chars[i]; if (indexMap != null) indexMap.put(info.indexTitle, j); } return infos; }
/** * Returns true if there is a row for <code>row</code>. <code>nextRow</code> gives the bounds of * the receiver. Information about the found row is returned in <code>info</code>. This should * be invoked on root with <code>nextRow</code> set to <code>getRowCount</code>(). */ protected boolean getPathForRow(int row, int nextRow, SearchInfo info) { if (this.row == row) { info.node = this; info.isNodeParentNode = false; info.childIndex = childIndex; return true; } FHTreeStateNode child; FHTreeStateNode lastChild = null; for (int counter = 0, maxCounter = getChildCount(); counter < maxCounter; counter++) { child = (FHTreeStateNode) getChildAt(counter); if (child.row > row) { if (counter == 0) { // No node exists for it, and is first. info.node = this; info.isNodeParentNode = true; info.childIndex = row - this.row - 1; return true; } else { // May have been in last child's bounds. int lastChildEndRow = 1 + child.row - (child.childIndex - lastChild.childIndex); if (row < lastChildEndRow) { return lastChild.getPathForRow(row, lastChildEndRow, info); } // Between last child and child, but not in last child info.node = this; info.isNodeParentNode = true; info.childIndex = row - lastChildEndRow + lastChild.childIndex + 1; return true; } } lastChild = child; } // Not in children, but we should have it, offset from // nextRow. if (lastChild != null) { int lastChildEndRow = nextRow - (childCount - lastChild.childIndex) + 1; if (row < lastChildEndRow) { return lastChild.getPathForRow(row, lastChildEndRow, info); } // Between last child and child, but not in last child info.node = this; info.isNodeParentNode = true; info.childIndex = row - lastChildEndRow + lastChild.childIndex + 1; return true; } else { // No children. int retChildIndex = row - this.row - 1; if (retChildIndex >= childCount) { return false; } info.node = this; info.isNodeParentNode = true; info.childIndex = retChildIndex; return true; } }
public void disposeOld() { if (srcInfos != null) for (SearchInfo<T> info : srcInfos) info.dispose(); srcInfos = null; }