Adjust toString() of ExternalNameRecord
Fix some IntelliJ warnings Reformat TextPieceTable git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1773776 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
701b19cf21
commit
230453d76e
@ -214,7 +214,7 @@ public final class ExternalNameRecord extends StandardRecord {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("[EXTERNALNAME]\n");
|
||||
sb.append(" .options = ").append(field_1_option_flag).append("\n");
|
||||
sb.append(" .ix = ").append(field_2_ixals).append("\n");
|
||||
@ -222,7 +222,7 @@ public final class ExternalNameRecord extends StandardRecord {
|
||||
if(field_5_name_definition != null) {
|
||||
Ptg[] ptgs = field_5_name_definition.getTokens();
|
||||
for (Ptg ptg : ptgs) {
|
||||
sb.append(ptg.toString()).append(ptg.getRVAType()).append("\n");
|
||||
sb.append(" .namedef = ").append(ptg.toString()).append(ptg.getRVAType()).append("\n");
|
||||
}
|
||||
}
|
||||
sb.append("[/EXTERNALNAME]\n");
|
||||
|
@ -163,6 +163,7 @@ public class XSSFSheetXMLHandler extends DefaultHandler {
|
||||
private void init() {
|
||||
if (commentsTable != null) {
|
||||
commentCellRefs = new LinkedList<CellAddress>();
|
||||
//noinspection deprecation
|
||||
for (CTComment comment : commentsTable.getCTComments().getCommentList().getCommentArray()) {
|
||||
commentCellRefs.add(new CellAddress(comment.getRef()));
|
||||
}
|
||||
@ -228,10 +229,10 @@ public class XSSFSheetXMLHandler extends DefaultHandler {
|
||||
// match the current cell
|
||||
if(formulasNotResults) {
|
||||
logger.log(POILogger.WARN, "shared formulas not yet supported!");
|
||||
} else {
|
||||
} /*else {
|
||||
// It's a shared formula, so we can't get at the formula string yet
|
||||
// However, they don't care about the formula string, so that's ok!
|
||||
}
|
||||
}*/
|
||||
}
|
||||
} else {
|
||||
fIsOpen = true;
|
||||
@ -334,7 +335,7 @@ public class XSSFSheetXMLHandler extends DefaultHandler {
|
||||
thisStr = fv;
|
||||
}
|
||||
} else {
|
||||
// No formating applied, just do raw value in all cases
|
||||
// No formatting applied, just do raw value in all cases
|
||||
thisStr = fv;
|
||||
}
|
||||
}
|
||||
|
@ -38,8 +38,7 @@ import org.apache.poi.util.POILogger;
|
||||
* @author Ryan Ackley
|
||||
*/
|
||||
@Internal
|
||||
public class TextPieceTable implements CharIndexTranslator
|
||||
{
|
||||
public class TextPieceTable implements CharIndexTranslator {
|
||||
private static final POILogger logger = POILogFactory
|
||||
.getLogger(TextPieceTable.class);
|
||||
|
||||
@ -48,13 +47,11 @@ public class TextPieceTable implements CharIndexTranslator
|
||||
protected ArrayList<TextPiece> _textPieces = new ArrayList<TextPiece>();
|
||||
protected ArrayList<TextPiece> _textPiecesFCOrder = new ArrayList<TextPiece>();
|
||||
|
||||
public TextPieceTable()
|
||||
{
|
||||
public TextPieceTable() {
|
||||
}
|
||||
|
||||
public TextPieceTable(byte[] documentStream, byte[] tableStream,
|
||||
int offset, int size, int fcMin )
|
||||
{
|
||||
int offset, int size, int fcMin) {
|
||||
// get our plex of PieceDescriptors
|
||||
PlexOfCps pieceTable = new PlexOfCps(tableStream, offset, size,
|
||||
PieceDescriptor.getSizeInBytes());
|
||||
@ -64,8 +61,7 @@ public class TextPieceTable implements CharIndexTranslator
|
||||
|
||||
// iterate through piece descriptors raw bytes and create
|
||||
// PieceDescriptor objects
|
||||
for ( int x = 0; x < length; x++ )
|
||||
{
|
||||
for (int x = 0; x < length; x++) {
|
||||
GenericPropertyNode node = pieceTable.getProperty(x);
|
||||
pieces[x] = new PieceDescriptor(node.getBytes(), 0);
|
||||
}
|
||||
@ -73,18 +69,15 @@ public class TextPieceTable implements CharIndexTranslator
|
||||
// Figure out the cp of the earliest text piece
|
||||
// Note that text pieces don't have to be stored in order!
|
||||
_cpMin = pieces[0].getFilePosition() - fcMin;
|
||||
for ( int x = 0; x < pieces.length; x++ )
|
||||
{
|
||||
int start = pieces[x].getFilePosition() - fcMin;
|
||||
if ( start < _cpMin )
|
||||
{
|
||||
for (PieceDescriptor piece : pieces) {
|
||||
int start = piece.getFilePosition() - fcMin;
|
||||
if (start < _cpMin) {
|
||||
_cpMin = start;
|
||||
}
|
||||
}
|
||||
|
||||
// using the PieceDescriptors, build our list of TextPieces.
|
||||
for ( int x = 0; x < pieces.length; x++ )
|
||||
{
|
||||
for (int x = 0; x < pieces.length; x++) {
|
||||
int start = pieces[x].getFilePosition();
|
||||
GenericPropertyNode node = pieceTable.getProperty(x);
|
||||
|
||||
@ -95,8 +88,7 @@ public class TextPieceTable implements CharIndexTranslator
|
||||
// What's the relationship between bytes and characters?
|
||||
boolean unicode = pieces[x].isUnicode();
|
||||
int multiple = 1;
|
||||
if ( unicode )
|
||||
{
|
||||
if (unicode) {
|
||||
multiple = 2;
|
||||
}
|
||||
|
||||
@ -122,8 +114,7 @@ public class TextPieceTable implements CharIndexTranslator
|
||||
Collections.sort(_textPiecesFCOrder, new FCComparator());
|
||||
}
|
||||
|
||||
public void add( TextPiece piece )
|
||||
{
|
||||
public void add(TextPiece piece) {
|
||||
_textPieces.add(piece);
|
||||
_textPiecesFCOrder.add(piece);
|
||||
Collections.sort(_textPieces);
|
||||
@ -133,13 +124,10 @@ public class TextPieceTable implements CharIndexTranslator
|
||||
/**
|
||||
* Adjust all the text piece after inserting some text into one of them
|
||||
*
|
||||
* @param listIndex
|
||||
* The TextPiece that had characters inserted into
|
||||
* @param length
|
||||
* The number of characters inserted
|
||||
* @param listIndex The TextPiece that had characters inserted into
|
||||
* @param length The number of characters inserted
|
||||
*/
|
||||
public int adjustForInsert( int listIndex, int length )
|
||||
{
|
||||
public int adjustForInsert(int listIndex, int length) {
|
||||
int size = _textPieces.size();
|
||||
|
||||
TextPiece tp = _textPieces.get(listIndex);
|
||||
@ -148,8 +136,7 @@ public class TextPieceTable implements CharIndexTranslator
|
||||
tp.setEnd(tp.getEnd() + length);
|
||||
|
||||
// Now change all subsequent ones
|
||||
for ( int x = listIndex + 1; x < size; x++ )
|
||||
{
|
||||
for (int x = listIndex + 1; x < size; x++) {
|
||||
tp = _textPieces.get(x);
|
||||
tp.setStart(tp.getStart() + length);
|
||||
tp.setEnd(tp.getEnd() + length);
|
||||
@ -159,18 +146,14 @@ public class TextPieceTable implements CharIndexTranslator
|
||||
return length;
|
||||
}
|
||||
|
||||
public boolean equals( Object o )
|
||||
{
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof TextPieceTable)) return false;
|
||||
TextPieceTable tpt = (TextPieceTable) o;
|
||||
|
||||
int size = tpt._textPieces.size();
|
||||
if ( size == _textPieces.size() )
|
||||
{
|
||||
for ( int x = 0; x < size; x++ )
|
||||
{
|
||||
if ( !tpt._textPieces.get( x ).equals( _textPieces.get( x ) ) )
|
||||
{
|
||||
if (size == _textPieces.size()) {
|
||||
for (int x = 0; x < size; x++) {
|
||||
if (!tpt._textPieces.get(x).equals(_textPieces.get(x))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -179,13 +162,10 @@ public class TextPieceTable implements CharIndexTranslator
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getByteIndex( int charPos )
|
||||
{
|
||||
public int getByteIndex(int charPos) {
|
||||
int byteCount = 0;
|
||||
for ( TextPiece tp : _textPieces )
|
||||
{
|
||||
if ( charPos >= tp.getEnd() )
|
||||
{
|
||||
for (TextPiece tp : _textPieces) {
|
||||
if (charPos >= tp.getEnd()) {
|
||||
byteCount = tp.getPieceDescriptor().getFilePosition()
|
||||
+ (tp.getEnd() - tp.getStart())
|
||||
* (tp.isUnicode() ? 2 : 1);
|
||||
@ -195,8 +175,7 @@ public class TextPieceTable implements CharIndexTranslator
|
||||
|
||||
continue;
|
||||
}
|
||||
if ( charPos < tp.getEnd() )
|
||||
{
|
||||
if (charPos < tp.getEnd()) {
|
||||
int left = charPos - tp.getStart();
|
||||
byteCount = tp.getPieceDescriptor().getFilePosition() + left
|
||||
* (tp.isUnicode() ? 2 : 1);
|
||||
@ -207,20 +186,17 @@ public class TextPieceTable implements CharIndexTranslator
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public int getCharIndex( int bytePos )
|
||||
{
|
||||
public int getCharIndex(int bytePos) {
|
||||
return getCharIndex(bytePos, 0);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public int getCharIndex( int startBytePos, int startCP )
|
||||
{
|
||||
public int getCharIndex(int startBytePos, int startCP) {
|
||||
int charCount = 0;
|
||||
|
||||
int bytePos = lookIndexForward(startBytePos);
|
||||
|
||||
for ( TextPiece tp : _textPieces )
|
||||
{
|
||||
for (TextPiece tp : _textPieces) {
|
||||
int pieceStart = tp.getPieceDescriptor().getFilePosition();
|
||||
|
||||
int bytesLength = tp.bytesLength();
|
||||
@ -228,31 +204,22 @@ public class TextPieceTable implements CharIndexTranslator
|
||||
|
||||
int toAdd;
|
||||
|
||||
if ( bytePos < pieceStart || bytePos > pieceEnd )
|
||||
{
|
||||
if (bytePos < pieceStart || bytePos > pieceEnd) {
|
||||
toAdd = bytesLength;
|
||||
}
|
||||
else if ( bytePos > pieceStart && bytePos < pieceEnd )
|
||||
{
|
||||
} else if (bytePos > pieceStart && bytePos < pieceEnd) {
|
||||
toAdd = (bytePos - pieceStart);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
toAdd = bytesLength - (pieceEnd - bytePos);
|
||||
}
|
||||
|
||||
if ( tp.isUnicode() )
|
||||
{
|
||||
if (tp.isUnicode()) {
|
||||
charCount += toAdd / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
charCount += toAdd;
|
||||
}
|
||||
|
||||
if (bytePos >= pieceStart && bytePos <= pieceEnd
|
||||
&& charCount >= startCP )
|
||||
{
|
||||
&& charCount >= startCP) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -262,11 +229,9 @@ public class TextPieceTable implements CharIndexTranslator
|
||||
|
||||
@Override
|
||||
public int[][] getCharIndexRanges(int startBytePosInclusive,
|
||||
int endBytePosExclusive )
|
||||
{
|
||||
int endBytePosExclusive) {
|
||||
List<int[]> result = new LinkedList<int[]>();
|
||||
for ( TextPiece textPiece : _textPiecesFCOrder )
|
||||
{
|
||||
for (TextPiece textPiece : _textPiecesFCOrder) {
|
||||
final int tpStart = textPiece.getPieceDescriptor()
|
||||
.getFilePosition();
|
||||
final int tpEnd = textPiece.getPieceDescriptor().getFilePosition()
|
||||
@ -297,24 +262,20 @@ public class TextPieceTable implements CharIndexTranslator
|
||||
return result.toArray(new int[result.size()][]);
|
||||
}
|
||||
|
||||
public int getCpMin()
|
||||
{
|
||||
public int getCpMin() {
|
||||
return _cpMin;
|
||||
}
|
||||
|
||||
public StringBuilder getText()
|
||||
{
|
||||
public StringBuilder getText() {
|
||||
final long start = System.currentTimeMillis();
|
||||
|
||||
// rebuild document paragraphs structure
|
||||
StringBuilder docText = new StringBuilder();
|
||||
for ( TextPiece textPiece : _textPieces )
|
||||
{
|
||||
for (TextPiece textPiece : _textPieces) {
|
||||
String toAppend = textPiece.getStringBuilder().toString();
|
||||
int toAppendLength = toAppend.length();
|
||||
|
||||
if ( toAppendLength != textPiece.getEnd() - textPiece.getStart() )
|
||||
{
|
||||
if (toAppendLength != textPiece.getEnd() - textPiece.getStart()) {
|
||||
logger.log(
|
||||
POILogger.WARN,
|
||||
"Text piece has boundaries [",
|
||||
@ -337,30 +298,24 @@ public class TextPieceTable implements CharIndexTranslator
|
||||
return docText;
|
||||
}
|
||||
|
||||
public List<TextPiece> getTextPieces()
|
||||
{
|
||||
public List<TextPiece> getTextPieces() {
|
||||
return _textPieces;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
public int hashCode() {
|
||||
return _textPieces.size();
|
||||
}
|
||||
|
||||
public boolean isIndexInTable( int bytePos )
|
||||
{
|
||||
for ( TextPiece tp : _textPiecesFCOrder )
|
||||
{
|
||||
public boolean isIndexInTable(int bytePos) {
|
||||
for (TextPiece tp : _textPiecesFCOrder) {
|
||||
int pieceStart = tp.getPieceDescriptor().getFilePosition();
|
||||
|
||||
if ( bytePos > pieceStart + tp.bytesLength() )
|
||||
{
|
||||
if (bytePos > pieceStart + tp.bytesLength()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( pieceStart > bytePos )
|
||||
{
|
||||
if (pieceStart > bytePos) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -370,14 +325,11 @@ public class TextPieceTable implements CharIndexTranslator
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean isIndexInTable( int startBytePos, int endBytePos )
|
||||
{
|
||||
for ( TextPiece tp : _textPiecesFCOrder )
|
||||
{
|
||||
boolean isIndexInTable(int startBytePos, int endBytePos) {
|
||||
for (TextPiece tp : _textPiecesFCOrder) {
|
||||
int pieceStart = tp.getPieceDescriptor().getFilePosition();
|
||||
|
||||
if ( startBytePos >= pieceStart + tp.bytesLength() )
|
||||
{
|
||||
if (startBytePos >= pieceStart + tp.bytesLength()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -393,23 +345,19 @@ public class TextPieceTable implements CharIndexTranslator
|
||||
return false;
|
||||
}
|
||||
|
||||
public int lookIndexBackward( final int startBytePos )
|
||||
{
|
||||
public int lookIndexBackward(final int startBytePos) {
|
||||
int bytePos = startBytePos;
|
||||
int lastEnd = 0;
|
||||
|
||||
for ( TextPiece tp : _textPiecesFCOrder )
|
||||
{
|
||||
for (TextPiece tp : _textPiecesFCOrder) {
|
||||
int pieceStart = tp.getPieceDescriptor().getFilePosition();
|
||||
|
||||
if ( bytePos > pieceStart + tp.bytesLength() )
|
||||
{
|
||||
if (bytePos > pieceStart + tp.bytesLength()) {
|
||||
lastEnd = pieceStart + tp.bytesLength();
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( pieceStart > bytePos )
|
||||
{
|
||||
if (pieceStart > bytePos) {
|
||||
bytePos = lastEnd;
|
||||
}
|
||||
|
||||
@ -419,8 +367,7 @@ public class TextPieceTable implements CharIndexTranslator
|
||||
return bytePos;
|
||||
}
|
||||
|
||||
public int lookIndexForward( final int startBytePos )
|
||||
{
|
||||
public int lookIndexForward(final int startBytePos) {
|
||||
if (_textPiecesFCOrder.isEmpty())
|
||||
throw new IllegalStateException("Text pieces table is empty");
|
||||
|
||||
@ -434,8 +381,7 @@ public class TextPieceTable implements CharIndexTranslator
|
||||
int low = 0;
|
||||
int high = _textPiecesFCOrder.size() - 1;
|
||||
|
||||
while ( low <= high )
|
||||
{
|
||||
while (low <= high) {
|
||||
int mid = (low + high) >>> 1;
|
||||
final TextPiece textPiece = _textPiecesFCOrder.get(mid);
|
||||
int midVal = textPiece.getPieceDescriptor().getFilePosition();
|
||||
@ -459,21 +405,16 @@ public class TextPieceTable implements CharIndexTranslator
|
||||
return _textPiecesFCOrder.get(low + 1).getPieceDescriptor().getFilePosition();
|
||||
}
|
||||
|
||||
public byte[] writeTo( HWPFOutputStream docStream ) throws IOException
|
||||
{
|
||||
public byte[] writeTo(HWPFOutputStream docStream) throws IOException {
|
||||
PlexOfCps textPlex = new PlexOfCps(PieceDescriptor.getSizeInBytes());
|
||||
// int fcMin = docStream.getOffset();
|
||||
|
||||
int size = _textPieces.size();
|
||||
for ( int x = 0; x < size; x++ )
|
||||
{
|
||||
TextPiece next = _textPieces.get( x );
|
||||
for (TextPiece next : _textPieces) {
|
||||
PieceDescriptor pd = next.getPieceDescriptor();
|
||||
|
||||
int offset = docStream.getOffset();
|
||||
int mod = (offset % POIFSConstants.SMALLER_BIG_BLOCK_SIZE);
|
||||
if ( mod != 0 )
|
||||
{
|
||||
if (mod != 0) {
|
||||
mod = POIFSConstants.SMALLER_BIG_BLOCK_SIZE - mod;
|
||||
byte[] buf = new byte[mod];
|
||||
docStream.write(buf);
|
||||
@ -498,22 +439,15 @@ public class TextPieceTable implements CharIndexTranslator
|
||||
return textPlex.toByteArray();
|
||||
}
|
||||
|
||||
private static class FCComparator implements Comparator<TextPiece>, Serializable
|
||||
{
|
||||
public int compare( TextPiece textPiece, TextPiece textPiece1 )
|
||||
{
|
||||
private static class FCComparator implements Comparator<TextPiece>, Serializable {
|
||||
public int compare(TextPiece textPiece, TextPiece textPiece1) {
|
||||
if (textPiece.getPieceDescriptor().fc > textPiece1
|
||||
.getPieceDescriptor().fc )
|
||||
{
|
||||
.getPieceDescriptor().fc) {
|
||||
return 1;
|
||||
}
|
||||
else if ( textPiece.getPieceDescriptor().fc < textPiece1
|
||||
.getPieceDescriptor().fc )
|
||||
{
|
||||
} else if (textPiece.getPieceDescriptor().fc < textPiece1
|
||||
.getPieceDescriptor().fc) {
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -118,7 +118,6 @@ public final class TestFormulaBugs {
|
||||
|
||||
/**
|
||||
* Bug 42448 - Can't parse SUMPRODUCT(A!C7:A!C67, B8:B68) / B69 <p/>
|
||||
* @throws IOException
|
||||
*/
|
||||
@Test
|
||||
public void test42448() throws IOException {
|
||||
|
Loading…
Reference in New Issue
Block a user