下面的類是爲了索引逐行的位置。 引發錯誤的方法意味着在當前索引上附加單獨文檔的索引。也就是說,如果有6條線路的頭文件,附加文件的第一行應該被索引爲7行NoSuchElementException中的每個循環與ArrayList <Integer>
public class DocumentIndex {
// a NavigableMap implementation to store indexed words and their locations
private TreeMap<String, ArrayList<Integer>> map = new TreeMap<String, ArrayList<Integer>>();
/**
* A method to append another index onto the main index
* @param indexAppendix the additional index to be appended onto the main index
*/
public void append(DocumentIndex indexAppendix){
if(indexAppendix == null){
throw new NullPointerException();
}
Integer docEnd = 0; // the last line recorded in the main index
Set<String> set = map.keySet(); // a Set of the key values from map
//select each key
for(Iterator<String> iter = set.iterator(); iter.hasNext();){
String key = iter.next(); // the current key value
// for each key select contents and determine the highest value
for(Iterator<Integer> iter2 = this.find(key).iterator(); iter2.hasNext();){
Integer compare = iter2.next(); // the key index current value
if(compare>docEnd){
docEnd=compare;
}
}
}
// for each key find an index value
for(Iterator<String> iter = set.iterator(); iter.hasNext();){
String key = iter.next(); // the current key value
// for each index value map that value adjusting for the length of the original document
ArrayList<Integer> toAdd = new ArrayList<Integer>();
for(Iterator<Integer> iter2 = this.find(key).iterator(); iter2.hasNext();){
Integer addIter = iter2.next();
toAdd.add(addIter); // the current index value
}
/**
*Below is the loop in which the error is thrown
*/
for(Iterator<Integer> iter3 = toAdd.iterator(); iter.hasNext();){
Integer addIter = iter3.next(); // The error is thrown on this line
map.get(key).add(addIter+docEnd);
}
}
}
我在做什麼錯?
+1因爲導師應該跟上! – Fuhrmanator 2012-04-21 01:45:38
@Fuhrmanator - 公平地說,我們不知道Ocasta的教練是否有過錯。 – 2012-04-21 07:25:12
作爲一名指導老師,即使在我正式使用它之後,我仍然沒有在「新」java :)之後更新我的作業。某處的某位講師未使用「新的」語法... – Fuhrmanator 2012-04-21 14:15:27