Add a getEntryNames() method to POIFS/NPOIFS directory entries, to make listing easier

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1590148 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2014-04-25 21:10:52 +00:00
parent 00db163084
commit 184be5c03b
3 changed files with 37 additions and 0 deletions

View File

@ -23,6 +23,7 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import java.util.Set;
import org.apache.poi.hpsf.ClassID;
@ -49,6 +50,17 @@ public interface DirectoryEntry
*/
public Iterator<Entry> getEntries();
/**
* get the names of all the Entries contained directly in this
* instance (in other words, names of children only; no grandchildren
* etc).
*
* @return the names of all the entries that may be retrieved with
* getEntry(String), which may be empty (if this
* DirectoryEntry is empty)
*/
public Set<String> getEntryNames();
/**
* is this DirectoryEntry empty?

View File

@ -27,6 +27,7 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.poi.hpsf.ClassID;
import org.apache.poi.poifs.dev.POIFSViewable;
@ -317,6 +318,20 @@ public class DirectoryNode
{
return _entries.iterator();
}
/**
* get the names of all the Entries contained directly in this
* instance (in other words, names of children only; no grandchildren
* etc).
*
* @return the names of all the entries that may be retrieved with
* getEntry(String), which may be empty (if this
* DirectoryEntry is empty)
*/
public Set<String> getEntryNames()
{
return _byname.keySet();
}
/**
* is this DirectoryEntry empty?

View File

@ -114,6 +114,16 @@ public class FilteringDirectoryNode implements DirectoryEntry
}
return size;
}
public Set<String> getEntryNames() {
Set<String> names = new HashSet<String>();
for (String name : directory.getEntryNames()) {
if (!excludes.contains(name)) {
names.add(name);
}
}
return names;
}
public boolean isEmpty() {
return (getEntryCount() == 0);