아래 클래스는 줄마다 단어의 위치를 색인화합니다. 오류를 발생시키는 방법은 현재 색인에 별도의 문서 색인을 추가하는 것입니다. 즉, 첫 번째 문서의 6 개 라인이있는 경우, 첨부 문서의 첫 번째 라인은 내가 잘못 뭐하는 거지 라인 7.ArrayList가있는 각 루프에 NoSuchElementException이 발생했습니다. <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
@Fuhrmanator - 공정하기 위해서, 우리는 오케 스타의 강사가 잘못한 것인지 알 수 없습니다. –
강사로서 나는 공식적인 직후에 그것을 사용하고 있었지만 "새로운"java 다음에 숙제를 업데이트하지 않았다고 유죄를 나타 냈습니다. 어딘가에있는 일부 강사는 구문에 "새"를 사용하지 않습니다 ... – Fuhrmanator