for -> foreach

string.equals() -> string.isEmpty() or .equals(string)
ArrayList -> List

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1812461 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Javen O'Neal 2017-10-18 07:33:07 +00:00
parent bcbadce32e
commit 36dcbd7403

View File

@ -21,6 +21,7 @@ import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import org.apache.poi.POIOLE2TextExtractor; import org.apache.poi.POIOLE2TextExtractor;
import org.apache.poi.hdgf.HDGFDiagram; import org.apache.poi.hdgf.HDGFDiagram;
@ -65,26 +66,25 @@ public final class VisioTextExtractor extends POIOLE2TextExtractor {
* @return An array of each Text item in the document * @return An array of each Text item in the document
*/ */
public String[] getAllText() { public String[] getAllText() {
ArrayList<String> text = new ArrayList<>(); List<String> text = new ArrayList<>();
for(Stream stream : hdgf.getTopLevelStreams()) { for(Stream stream : hdgf.getTopLevelStreams()) {
findText(stream, text); findText(stream, text);
} }
return text.toArray( new String[text.size()] ); return text.toArray( new String[text.size()] );
} }
private void findText(Stream stream, ArrayList<String> text) { private void findText(Stream stream, List<String> text) {
if(stream instanceof PointerContainingStream) { if(stream instanceof PointerContainingStream) {
PointerContainingStream ps = (PointerContainingStream)stream; PointerContainingStream ps = (PointerContainingStream)stream;
for(int i=0; i<ps.getPointedToStreams().length; i++) { for(final Stream substream : ps.getPointedToStreams()) {
findText(ps.getPointedToStreams()[i], text); findText(substream, text);
} }
} }
if(stream instanceof ChunkStream) { if(stream instanceof ChunkStream) {
ChunkStream cs = (ChunkStream)stream; ChunkStream cs = (ChunkStream)stream;
for(int i=0; i<cs.getChunks().length; i++) { for(final Chunk chunk : cs.getChunks()) {
Chunk chunk = cs.getChunks()[i];
if(chunk != null && if(chunk != null &&
chunk.getName() != null && chunk.getName() != null &&
chunk.getName().equals("Text") && "Text".equals(chunk.getName()) &&
chunk.getCommands().length > 0) { chunk.getCommands().length > 0) {
// First command // First command
@ -93,7 +93,7 @@ public final class VisioTextExtractor extends POIOLE2TextExtractor {
// Capture the text, as long as it isn't // Capture the text, as long as it isn't
// simply an empty string // simply an empty string
String str = cmd.getValue().toString(); String str = cmd.getValue().toString();
if(str.equals("") || str.equals("\n")) { if(str.isEmpty() || "\n".equals(str)) {
// Ignore empty strings // Ignore empty strings
} else { } else {
text.add( str ); text.add( str );