I am trying to fill a list myClassTypes with recursive calls to getMyClassTypes(). But it gets initialized every time there is recursive call to the method. And, I am losing few values because of this. I understand that the problem is with declaring locally: List myClassTypes = new ArrayList<>(); But, I don't want to declare the list at the class level. Here is the code I am working with:
private List<MyClassType> getMyClassTypes(final String path) throws SVNException {
final Collection<SVNDirEntry> svnDirectoryEntries = svnRepository.getDir(path, -1, null, (Collection<SVNDirEntry>) null);
final Iterator<SVNDirEntry> svnDirectoryEntryIterator = svnDirectoryEntries.iterator();
final List<MyClassType> myClassTypes = new ArrayList<>();
while (svnDirectoryEntryIterator.hasNext()) {
final SVNDirEntry entry = svnDirectoryEntryIterator.next();
final String fileName = entry.getName();
if (!path.isEmpty() && path.matches(SUB_DIRECTORY_NAME_PATTERN) && fileName.endsWith(".xml")) {
final MyClassType myClassType = new MyClassType(path, fileName);
myClassTypes.add(myClassType);
}
/*
* Check if the entry is a directory recursively.
*/
if (someCondition) {
getMyClassTypes((path.equals("")) ? entry.getName() : path + "/" + entry.getName());
}
}
return myClassTypes;
}
How to manage the 'myClassTypes' to contain all the values even after 'n times' recursive calls?
getMyClassTypesntimes?