/** * @param key 搜索使用的KeyWord * @param lastSearched 上次已搜索到的结果 * @param start 在搜索结果集中进行搜索时起始的id default:0 * @param limit 搜索集合的结果数量限制 default:0 无限制 * @param filter 过滤器 default:0 当前未使用 * @param isT9 是否对key进行T9映射 * @return SearchInfo[] 所有结果都已经返回,以内置的MatchType进行区分。 */ public SearchInfo<T>[] javaSearchAll( 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; @SuppressWarnings("unchecked") SearchInfo<T>[] result = new SearchInfo[resultArray.length - 1]; MATCH_TYPE matchType = MATCH_TYPE.NameMatch; for (int i = 0, j = 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; } result[i] = srcInfos[primaryKey].clone(); result[i].cOrder = i; result[i].matchType = matchType; result[i].matchPhoneID = phoneIndex; i++; } return result; }
/** * @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; }