Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/DropCapSpecifier.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/DropCapSpecifier.java?rev=1871938&r1=1871937&r2=1871938&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/DropCapSpecifier.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/DropCapSpecifier.java Tue Dec 24 11:56:42 2019 @@ -17,42 +17,50 @@ package org.apache.poi.hwpf.usermodel; +import org.apache.poi.common.Duplicatable; import org.apache.poi.util.BitField; import org.apache.poi.util.BitFieldFactory; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.Removal; /** * This data structure is used by a paragraph to determine how it should drop * its first letter. I think its the visual effect that will show a giant first * letter to a paragraph. I've seen this used in the first paragraph of a book - * - * @author Ryan Ackley */ -public final class DropCapSpecifier implements Cloneable -{ +public final class DropCapSpecifier implements Duplicatable { + private static final BitField _lines = BitFieldFactory.getInstance( 0xf8 ); + private static final BitField _type = BitFieldFactory.getInstance( 0x07 ); + private short _fdct; - private static BitField _lines = BitFieldFactory.getInstance( 0xf8 ); - private static BitField _type = BitFieldFactory.getInstance( 0x07 ); - public DropCapSpecifier() - { - this._fdct = 0; + public DropCapSpecifier() { + _fdct = 0; + } + + public DropCapSpecifier(DropCapSpecifier other) { + _fdct = other._fdct; } - public DropCapSpecifier( byte[] buf, int offset ) - { + public DropCapSpecifier( byte[] buf, int offset ) { this( LittleEndian.getShort( buf, offset ) ); } - public DropCapSpecifier( short fdct ) - { + public DropCapSpecifier( short fdct ) { this._fdct = fdct; } @Override - public DropCapSpecifier clone() - { - return new DropCapSpecifier( _fdct ); + @SuppressWarnings("squid:S2975") + @Deprecated + @Removal(version = "5.0.0") + public DropCapSpecifier clone() { + return copy(); + } + + @Override + public DropCapSpecifier copy() { + return new DropCapSpecifier(this); } @Override
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/LineSpacingDescriptor.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/LineSpacingDescriptor.java?rev=1871938&r1=1871937&r2=1871938&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/LineSpacingDescriptor.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/LineSpacingDescriptor.java Tue Dec 24 11:56:42 2019 @@ -17,36 +17,44 @@ package org.apache.poi.hwpf.usermodel; +import org.apache.poi.common.Duplicatable; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.Removal; /** * This class is used to determine line spacing for a paragraph. - * - * @author Ryan Ackley */ -public final class LineSpacingDescriptor - implements Cloneable -{ +public final class LineSpacingDescriptor implements Duplicatable { short _dyaLine; short _fMultiLinespace; - public LineSpacingDescriptor() - { - //see page 181 + public LineSpacingDescriptor() { _dyaLine = 240; _fMultiLinespace = 1; } - public LineSpacingDescriptor(byte[] buf, int offset) - { + public LineSpacingDescriptor(LineSpacingDescriptor other) { + _dyaLine = other._dyaLine; + _fMultiLinespace = other._fMultiLinespace; + } + + + public LineSpacingDescriptor(byte[] buf, int offset) { _dyaLine = LittleEndian.getShort(buf, offset); _fMultiLinespace = LittleEndian.getShort(buf, offset + LittleEndian.SHORT_SIZE); } - public Object clone() - throws CloneNotSupportedException - { - return super.clone(); + @Override + @SuppressWarnings("squid:S2975") + @Deprecated + @Removal(version = "5.0.0") + public LineSpacingDescriptor clone() { + return copy(); + } + + @Override + public LineSpacingDescriptor copy() { + return new LineSpacingDescriptor(this); } public void setMultiLinespace(short fMultiLinespace) @@ -71,7 +79,7 @@ public final class LineSpacingDescriptor { _dyaLine = dyaLine; } - + @Override public boolean equals(Object o) { @@ -86,7 +94,7 @@ public final class LineSpacingDescriptor assert false : "hashCode not designed"; return 42; // any arbitrary constant will do } - + public boolean isEmpty() { return _dyaLine == 0 && _fMultiLinespace == 0; Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Paragraph.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Paragraph.java?rev=1871938&r1=1871937&r2=1871938&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Paragraph.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Paragraph.java Tue Dec 24 11:56:42 2019 @@ -19,6 +19,7 @@ package org.apache.poi.hwpf.usermodel; import java.util.NoSuchElementException; +import org.apache.poi.common.Duplicatable; import org.apache.poi.hwpf.HWPFDocumentCore; import org.apache.poi.hwpf.model.LFO; import org.apache.poi.hwpf.model.ListLevel; @@ -31,67 +32,68 @@ import org.apache.poi.hwpf.sprm.TableSpr import org.apache.poi.util.Internal; import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; +import org.apache.poi.util.Removal; -public class Paragraph extends Range implements Cloneable { - private final static POILogger log = POILogFactory.getLogger( Paragraph.class ); +public class Paragraph extends Range implements Duplicatable { + private static final POILogger log = POILogFactory.getLogger( Paragraph.class ); - public final static short SPRM_JC = 0x2403; - public final static short SPRM_FSIDEBYSIDE = 0x2404; - public final static short SPRM_FKEEP = 0x2405; - public final static short SPRM_FKEEPFOLLOW = 0x2406; - public final static short SPRM_FPAGEBREAKBEFORE = 0x2407; - public final static short SPRM_BRCL = 0x2408; - public final static short SPRM_BRCP = 0x2409; - public final static short SPRM_ILVL = 0x260A; - public final static short SPRM_ILFO = 0x460B; - public final static short SPRM_FNOLINENUMB = 0x240C; - public final static short SPRM_CHGTABSPAPX = (short)0xC60D; - public final static short SPRM_DXARIGHT = (short)0x840E; - public final static short SPRM_DXALEFT = (short)0x840F; - public final static short SPRM_DXALEFT1 = (short)0x8411; - public final static short SPRM_DYALINE = 0x6412; - public final static short SPRM_DYABEFORE = (short)0xA413; - public final static short SPRM_DYAAFTER = (short)0xA414; - public final static short SPRM_CHGTABS = (short)0xC615; - public final static short SPRM_FINTABLE = 0x2416; - public final static short SPRM_FTTP = 0x2417; - public final static short SPRM_DXAABS = (short)0x8418; - public final static short SPRM_DYAABS = (short)0x8419; - public final static short SPRM_DXAWIDTH = (short)0x841A; - public final static short SPRM_PC = 0x261B; - public final static short SPRM_WR = 0x2423; - public final static short SPRM_BRCTOP = 0x6424; - public final static short SPRM_BRCLEFT = 0x6425; - public final static short SPRM_BRCBOTTOM = 0x6426; - public final static short SPRM_BRCRIGHT = 0x6427; - public final static short SPRM_BRCBAR = 0x6629; - public final static short SPRM_FNOAUTOHYPH = 0x242A; - public final static short SPRM_WHEIGHTABS = 0x442B; - public final static short SPRM_DCS = 0x442C; - public final static short SPRM_SHD80 = 0x442D; - public final static short SPRM_SHD = (short)0xC64D; - public final static short SPRM_DYAFROMTEXT = (short)0x842E; - public final static short SPRM_DXAFROMTEXT = (short)0x842F; - public final static short SPRM_FLOCKED = 0x2430; - public final static short SPRM_FWIDOWCONTROL = 0x2431; - public final static short SPRM_RULER = (short)0xC632; - public final static short SPRM_FKINSOKU = 0x2433; - public final static short SPRM_FWORDWRAP = 0x2434; - public final static short SPRM_FOVERFLOWPUNCT = 0x2435; - public final static short SPRM_FTOPLINEPUNCT = 0x2436; - public final static short SPRM_AUTOSPACEDE = 0x2437; - public final static short SPRM_AUTOSPACEDN = 0x2438; - public final static short SPRM_WALIGNFONT = 0x4439; - public final static short SPRM_FRAMETEXTFLOW = 0x443A; - public final static short SPRM_ANLD = (short)0xC63E; - public final static short SPRM_PROPRMARK = (short)0xC63F; - public final static short SPRM_OUTLVL = 0x2640; - public final static short SPRM_FBIDI = 0x2441; - public final static short SPRM_FNUMRMLNS = 0x2443; - public final static short SPRM_CRLF = 0x2444; - public final static short SPRM_NUMRM = (short)0xC645; - public final static short SPRM_USEPGSUSETTINGS = 0x2447; - public final static short SPRM_FADJUSTRIGHT = 0x2448; + public static final short SPRM_JC = 0x2403; + public static final short SPRM_FSIDEBYSIDE = 0x2404; + public static final short SPRM_FKEEP = 0x2405; + public static final short SPRM_FKEEPFOLLOW = 0x2406; + public static final short SPRM_FPAGEBREAKBEFORE = 0x2407; + public static final short SPRM_BRCL = 0x2408; + public static final short SPRM_BRCP = 0x2409; + public static final short SPRM_ILVL = 0x260A; + public static final short SPRM_ILFO = 0x460B; + public static final short SPRM_FNOLINENUMB = 0x240C; + public static final short SPRM_CHGTABSPAPX = (short)0xC60D; + public static final short SPRM_DXARIGHT = (short)0x840E; + public static final short SPRM_DXALEFT = (short)0x840F; + public static final short SPRM_DXALEFT1 = (short)0x8411; + public static final short SPRM_DYALINE = 0x6412; + public static final short SPRM_DYABEFORE = (short)0xA413; + public static final short SPRM_DYAAFTER = (short)0xA414; + public static final short SPRM_CHGTABS = (short)0xC615; + public static final short SPRM_FINTABLE = 0x2416; + public static final short SPRM_FTTP = 0x2417; + public static final short SPRM_DXAABS = (short)0x8418; + public static final short SPRM_DYAABS = (short)0x8419; + public static final short SPRM_DXAWIDTH = (short)0x841A; + public static final short SPRM_PC = 0x261B; + public static final short SPRM_WR = 0x2423; + public static final short SPRM_BRCTOP = 0x6424; + public static final short SPRM_BRCLEFT = 0x6425; + public static final short SPRM_BRCBOTTOM = 0x6426; + public static final short SPRM_BRCRIGHT = 0x6427; + public static final short SPRM_BRCBAR = 0x6629; + public static final short SPRM_FNOAUTOHYPH = 0x242A; + public static final short SPRM_WHEIGHTABS = 0x442B; + public static final short SPRM_DCS = 0x442C; + public static final short SPRM_SHD80 = 0x442D; + public static final short SPRM_SHD = (short)0xC64D; + public static final short SPRM_DYAFROMTEXT = (short)0x842E; + public static final short SPRM_DXAFROMTEXT = (short)0x842F; + public static final short SPRM_FLOCKED = 0x2430; + public static final short SPRM_FWIDOWCONTROL = 0x2431; + public static final short SPRM_RULER = (short)0xC632; + public static final short SPRM_FKINSOKU = 0x2433; + public static final short SPRM_FWORDWRAP = 0x2434; + public static final short SPRM_FOVERFLOWPUNCT = 0x2435; + public static final short SPRM_FTOPLINEPUNCT = 0x2436; + public static final short SPRM_AUTOSPACEDE = 0x2437; + public static final short SPRM_AUTOSPACEDN = 0x2438; + public static final short SPRM_WALIGNFONT = 0x4439; + public static final short SPRM_FRAMETEXTFLOW = 0x443A; + public static final short SPRM_ANLD = (short)0xC63E; + public static final short SPRM_PROPRMARK = (short)0xC63F; + public static final short SPRM_OUTLVL = 0x2640; + public static final short SPRM_FBIDI = 0x2441; + public static final short SPRM_FNUMRMLNS = 0x2443; + public static final short SPRM_CRLF = 0x2444; + public static final short SPRM_NUMRM = (short)0xC645; + public static final short SPRM_USEPGSUSETTINGS = 0x2447; + public static final short SPRM_FADJUSTRIGHT = 0x2448; @Internal public static Paragraph newParagraph( Range parent, PAPX papx ) @@ -169,11 +171,18 @@ public class Paragraph extends Range imp _istd = papx.getIstd(); } + Paragraph(Paragraph other) { + super(other); + _istd = other._istd; + _props = (other._props == null) ? null : other._props.copy(); + _papx = (other._papx == null) ? null : other._papx.copy(); + } + /** * Returns the index of the style which applies to this * Paragraph. Details of the style can be looked up * from the {@link StyleSheet}, via - * {@link StyleSheet#getStyleDescription(int)} + * {@link StyleSheet#getStyleDescription(int)} */ public short getStyleIndex() { @@ -540,7 +549,7 @@ public class Paragraph extends Range imp /** * Returns number of tabs stops defined for paragraph. Must be >= 0 and <= * 64. - * + * * @return number of tabs stops defined for paragraph. Must be >= 0 and <= * 64 */ @@ -551,7 +560,7 @@ public class Paragraph extends Range imp /** * Returns array of positions of itbdMac tab stops - * + * * @return array of positions of itbdMac tab stops */ public int[] getTabStopsPositions() @@ -576,24 +585,24 @@ public class Paragraph extends Range imp /** * Clone the ParagraphProperties object associated with this - * Paragraph, so that you can apply the same properties to + * Paragraph, so that you can apply the same properties to * another Paragraph. */ public ParagraphProperties cloneProperties() { - try { - return (ParagraphProperties)_props.clone(); - } catch (Exception e) { - throw new RuntimeException(e); - } + return _props.copy(); } - public Object clone() throws CloneNotSupportedException - { - Paragraph p = (Paragraph)super.clone(); - p._props = (ParagraphProperties)_props.clone(); - //p._baseStyle = _baseStyle; - p._papx = new SprmBuffer(0); - return p; + @Override + @SuppressWarnings("squid:S2975") + @Deprecated + @Removal(version = "5.0.0") + public Paragraph clone() { + return copy(); + } + + @Override + public Paragraph copy() { + return new Paragraph(this); } private short getFrameTextFlow() Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ParagraphProperties.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ParagraphProperties.java?rev=1871938&r1=1871937&r2=1871938&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ParagraphProperties.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ParagraphProperties.java Tue Dec 24 11:56:42 2019 @@ -17,35 +17,36 @@ package org.apache.poi.hwpf.usermodel; +import org.apache.poi.common.Duplicatable; import org.apache.poi.hwpf.model.types.PAPAbstractType; +import org.apache.poi.util.Removal; -public final class ParagraphProperties extends PAPAbstractType implements - Cloneable -{ +@SuppressWarnings("unused") +public final class ParagraphProperties extends PAPAbstractType implements Duplicatable { private boolean jcLogical; - public ParagraphProperties() - { - setAnld( new byte[84] ); - setPhe( new byte[12] ); + public ParagraphProperties() { + setAnld(new byte[84]); + setPhe(new byte[12]); } - public Object clone() throws CloneNotSupportedException - { - ParagraphProperties pp = (ParagraphProperties) super.clone(); - pp.setAnld( getAnld().clone() ); - pp.setBrcTop( (BorderCode) getBrcTop().clone() ); - pp.setBrcLeft( (BorderCode) getBrcLeft().clone() ); - pp.setBrcBottom( (BorderCode) getBrcBottom().clone() ); - pp.setBrcRight( (BorderCode) getBrcRight().clone() ); - pp.setBrcBetween( (BorderCode) getBrcBetween().clone() ); - pp.setBrcBar( (BorderCode) getBrcBar().clone() ); - pp.setDcs( getDcs().clone() ); - pp.setLspd( (LineSpacingDescriptor) getLspd().clone() ); - pp.setShd( getShd().clone() ); - pp.setPhe( getPhe().clone() ); - return pp; + public ParagraphProperties(ParagraphProperties other) { + super(other); + jcLogical = other.jcLogical; + } + + @Override + @SuppressWarnings({"squid:S2975", "MethodDoesntCallSuperMethod"}) + @Deprecated + @Removal(version = "5.0.0") + public ParagraphProperties clone() { + return copy(); + } + + @Override + public ParagraphProperties copy() { + return new ParagraphProperties(this); } public BorderCode getBarBorder() @@ -92,12 +93,12 @@ public final class ParagraphProperties e switch ( getJc() ) { - case 0: - return 2; - case 2: - return 0; - default: - return getJc(); + case 0: + return 2; + case 2: + return 0; + default: + return getJc(); } } @@ -332,3 +333,4 @@ public final class ParagraphProperties e } } + Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java?rev=1871938&r1=1871937&r2=1871938&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java Tue Dec 24 11:56:42 2019 @@ -17,6 +17,8 @@ package org.apache.poi.hwpf.usermodel; +import static java.util.stream.Collectors.toList; + import java.util.List; import org.apache.poi.hwpf.HWPFDocument; @@ -47,49 +49,47 @@ import org.apache.poi.util.POILogger; * Ranges are only valid if there hasn't been an insert in a prior Range since * the Range's creation. Once an element (text, paragraph, etc.) has been * inserted into a Range, subsequent Ranges become unstable. - * - * @author Ryan Ackley */ -public class Range { // TODO -instantiable superclass +public class Range { + + private static final POILogger logger = POILogFactory.getLogger( Range.class ); - private POILogger logger = POILogFactory.getLogger( Range.class ); - /** * @deprecated POI 3.8 beta 5 */ @Deprecated public static final int TYPE_PARAGRAPH = 0; - + /** * @deprecated POI 3.8 beta 5 */ @Deprecated public static final int TYPE_CHARACTER = 1; - + /** * @deprecated POI 3.8 beta 5 */ @Deprecated public static final int TYPE_SECTION = 2; - + /** * @deprecated POI 3.8 beta 5 */ @Deprecated public static final int TYPE_TEXT = 3; - + /** * @deprecated POI 3.8 beta 5 */ @Deprecated public static final int TYPE_LISTENTRY = 4; - + /** * @deprecated POI 3.8 beta 5 */ @Deprecated public static final int TYPE_TABLE = 5; - + /** * @deprecated POI 3.8 beta 5 */ @@ -145,18 +145,15 @@ public class Range { // TODO -instantiab protected int _charEnd; protected StringBuilder _text; - + /** * Used to construct a Range from a document. This is generally used to * create a Range that spans the whole document, or at least one whole part * of the document (eg main text, header, comment) * - * @param start - * Starting character offset of the range. - * @param end - * Ending character offset of the range. - * @param doc - * The HWPFDocument the range is based on. + * @param start Starting character offset of the range. + * @param end Ending character offset of the range. + * @param doc The HWPFDocument the range is based on. */ public Range(int start, int end, HWPFDocumentCore doc) { _start = start; @@ -174,12 +171,9 @@ public class Range { // TODO -instantiab /** * Used to create Ranges that are children of other Ranges. * - * @param start - * Starting character offset of the range. - * @param end - * Ending character offset of the range. - * @param parent - * The parent this range belongs to. + * @param start Starting character offset of the range. + * @param end Ending character offset of the range. + * @param parent The parent this range belongs to. */ protected Range(int start, int end, Range parent) { _start = start; @@ -195,6 +189,26 @@ public class Range { // TODO -instantiab sanityCheck(); } + protected Range(Range other) { + _parent = other._parent; + _start = other._start; + _end = other._end; + _doc = other._doc; + _sectionRangeFound = other._sectionRangeFound; + _sections = (other._sections == null) ? null : other._sections.stream().map(SEPX::copy).collect(toList()); + _sectionStart = other._sectionStart; + _sectionEnd = other._sectionEnd; + _parRangeFound = other._parRangeFound; + _paragraphs = (other._paragraphs == null) ? null : other._paragraphs.stream().map(PAPX::copy).collect(toList()); + _parStart = other._parStart; + _parEnd = other._parEnd; + _charRangeFound = other._charRangeFound; + _characters = (other._characters == null) ? null : other._characters.stream().map(CHPX::copy).collect(toList()); + _charStart = other._charStart; + _charEnd = other._charEnd; + _text = (other._text == null) ? null : new StringBuilder(other._text); + } + /** * Ensures that the start and end were were given are actually valid, to @@ -305,7 +319,7 @@ public class Range { // TODO -instantiab /** * Inserts text into the front of this range. - * + * * @param text * The text to insert * @return The character run that text was inserted into. @@ -335,7 +349,7 @@ public class Range { // TODO -instantiab /** * Inserts text onto the end of this range - * + * * @param text * The text to insert * @return The character run the text was inserted into. @@ -569,7 +583,7 @@ public class Range { // TODO -instantiab /** * Inserts a simple table into the beginning of this range. - * + * * @param columns * The number of columns * @param rows @@ -582,7 +596,7 @@ public class Range { // TODO -instantiab parProps.setItap( 1 ); final int oldEnd = this._end; - + for ( int x = 0; x < rows; x++ ) { Paragraph cell = this.insertBefore( parProps, StyleSheet.NIL_STYLE ); @@ -602,11 +616,11 @@ public class Range { // TODO -instantiab return new Table( _start, _start + diff, this, 1 ); } - + /** * Replace range text with new one, adding it to the range and deleting * original text from document - * + * * @param newText * The text to be replaced with * @param addAfter @@ -941,7 +955,7 @@ public class Range { // TODO -instantiab /** * Used to find the list indexes of a particular property. - * + * * @param rpl * A list of property nodes. * @param start @@ -988,7 +1002,7 @@ public class Range { // TODO -instantiab */ private int[] findRange(List<? extends PropertyNode<?>> rpl, int min, int start, int end) { int x = min; - + if ( rpl.size() == min ) return new int[] { min, min }; @@ -1043,9 +1057,9 @@ public class Range { // TODO -instantiab /** * Adjust the value of the various FIB character count fields, eg * <code>FIB.CCPText</code> after an insert or a delete... - * + * * Works on all CCP fields from this range onwards - * + * * @param adjustment * The (signed) value that should be added to the FIB CCP fields */ Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Section.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Section.java?rev=1871938&r1=1871937&r2=1871938&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Section.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Section.java Tue Dec 24 11:56:42 2019 @@ -17,17 +17,21 @@ package org.apache.poi.hwpf.usermodel; +import org.apache.poi.common.Duplicatable; import org.apache.poi.hwpf.HWPFOldDocument; import org.apache.poi.hwpf.model.SEPX; +import org.apache.poi.util.Removal; -public final class Section extends Range -{ - private SectionProperties _props; +public final class Section extends Range implements Duplicatable { + private final SectionProperties _props; - public Section( SEPX sepx, Range parent ) - { - super( Math.max( parent._start, sepx.getStart() ), Math.min( - parent._end, sepx.getEnd() ), parent ); + public Section(Section other) { + super(other); + _props = other._props.copy(); + } + + public Section( SEPX sepx, Range parent ) { + super( Math.max( parent._start, sepx.getStart() ), Math.min(parent._end, sepx.getEnd() ), parent ); // XXX: temporary workaround for old Word95 document if ( parent.getDocument() instanceof HWPFOldDocument ) @@ -36,11 +40,17 @@ public final class Section extends Range _props = sepx.getSectionProperties(); } - public Object clone() throws CloneNotSupportedException - { - Section s = (Section) super.clone(); - s._props = (SectionProperties) _props.clone(); - return s; + @Override + @SuppressWarnings({"squid:S2975", "MethodDoesntCallSuperMethod"}) + @Deprecated + @Removal(version = "5.0.0") + public Section clone() { + return copy(); + } + + @Override + public Section copy() { + return new Section(this); } /** @@ -99,7 +109,7 @@ public final class Section extends Range * Set the height of the bottom margin in twips. In the AbstractWordUtils class, a constant * is defined that indicates how many twips there are per inch and it can be used in setting * the margins width a little like this; - * + * * section.setMarginBottom( (int) 1.5 * AbstractWordUtils.TWIPS_PER_INCH ); * * @param marginWidth A primitive int whose value will indciate how high the margin should @@ -114,7 +124,7 @@ public final class Section extends Range * Set the width of the left hand margin in twips. In the AbstractWordUtils class, a constant * is defined that indicates how many twips there are per inch and it can be used in setting * the margins width a little like this; - * + * * section.setMarginLeft( (int) 1.5 * AbstractWordUtils.TWIPS_PER_INCH ); * * @param marginWidth A primitive int whose value will indciate how high the margin should @@ -129,7 +139,7 @@ public final class Section extends Range * Set the width of the right hand margin in twips. In the AbstractWordUtils class, a constant * is defined that indicates how many twips there are per inch and it can be used in setting * the margins width a little like this; - * + * * section.setMarginRight( (int) 1.5 * AbstractWordUtils.TWIPS_PER_INCH ); * * @param marginWidth A primitive int whose value will indciate how high the margin should @@ -144,7 +154,7 @@ public final class Section extends Range * Set the height of the top margin in twips. In the AbstractWordUtils class, a constant * is defined that indicates how many twips there are per inch and it can be used in setting * the margins width a little like this; - * + * * section.setMarginTop( (int) 1.5 * AbstractWordUtils.TWIPS_PER_INCH ); * * @param marginWidth A primitive int whose value will indciate how high the margin should @@ -181,7 +191,7 @@ public final class Section extends Range public int getFootnoteNumberingOffset() { return _props.getNFtn(); } - + /** * Get the numbering format of embedded footnotes * @@ -192,7 +202,7 @@ public final class Section extends Range public int getFootnoteNumberingFormat() { return _props.getNfcFtnRef(); } - + /** * Get the endnote restart qualifier * @@ -203,18 +213,18 @@ public final class Section extends Range * </dl> * * @return an Rnc, as decribed above, specifying when and where endnote numbering restarts - */ + */ public short getEndnoteRestartQualifier() { return _props.getRncEdn(); } - + /** * @return an offset to be added to endnote numbers */ public int getEndnoteNumberingOffset() { return _props.getNEdn(); } - + /** * Get the numbering format of embedded endnotes * Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/SectionProperties.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/SectionProperties.java?rev=1871938&r1=1871937&r2=1871938&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/SectionProperties.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/SectionProperties.java Tue Dec 24 11:56:42 2019 @@ -17,20 +17,22 @@ package org.apache.poi.hwpf.usermodel; +import org.apache.poi.common.Duplicatable; import org.apache.poi.hwpf.model.types.SEPAbstractType; +import org.apache.poi.util.Removal; -public final class SectionProperties extends SEPAbstractType implements Cloneable -{ +public final class SectionProperties extends SEPAbstractType implements Duplicatable { private short field_60_rncftn; private short field_61_rncedn; private int field_62_nftn; + // initialize with default value; msonfcArabic @SuppressWarnings("RedundantFieldInitialization") - private int field_63_nfcftnref = 0x00; // initialize with default value; msonfcArabic + private int field_63_nfcftnref = 0x00; private int field_64_nedn; - private int field_65_nfcednref = 0x02; // initialize with default value; msonfcLCRoman + // initialize with default value; msonfcLCRoman + private int field_65_nfcednref = 0x02; - public SectionProperties() - { + public SectionProperties() { field_20_brcTop = new BorderCode(); field_21_brcLeft = new BorderCode(); field_22_brcBottom = new BorderCode(); @@ -38,29 +40,38 @@ public final class SectionProperties ext field_26_dttmPropRMark = new DateAndTime(); } + public SectionProperties(SectionProperties other) { + super(other); + field_60_rncftn = other.field_60_rncftn; + field_61_rncedn = other.field_61_rncedn; + field_62_nftn = other.field_62_nftn; + field_63_nfcftnref = other.field_63_nfcftnref; + field_64_nedn = other.field_64_nedn; + field_65_nfcednref = other.field_65_nfcednref; + } + @Override - public Object clone() throws CloneNotSupportedException - { - SectionProperties copy = (SectionProperties) super.clone(); - copy.field_20_brcTop = (BorderCode) field_20_brcTop.clone(); - copy.field_21_brcLeft = (BorderCode) field_21_brcLeft.clone(); - copy.field_22_brcBottom = (BorderCode) field_22_brcBottom.clone(); - copy.field_23_brcRight = (BorderCode) field_23_brcRight.clone(); - copy.field_26_dttmPropRMark = (DateAndTime) field_26_dttmPropRMark - .clone(); + @SuppressWarnings("squid:S2975") + @Deprecated + @Removal(version = "5.0.0") + public SectionProperties clone() { + return copy(); + } - return copy; + @Override + public SectionProperties copy() { + return new SectionProperties(this); } - + /** * sprmSRncFtn, [MS-DOC], 20140721, 2.6.4 - * + * * @param field_60_rncftn unsigned 8-bit integer specifying the footnote numbering restart condition */ public void setRncFtn(final short field_60_rncftn) { this.field_60_rncftn = field_60_rncftn; } - + /** * @see #setRncFtn(short) * @return an Rnc value specifying when and where footnote numbering restarts @@ -68,16 +79,16 @@ public final class SectionProperties ext public short getRncFtn() { return this.field_60_rncftn; } - + /** * sprmSRncEdn, [MS-DOC], 20140721, 2.6.4 - * + * * @param field_61_rncedn unsigned 8-bit integer specifying the endnote numbering restart condition */ public void setRncEdn(final short field_61_rncedn) { this.field_61_rncedn = field_61_rncedn; } - + /** * @see #setRncEdn(short) * @return an Rnc value specifying when and where endnote numbering restarts @@ -85,16 +96,16 @@ public final class SectionProperties ext public short getRncEdn() { return this.field_61_rncedn; } - + /** * sprmSNftn, [MS-DOC], v20140721, 2.6.4 - * + * * @param field_62_nftn a number specifying the offset to add to footnote numbers */ public void setNFtn(final int field_62_nftn) { this.field_62_nftn = field_62_nftn; } - + /** * @see #setNFtn(int) * @return a 16-bit integer specifying the offset to add to footnote numbering @@ -102,34 +113,34 @@ public final class SectionProperties ext public int getNFtn() { return this.field_62_nftn; } - + /** * sprmSNfcFtnRef, [MS-DOC], v20140721 - * + * * @param field_63_nfcftnref an Nfc specifying the numbering format for footnotes */ public void setNfcFtnRef(final int field_63_nfcftnref) { this.field_63_nfcftnref = field_63_nfcftnref; } - + /** - * + * * @see #setNfcFtnRef(int) * @return a 16-bit integer with an Nfc specifying the numbering format for footnotes */ public int getNfcFtnRef() { return this.field_63_nfcftnref; } - + /** * sprmSNEdn, [MS-DOC], v20140721, 2.6.4 - * + * * @param field_64_nedn a number specifying the offset to add to footnote numbers */ public void setNEdn(final int field_64_nedn) { this.field_64_nedn = field_64_nedn; } - + /** * @see #setNEdn(int) * @return a 16-bit integer specifying the offset to add to endnote numbering @@ -137,18 +148,18 @@ public final class SectionProperties ext public int getNEdn() { return this.field_64_nedn; } - + /** * sprmSNfcEdnRef, [MS-DOC], v20140721 - * + * * @param field_65_nfcednref an Nfc specifying the numbering format for endnotes */ public void setNfcEdnRef(final int field_65_nfcednref) { this.field_65_nfcednref = field_65_nfcednref; } - + /** - * + * * @see #setNfcEdnRef(int) * @return a 16-bit integer with an Nfc specifying the numbering format for endnotes */ Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ShadingDescriptor.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ShadingDescriptor.java?rev=1871938&r1=1871937&r2=1871938&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ShadingDescriptor.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ShadingDescriptor.java Tue Dec 24 11:56:42 2019 @@ -17,30 +17,36 @@ package org.apache.poi.hwpf.usermodel; +import org.apache.poi.common.Duplicatable; import org.apache.poi.hwpf.model.types.SHDAbstractType; +import org.apache.poi.util.Removal; /** * The SHD is a substructure of the CHP, PAP, and TC for Word 2000. - * - * @author vlsergey */ -public final class ShadingDescriptor extends SHDAbstractType implements - Cloneable -{ +public final class ShadingDescriptor extends SHDAbstractType implements Duplicatable { - public ShadingDescriptor() - { + public ShadingDescriptor() {} + + public ShadingDescriptor(ShadingDescriptor other) { + super(other); } - public ShadingDescriptor( byte[] buf, int offset ) - { - super(); + public ShadingDescriptor( byte[] buf, int offset ) { fillFields( buf, offset ); } - public ShadingDescriptor clone() throws CloneNotSupportedException - { - return (ShadingDescriptor) super.clone(); + @Override + @SuppressWarnings("squid:S2975") + @Deprecated + @Removal(version = "5.0.0") + public ShadingDescriptor clone() { + return copy(); + } + + @Override + public ShadingDescriptor copy() { + return new ShadingDescriptor(this); } public boolean isEmpty() Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ShadingDescriptor80.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ShadingDescriptor80.java?rev=1871938&r1=1871937&r2=1871938&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ShadingDescriptor80.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ShadingDescriptor80.java Tue Dec 24 11:56:42 2019 @@ -17,36 +17,42 @@ package org.apache.poi.hwpf.usermodel; +import org.apache.poi.common.Duplicatable; import org.apache.poi.hwpf.model.Colorref; - import org.apache.poi.hwpf.model.types.SHD80AbstractType; +import org.apache.poi.util.Removal; /** * The SHD80 is a substructure of the CHP and PAP, and TC for Word 97. */ -public final class ShadingDescriptor80 extends SHD80AbstractType implements - Cloneable -{ +@SuppressWarnings("unused") +public final class ShadingDescriptor80 extends SHD80AbstractType implements Duplicatable { + + public ShadingDescriptor80() {} - public ShadingDescriptor80() - { + public ShadingDescriptor80(ShadingDescriptor80 other) { + super(other); } - public ShadingDescriptor80( byte[] buf, int offset ) - { - super(); + public ShadingDescriptor80( byte[] buf, int offset ) { fillFields( buf, offset ); } - public ShadingDescriptor80( short value ) - { - super(); + public ShadingDescriptor80( short value ) { field_1_value = value; } - public ShadingDescriptor80 clone() throws CloneNotSupportedException - { - return (ShadingDescriptor80) super.clone(); + @Override + @SuppressWarnings({"squid:S2975", "MethodDoesntCallSuperMethod"}) + @Deprecated + @Removal(version = "5.0.0") + public ShadingDescriptor80 clone() { + return copy(); + } + + @Override + public ShadingDescriptor80 copy() { + return new ShadingDescriptor80(this); } public boolean isEmpty() Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableAutoformatLookSpecifier.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableAutoformatLookSpecifier.java?rev=1871938&r1=1871937&r2=1871938&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableAutoformatLookSpecifier.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableAutoformatLookSpecifier.java Tue Dec 24 11:56:42 2019 @@ -18,35 +18,34 @@ package org.apache.poi.hwpf.usermodel; import java.util.Objects; +import org.apache.poi.common.Duplicatable; import org.apache.poi.hwpf.model.types.TLPAbstractType; +import org.apache.poi.util.Removal; -public class TableAutoformatLookSpecifier extends TLPAbstractType implements - Cloneable -{ +public class TableAutoformatLookSpecifier extends TLPAbstractType implements Duplicatable { public static final int SIZE = 4; - public TableAutoformatLookSpecifier() - { - super(); + public TableAutoformatLookSpecifier() {} + + public TableAutoformatLookSpecifier(TableAutoformatLookSpecifier other) { + super(other); } - public TableAutoformatLookSpecifier( byte[] data, int offset ) - { - super(); + public TableAutoformatLookSpecifier( byte[] data, int offset ) { fillFields( data, offset ); } @Override - public TableAutoformatLookSpecifier clone() - { - try - { - return (TableAutoformatLookSpecifier) super.clone(); - } - catch ( CloneNotSupportedException e ) - { - throw new Error( e.getMessage(), e ); - } + @SuppressWarnings({"squid:S2975", "MethodDoesntCallSuperMethod"}) + @Deprecated + @Removal(version = "5.0.0") + public TableAutoformatLookSpecifier clone() { + return copy(); + } + + @Override + public TableAutoformatLookSpecifier copy() { + return new TableAutoformatLookSpecifier(this); } @Override Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableCellDescriptor.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableCellDescriptor.java?rev=1871938&r1=1871937&r2=1871938&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableCellDescriptor.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableCellDescriptor.java Tue Dec 24 11:56:42 2019 @@ -17,16 +17,18 @@ package org.apache.poi.hwpf.usermodel; +import org.apache.poi.common.Duplicatable; import org.apache.poi.hwpf.model.types.TCAbstractType; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.Removal; -public final class TableCellDescriptor extends TCAbstractType implements - Cloneable -{ +public final class TableCellDescriptor extends TCAbstractType implements Duplicatable { public static final int SIZE = 20; - public TableCellDescriptor() - { + public TableCellDescriptor() {} + + public TableCellDescriptor(TableCellDescriptor other) { + super(other); } protected void fillFields(byte[] data, int offset) @@ -49,16 +51,17 @@ public final class TableCellDescriptor e getBrcRight().serialize(data, 0x10 + offset); } - public Object clone() - throws CloneNotSupportedException - { - TableCellDescriptor tc = (TableCellDescriptor)super.clone(); - tc.setShd( getShd().clone() ); - tc.setBrcTop((BorderCode)getBrcTop().clone()); - tc.setBrcLeft((BorderCode)getBrcLeft().clone()); - tc.setBrcBottom((BorderCode)getBrcBottom().clone()); - tc.setBrcRight((BorderCode)getBrcRight().clone()); - return tc; + @Override + @SuppressWarnings({"squid:S2975", "MethodDoesntCallSuperMethod"}) + @Deprecated + @Removal(version = "5.0.0") + public TableCellDescriptor clone() { + return copy(); + } + + @Override + public TableCellDescriptor copy() { + return new TableCellDescriptor(this); } public static TableCellDescriptor convertBytesToTC(byte[] buf, int offset) Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableProperties.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableProperties.java?rev=1871938&r1=1871937&r2=1871938&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableProperties.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableProperties.java Tue Dec 24 11:56:42 2019 @@ -17,33 +17,34 @@ package org.apache.poi.hwpf.usermodel; +import org.apache.poi.common.Duplicatable; import org.apache.poi.hwpf.model.types.TAPAbstractType; +import org.apache.poi.util.Removal; -public final class TableProperties extends TAPAbstractType implements Cloneable -{ +public final class TableProperties extends TAPAbstractType implements Duplicatable { - public TableProperties() - { - setTlp( new TableAutoformatLookSpecifier() ); - setShdTable( new ShadingDescriptor() ); - setBrcBottom( new BorderCode() ); - setBrcHorizontal( new BorderCode() ); - setBrcLeft( new BorderCode() ); - setBrcRight( new BorderCode() ); - setBrcTop( new BorderCode() ); - setBrcVertical( new BorderCode() ); - setRgbrcInsideDefault_0( new BorderCode() ); - setRgbrcInsideDefault_1( new BorderCode() ); - setRgdxaCenter( new short[0] ); - setRgdxaCenterPrint( new short[0] ); - setRgshd( new ShadingDescriptor[0] ); - setRgtc( new TableCellDescriptor[0] ); + public TableProperties() { + setTlp(new TableAutoformatLookSpecifier()); + setShdTable(new ShadingDescriptor()); + setBrcBottom(new BorderCode()); + setBrcHorizontal(new BorderCode()); + setBrcLeft(new BorderCode()); + setBrcRight(new BorderCode()); + setBrcTop(new BorderCode()); + setBrcVertical(new BorderCode()); + setRgbrcInsideDefault_0(new BorderCode()); + setRgbrcInsideDefault_1(new BorderCode()); + setRgdxaCenter(new short[0]); + setRgdxaCenterPrint(new short[0]); + setRgshd(new ShadingDescriptor[0]); + setRgtc(new TableCellDescriptor[0]); } - public TableProperties( short columns ) - { - this(); + public TableProperties(TableProperties other) { + super(other); + } + public TableProperties( short columns ) { setItcMac( columns ); setRgshd( new ShadingDescriptor[columns] ); @@ -63,40 +64,16 @@ public final class TableProperties exten setRgdxaCenterPrint( new short[columns] ); } - public Object clone() throws CloneNotSupportedException - { - TableProperties tap = (TableProperties) super.clone(); - - tap.setTlp( getTlp().clone() ); - tap.setRgshd( new ShadingDescriptor[getRgshd().length] ); - for ( int x = 0; x < getRgshd().length; x++ ) - { - tap.getRgshd()[x] = getRgshd()[x].clone(); - } - - tap.setBrcBottom( (BorderCode) getBrcBottom().clone() ); - tap.setBrcHorizontal( (BorderCode) getBrcHorizontal().clone() ); - tap.setBrcLeft( (BorderCode) getBrcLeft().clone() ); - tap.setBrcRight( (BorderCode) getBrcRight().clone() ); - tap.setBrcTop( (BorderCode) getBrcTop().clone() ); - tap.setBrcVertical( (BorderCode) getBrcVertical().clone() ); - - tap.setShdTable( getShdTable().clone() ); - - tap.setRgbrcInsideDefault_0( (BorderCode) getRgbrcInsideDefault_0() - .clone() ); - tap.setRgbrcInsideDefault_1( (BorderCode) getRgbrcInsideDefault_1() - .clone() ); - - tap.setRgdxaCenter( getRgdxaCenter().clone() ); - tap.setRgdxaCenterPrint( getRgdxaCenterPrint().clone() ); - - tap.setRgtc( new TableCellDescriptor[getRgtc().length] ); - for ( int x = 0; x < getRgtc().length; x++ ) - { - tap.getRgtc()[x] = (TableCellDescriptor) getRgtc()[x].clone(); - } - return tap; + @Override + @SuppressWarnings({"squid:S2975", "MethodDoesntCallSuperMethod"}) + @Deprecated + @Removal(version = "5.0.0") + public TableProperties clone() { + return copy(); } + @Override + public TableProperties copy() { + return new TableProperties(this); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@poi.apache.org For additional commands, e-mail: commits-h...@poi.apache.org