我遇到了导致 IllegalStateException 的迭代器删除问题。错误发生在
depIterator.remove() 我不确定为什么会这样。任何帮助,将不胜感激。
List<Dependency> listofAllDependency = new ArrayList<Dependency>();
while(!dependencyTable.isEmpty()){
//allValuesDependentsAreBuilt = false;
Iterator<Entry<Dependency, List<Dependency>>> depIterator = dependencyTable.entrySet().iterator();
while(depIterator.hasNext()){
ArrayList<String> allValuesDependentsAreBuilt = new ArrayList<String>();
Entry<Dependency, List<Dependency>> depEntry = depIterator.next();
//If the key's values have no dependencies
if(depEntry.getValue().size()==0){
//System.out.println(depEntry.getKey());
listofAllDependency.add(depEntry.getKey());
dependencyTable.remove(depEntry);
depIterator.remove();
}
for(Dependency dep :depEntry.getValue()){
if(!dependencyTable.containsKey(dep)){
allValuesDependentsAreBuilt.add("true");
}else
{
allValuesDependentsAreBuilt.add("false");
}
}
if(!allValuesDependentsAreBuilt.contains("false")){
listofAllDependency.add(depEntry.getKey());
dependencyTable.remove(depEntry);
depIterator.remove();
}
}
}