diff options
Diffstat (limited to 'xmerge/source/xmerge/java/org/openoffice/xmerge/merger')
21 files changed, 492 insertions, 583 deletions
diff --git a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/DiffAlgorithm.java b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/DiffAlgorithm.java index 00969b038e1d..a39649b03a91 100644 --- a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/DiffAlgorithm.java +++ b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/DiffAlgorithm.java @@ -19,24 +19,25 @@ package org.openoffice.xmerge.merger; /** - * This is the difference algorithm interface. It is an interface so - * that different algorithms may be plugged-in to actually compute - * the differences. + * This is the difference algorithm interface. * - * NOTE: this code may not be thread safe. + * <p>It is an interface so that different algorithms may be plugged-in to + * actually compute the differences.</p> + * + * <p>NOTE: this code may not be thread safe.</p> */ public interface DiffAlgorithm { /** - * Returns a <code>Difference</code> array. This method finds out - * the difference between two sequences. + * Returns a {@code Difference} array. + * + * <p>This method finds out the difference between two sequences.</p> * - * @param orgSeq The original sequence of object. - * @param modSeq The modified (or changed) sequence to - * compare against with the origial. + * @param orgSeq The original sequence of object. + * @param modSeq The modified (or changed) sequence to compare against + * with the original. * - * @return A <code>Difference</code> array. + * @return A {@code Difference} array. */ Difference[] computeDiffs(Iterator orgSeq, Iterator modSeq); -} - +}
\ No newline at end of file diff --git a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/Difference.java b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/Difference.java index feccb757a085..b24c2c78379d 100644 --- a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/Difference.java +++ b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/Difference.java @@ -18,118 +18,104 @@ package org.openoffice.xmerge.merger; - /** - * This is the <code>Difference</code> basic unit. Used by the - * <code>DiffAlgorithm</code> as a set of difference between two - * <code>Iterators</code> (the original and modified - * <code>Iterators</code>). + * This is the {@code Difference} basic unit. + * + * Used by the {@code DiffAlgorithm} as a set of difference between two + * {@code Iterators} (the original and modified {@code Iterators}). */ public final class Difference { - /** - * Add operation. - */ + /** Add operation. */ public static final int ADD = 1; - /** - * Delete operation. - */ + /** Delete operation. */ public static final int DELETE = 2; - /** - * Change operation. - */ + /** Change operation. */ public static final int CHANGE = 3; - /** - * Unchange operation (i.e. no change). - */ + /** Unchange operation (i.e. no change). */ public static final int UNCHANGE = 4; - /** - * The action of the diff - either {@link #ADD} or {@link #DELETE}. - */ + /** The action of the diff - either {@link #ADD} or {@link #DELETE} */ private int operation; /** - * <p>The position of the content that should be operated on (original - * iterator).</p> - * - * <p>For ADD, the orgPosition is the position of the original sequence - * where the diff will insert (the element count is starting from 0, and - * always insert before the element). The modPosition is the position - * of the diff in the modified sequence (also starting from 0).</p> - * - * <blockquote><pre> - * example: - * - * diff - <B D>and <A B C D E F> - * note: <B D>is original sequence and <A B C D E F> - * is the modified one. - * - * and here is the position of those sequence: - * <B D> <A B C D E F> - * 0 1 0 1 2 3 4 5 - * - * result: - * <diff orgPos=0 modPos=0 operation=ADD> <-- element A - * <diff orgPos=1 modPos=2 operation=ADD> <-- element C - * <diff orgPos=2 modPos=4 operation=ADD> <-- element E - * <diff orgPos=2 modPos=5 operation=ADD> <-- element F - * - * </pre> </blockquote> - * <p>One can notice the add operation is inserted before the position. - * Hence, in order to append an element, we will have a position of - * original sequence length + 1 to denote an append.</p> - * - * <p>For DELETE, orgPosition is the position that the element - * will be deleted (starting from 0) and modPosition is the position - * where the deleted element should be (consider as an ADD).</p> - * - * <p>The modPosition is less useful and it is difficult to understand - * how the position is calculated. One can just skip this piece of - * information. It is useful if one wants to reverse the role - * of original sequence and modified sequence and find out the diff - * easily (just change add to delete and delete to add for operation - * and swap the orgPosition and modPosition).</p> - * - * <blockquote><pre> - * example: - * - * diff - <A B C D E F> and < B D> - * note: <A B C D E F> is original sequence and <B D> - * is the modified one. - * - * and here is the position of those sequence: - * <A B C D E F> <B D> - * 0 1 2 3 4 5 0 1 - * - * result: - * <diff orgPos=0 modPos=0 operation=DELETE> <-- element A - * <diff orgPos=2 modPos=1 operation=DELETE> <-- element C - * <diff orgPos=4 modPos=2 operation=DELETE> <-- element E - * <diff orgPos=5 modPos=2 operation=DELETE> <-- element F - * </pre></blockquote> + * The position of the content that should be operated on (original + * {@code iterator}). + * + * <p>For {@code ADD}, the {@code orgPosition} is the position of the + * original sequence where the diff will insert (the element count is + * starting from 0, and always insert before the element). The + * {@code modPosition} is the position of the diff in the modified sequence + * (also starting from 0).</p> + * + * <blockquote><pre>{@literal example: + * + * diff - <B D> and <A B C D E F> + * note: <B D> is original sequence and <A B C D E F> + * is the modified one. + * + * and here is the position of those sequence: + * <B D> <A B C D E F> + * 0 1 0 1 2 3 4 5 + * + * result: + * <diff orgPos=0 modPos=0 operation=ADD> <-- element A + * <diff orgPos=1 modPos=2 operation=ADD> <-- element C + * <diff orgPos=2 modPos=4 operation=ADD> <-- element E + * <diff orgPos=2 modPos=5 operation=ADD> <-- element F}</pre></blockquote> + * + * <p>One can notice the add operation is inserted before the position. + * Hence, in order to append an element, we will have a position of original + * sequence length + 1 to denote an append.</p> + * + * <p>For {@code DELETE}, {@code orgPosition} is the position that the + * element will be deleted (starting from 0) and {@code modPosition} is the + * position where the deleted element should be (consider as an {@code ADD}). + * </p> + * + * <p>The {@code modPosition} is less useful and it is difficult to + * understand how the position is calculated. One can just skip this piece + * of information. It is useful if one wants to reverse the role of original + * sequence and modified sequence and find out the diff easily (just change + * add to delete and delete to add for operation and swap the + * {@code orgPosition} and {@code modPosition}).</p> + * + * <blockquote><pre>{@literal example: + * + * diff - <A B C D E F> and <B D> + * note: <A B C D E F> is original sequence and <B D> + * is the modified one. + * + * and here is the position of those sequence: + * <A B C D E F> <B D> + * 0 1 2 3 4 5 0 1 + * + * result: + * <diff orgPos=0 modPos=0 operation=DELETE> <-- element A + * <diff orgPos=2 modPos=1 operation=DELETE> <-- element C + * <diff orgPos=4 modPos=2 operation=DELETE> <-- element E + * <diff orgPos=5 modPos=2 operation=DELETE> <-- element F}</pre></blockquote> */ private int orgPosition; /** - * The position of the content that should be operated (modified iterator). - * For explanation and examples, see {@link #orgPosition}. + * The position of the content that should be operated (modified iterator). + * + * <p>For explanation and examples, see {@link #orgPosition}</p>. */ private int modPosition; - /** - * Constructor. This is the standard way to create a - * <code>Difference</code> object. - * - * @param operation Either {@link #ADD} or {@link #DELETE}. - * @param orgPosition The position in the original (first) - * <code>Iterator</code>. - * @param modPosition The position in the modified (second) - * <code>Iterator</code>. + * Constructor. + * + * This is the standard way to create a {@code Difference} object. + * + * @param operation Either {@link #ADD} or {@link #DELETE}. + * @param orgPosition The position in the original (first) {@code Iterator}. + * @param modPosition The position in the modified (second) {@code Iterator}. */ public Difference(int operation, int orgPosition, int modPosition) { @@ -138,43 +124,42 @@ public final class Difference { this.modPosition = modPosition; } - /** - * Get the operation of the <code>Difference</code>. + * Get the operation of the {@code Difference}. * - * @return the operation of the <code>Difference</code>, - * either {@link #ADD} or {@link #DELETE} + * @return the operation of the {@code Difference}, either {@link #ADD} or + * {@link #DELETE}. */ public int getOperation() { return operation; } /** - * Get the original <code>Iterator</code> position. + * Get the original {@code Iterator} position. * - * @return The position in the original (first) <code>Iterator</code> + * @return The position in the original (first) {@code Iterator}. */ public int getOrgPosition() { return orgPosition; } /** - * Get the modified <code>Iterator</code> position. + * Get the modified {@code Iterator} position. * - * @return The position in the modified (second) <code>Iterator</code> + * @return The position in the modified (second) {@code Iterator}. */ public int getModPosition() { return modPosition; } - /** - * Two <code>Difference</code> objects will equal if and only if - * all operation, orgPosition, modPosition and content are equal. + * Two {@code Difference} objects will equal if and only if all + * {@code operation}, {@code orgPosition}, {@code modPosition} and + * {@code content} are equal. * - * @param obj Object to compare. + * @param obj {@code Object} to compare. * - * @return true if equal, false otherwise. + * @return {@code true} if equal, {@code false} otherwise. */ @Override public boolean equals(Object obj) { @@ -191,9 +176,9 @@ public final class Difference { } /** - * Display debug information. + * Display debug information. * - * @return Debug string. + * @return Debug string. */ public String debug() { @@ -220,14 +205,14 @@ public final class Difference { } /** - * Returns position and operation values as a single string. + * Returns position and operation values as a single string. * - * @return orgPosition, modPosition and operation as a single string. + * @return {@code orgPosition}, {@code modPosition} and {@code operation} + * as a single {@code String}. */ @Override public String toString() { return orgPosition + " " + modPosition + " " + operation; } -} - +}
\ No newline at end of file diff --git a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/Iterator.java b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/Iterator.java index a2f05f7e37df..c6698283f980 100644 --- a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/Iterator.java +++ b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/Iterator.java @@ -19,35 +19,33 @@ package org.openoffice.xmerge.merger; /** - * This is an interface used by the {@link - * org.openoffice.xmerge.merger.DiffAlgorithm - * DiffAlgorithm} and {@link - * org.openoffice.xmerge.merger.MergeAlgorithm - * MergeAlgorithm} to access a <code>Document</code>. + * This is an interface used by the {@link + * org.openoffice.xmerge.merger.DiffAlgorithm DiffAlgorithm} and {@link + * org.openoffice.xmerge.merger.MergeAlgorithm MergeAlgorithm} to access a + * {@code Document}. */ public interface Iterator { - /** - * Move to next element in the sequence. + * Move to next element in the sequence. * - * @return The <code>Object</code> of the next element in the sequence. - * If there is no next element, then return null. + * @return The {@code Object} of the next element in the sequence. If there + * is no next element, then return {@code null}. */ Object next(); /** * Move to the beginning of the sequence. * - * @return The <code>Object</code> of the first element in the sequence. - * If it is empty, then return null. + * @return The {@code Object} of the first element in the sequence. If it + * is empty, then return {@code null}. */ Object start(); /** - * Return the current element <code>Object</code> content. + * Return the current element {@code Object} content. * - * @return The <code>Object</code> at current position. + * @return The {@code Object} at current position. */ Object currentElement(); @@ -59,32 +57,29 @@ public interface Iterator { int elementCount(); /** - * A method to allow the difference algorithm to test whether the - * <code>obj1</code> and <code>obj2</code> in the - * <code>Iterator</code> are considered equal. As not every - * <code>Object</code> in the <code>Iterator</code> can implement its - * own equal method, with this equivalent method, we can allow - * flexibility for the <code>Iterator</code> to choose a custom way - * to compare two objects. Two objects can even be compared based on - * the position in the <code>Iterator</code> rather than by - * the content via this option. + * A method to allow the difference algorithm to test whether the {@code obj1} + * and {@code obj2} in the {@code Iterator} are considered equal. + * + * <p>As not every {@code Object} in the {@code Iterator} can implement its + * own equal method, with this equivalent method, we can allow flexibility + * for the {@code Iterator} to choose a custom way to compare two objects. + * Two objects can even be compared based on the position in the + * {@code Iterator} rather than by the content via this option. * - * @param obj1 The first <code>Object</code>. - * @param obj2 The second <code>Object</code>. + * @param obj1 The first {@code Object} + * @param obj2 The second {@code Object}. * - * @return true if equal, false otherwise. + * @return {@code true} if equal, {@code false} otherwise. */ boolean equivalent(Object obj1, Object obj2); - /** - * <p>A method to force the <code>Iterator</code> to transverse the tree - * again to refresh the content.</p> + * A method to force the {@code Iterator} to transverse the tree again to + * refresh the content. * - * <p>It is used mainly for <code>Iterator</code> objects which take a snap - * shot instead of dynamically transversing the tree. The current - * position will be set to the beginning.</p> + * <p>It is used mainly for {@code Iterator} objects which take a snap shot + * instead of dynamically transversing the tree. The current position will + * be set to the beginning.</p> */ void refresh(); -} - +}
\ No newline at end of file diff --git a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/MergeAlgorithm.java b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/MergeAlgorithm.java index e4164da4b611..f74a9992b7ff 100644 --- a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/MergeAlgorithm.java +++ b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/MergeAlgorithm.java @@ -23,25 +23,26 @@ import org.openoffice.xmerge.merger.Iterator; import org.openoffice.xmerge.merger.Difference; /** - * This is the <code>MergeAlgorithm</code> interface. It is an - * interface so that different merge algorithms may be plugged-in - * to actually merge the diffs back to an original document. + * This is the {@code MergeAlgorithm} interface. + * + * <p>It is an interface so that different merge algorithms may be plugged-in + * to actually merge the diffs back to an original document.</p> */ public interface MergeAlgorithm { /** - * This method is to merge the difference to an <code>Iterator</code>. - * The original <code>Iterator</code> will be modified after the call. + * This method is to merge the difference to an {@code Iterator}. + * + * <p>The original {@code Iterator} will be modified after the call.</p> * - * @param orgSeq The original sequence which the difference - * will be applied. It will be modified. - * @param modSeq The modified sequence where the difference - * content will be extracted. - * @param differences The <code>Difference</code> array. + * @param orgSeq The original sequence which the difference will be + * applied. It will be modified. + * @param modSeq The modified sequence where the difference content + * will be extracted. + * @param differences The {@code Difference} array. * - * @throws MergeException If an error occurs during the merge. + * @throws MergeException If an error occurs during the merge. */ void applyDifference(Iterator orgSeq, Iterator modSeq, - Difference[] differences) throws MergeException; -} - + Difference[] differences) throws MergeException; +}
\ No newline at end of file diff --git a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/NodeMergeAlgorithm.java b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/NodeMergeAlgorithm.java index 0cf32b2a9e2a..98a9a8bd10be 100644 --- a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/NodeMergeAlgorithm.java +++ b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/NodeMergeAlgorithm.java @@ -21,21 +21,20 @@ package org.openoffice.xmerge.merger; import org.w3c.dom.Node; /** - * This is an interface for a {@link - * org.openoffice.xmerge.merger.MergeAlgorithm - * MergeAlgorithm} to merge two <code>Node</code> objects. It is an - * interface so that different merge algorithms may be plugged-in. + * This is an interface for a {@link org.openoffice.xmerge.merger.MergeAlgorithm + * MergeAlgorithm} to merge two {@code Node} objects. + * + * <p>It is an interface so that different merge algorithms may be plugged-in.</p> */ public interface NodeMergeAlgorithm { /** - * This method is used to merge two given <code>Node</code> - * objects. Note: the original <code>Node</code> may be modified. + * This method is used to merge two given {@code Node} objects. + * + * <p>Note: the original {@code Node} may be modified.</p> * - * @param originalNode The original <code>Node</code>. - * @param modifyNode The <code>Node</code> to be merged. It may - * be modified. + * @param originalNode The original {@code Node}. + * @param modifyNode The {@code Node} to be merged. It may be modified. */ void merge(Node originalNode, Node modifyNode); -} - +}
\ No newline at end of file diff --git a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/CellNodeIterator.java b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/CellNodeIterator.java index 9e7eb332d6a5..3d2dfc144d77 100644 --- a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/CellNodeIterator.java +++ b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/CellNodeIterator.java @@ -24,18 +24,17 @@ import org.w3c.dom.Element; import org.openoffice.xmerge.ConverterCapabilities; import org.openoffice.xmerge.converter.xml.OfficeConstants; - /** - * <p>This is an implementations of the <code>Iterator</code> interface. - * It will traverse the tree and find cell <code>Node</code> sequences.</p> + * This is an implementations of the {@code Iterator} interface. + * + * <p>It will traverse the tree and find cell {@code Node} sequences.</p> * - * <p>Note: Once the XML Tree is parsed, then the <code>Iterator</code> - * will be a snap shot of that tree. That means even the tree is - * modified later, than the cached paragraph <code>Node</code> list will - * not be updated accordingly. For this reason and for performance reasons - * this <code>Iterator</code> does not support any operation methods such - * as insert, remove or replace. The main purpose of this - * <code>Iterator</code> is to be used with difference, not with merge.</p> + * <p>Note: Once the XML Tree is parsed, then the {@code Iterator} will be a + * snap shot of that tree. That means even the tree is modified later, than the + * cached paragraph {@code Node} list will not be updated accordingly. For this + * reason and for performance reasons this {@code Iterator} does not support any + * operation methods such as insert, remove or replace. The main purpose of this + * {@code Iterator} is to be used with difference, not with merge.</p> */ public final class CellNodeIterator extends NodeIterator { @@ -43,23 +42,24 @@ public final class CellNodeIterator extends NodeIterator { private static final String SUPPORTED_TAG1 = OfficeConstants.TAG_TABLE_CELL; /** - * The standard constructor. + * The standard constructor. * - * @param cc The <code>ConverterCapabilities</code>. - * @param node The initial root <code>Node</code>. + * @param cc The {@code ConverterCapabilities}. + * @param node The initial root {@code Node}. */ public CellNodeIterator(ConverterCapabilities cc, Node node) { super(cc, node); } - /** - * Overwrite the parent <code>nodeSupported</code> method. Only cell - * <code>Node</code> objects are supported. + * Overwrite the parent {@code nodeSupported} method. * - * @param node The <code>Node</code> to check. + * <p>Only cell {@code Node} objects are supported.</p> * - * @return true if the <code>Node</code> is supported, false otherwise. + * @param node The {@code Node} to check. + * + * @return {@code true} if the {@code Node} is supported, {@code false} + * otherwise. */ @Override protected boolean nodeSupported(Node node) { @@ -70,7 +70,6 @@ public final class CellNodeIterator extends NodeIterator { node.getNodeName().equals(SUPPORTED_TAG1); } - @Override protected boolean childrenEqual(Node node1, Node node2) { @@ -94,5 +93,4 @@ public final class CellNodeIterator extends NodeIterator { return equal; } -} - +}
\ No newline at end of file diff --git a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/CharArrayLCSAlgorithm.java b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/CharArrayLCSAlgorithm.java index 6f558e00bf84..1501bd3f3556 100644 --- a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/CharArrayLCSAlgorithm.java +++ b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/CharArrayLCSAlgorithm.java @@ -22,24 +22,25 @@ import java.util.ArrayList; import org.openoffice.xmerge.merger.Difference; /** - * <p>This is an implementations of <code>DiffAlgorithm</code> interface - * which will difference char arrays.</p> + * This is an implementations of {@code DiffAlgorithm} interface which will + * difference char arrays. * - * <p>It also use Longest Common Subsequence (LCS). The algorithm is based - * on the book "Introduction to Algorithms" by Thomas H.Cormen, - * Charles E.Leiserson, and Ronald L.Riverst (MIT Press 1990) page 314.</p> + * <p>It also use Longest Common Subsequence (LCS). The algorithm is based on + * the book "Introduction to Algorithms" by Thomas H.Cormen, Charles E.Leiserson, + * and Ronald L.Riverst (MIT Press 1990) page 314.</p> */ public class CharArrayLCSAlgorithm { /** - * Return an <code>Difference</code> array. This method finds out - * the difference between two sequences. + * Return an {@code Difference} array. * - * @param orgSeq The original sequence. - * @param modSeq The modified (or changed) sequence to - * compare against the origial. + * <p>This method finds out the difference between two sequences.</p> * - * @return A <code>Difference</code> array. + * @param orgSeq The original sequence. + * @param modSeq The modified (or changed) sequence to compare against + * the original. + * + * @return A {@code Difference} array. */ public Difference[] computeDiffs(char[] orgSeq, char[] modSeq) { @@ -72,15 +73,15 @@ public class CharArrayLCSAlgorithm { } /** - * Create the difference table. - * The difference table is used internal to keep track what - * elements are common or different in the two sequences. + * Create the difference table. + * + * <p>The difference table is used internal to keep track what elements are + * common or different in the two sequences.</p> * - * @param orgSeq The original sequence to be used as a base. - * @param modSeq The modified sequence to compare. + * @param orgSeq The original sequence to be used as a base. + * @param modSeq The modified sequence to compare. * - * @return A difference table as a two-dimensional array of - * integers. + * @return A difference table as a two-dimensional array of integers. */ private int[][] createDiffTable(char[] orgSeq, char[] modSeq) { int orgSeqlen = orgSeq.length + 1; @@ -114,27 +115,25 @@ public class CharArrayLCSAlgorithm { return diffTable; } - /** - * Generate the <code>Difference</code> result vector. - * This method will be called recursively to backtrack the difference - * table to get the difference result (and also the LCS). + * Generate the {@code Difference} result vector. * - * @param diffTable The difference table containing the - * <code>Difference</code> result. - * @param i The nth element in original sequence to - * compare. This method is called recursively - * with i and j decreased until 0. - * @param j The nth element in modified sequence to - * compare. - * @param diffVector A vector to output the <code>Difference</code> - * result. Can not use a return variable as it - * is a recursive method. The vector will contain - * <code>Difference</code> objects with operation - * and positions filled in. + * <p>This method will be called recursively to backtrack the difference + * table to get the difference result (and also the LCS).</p> + * + * @param diffTable The difference table containing the {@code Difference} + * result. + * @param i The nth element in original sequence to compare. This + * method is called recursively with {@code i} and + * {@code j} decreased until {@code 0}. + * @param j The nth element in modified sequence to compare. + * @param diffVector A vector to output the {@code Difference} result. + * Can not use a return variable as it is a recursive + * method. The vector will contain {@code Difference} + * objects with operation and positions filled in. */ - private void generateResult(int[][] diffTable, - int i, int j, ArrayList<Difference> diffVector) { + private void generateResult(int[][] diffTable, int i, int j, + ArrayList<Difference> diffVector) { // handle the first element if (i == 0 || j == 0) { @@ -195,5 +194,4 @@ public class CharArrayLCSAlgorithm { } } } -} - +}
\ No newline at end of file diff --git a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/CharacterParser.java b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/CharacterParser.java index 258401e4135b..8b634ae821c1 100644 --- a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/CharacterParser.java +++ b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/CharacterParser.java @@ -25,20 +25,20 @@ import org.openoffice.xmerge.converter.xml.OfficeConstants; import java.util.ArrayList; import java.util.List; - /** - * <p>This is a parser to return a character array for difference purpose. - * It will use depth first search to traverse all the characters inside the - * text <code>Node</code> under a given <code>Node</code> (most likely to be - * a paragraph <code>Node</code>).</p> + * This is a parser to return a character array for difference purpose. + * + * <p>It will use depth first search to traverse all the characters inside the + * text {@code Node} under a given {@code Node} (most likely to be a paragraph + * {@code Node}).</p> * - * <p>Note: Once the XML Tree is parsed, then the <code>Iterator</code> will be - * a snap shot of that tree. That means even the tree is modified later, than - * the cached paragraph <code>Node</code> list will not be updated accordingly. - * For this reason and for performance reasons this <code>Iterator</code> does - * not support any operation methods such as insert, remove or replace. The - * main purpose of this <code>Iterator</code> is to be used with difference, - * not with merge.</p> + * <p>Note: Once the XML Tree is parsed, then the {@code Iterator} will be a + * snap shot of that tree. That means even the tree is modified later, than + * the cached paragraph {@code Node} list will not be updated accordingly. For + * this reason and for performance reasons this {@code Iterator} does not + * support any operation methods such as insert, remove or replace. The main + * purpose of this {@code Iterator} is to be used with difference, not with + * merge.</p> */ public class CharacterParser { @@ -47,11 +47,10 @@ public class CharacterParser { private List<TextNodeEntry> nodeList_ = null; private char[] charArray; - /** - * Standard constructor. + * Standard constructor. * - * @param node The initial root <code>Node</code>. + * @param node The initial root {@code Node}. */ public CharacterParser(Node node) { textNodes = new TextNodeIterator(node); @@ -60,11 +59,10 @@ public class CharacterParser { parseNodes(); } - /** - * Returns the <code>Node</code> pointer with the given character position. + * Returns the {@code Node} pointer with the given character position. * - * @return The <code>Node</code> pointer with the given character position. + * @return The {@code Node} pointer with the given character position. */ public List<TextNodeEntry> getNodeList() { // will go through the nodeList to find the corresponding node @@ -112,20 +110,18 @@ public class CharacterParser { charArray = strBuf.toString().toCharArray(); } - /** - * Adds a new <code>Node</code> entry. + * Adds a new {@code Node} entry. * - * @param textLen The text length. - * @param node The <code>Node</code>. + * @param textLen The text length. + * @param node The {@code Node}. */ private void addNewNodeEntry(int textLen, Node node) { TextNodeEntry nodeEntry = new TextNodeEntry(currentPosition, currentPosition + textLen - 1, node); - currentPosition = currentPosition + textLen; + currentPosition = currentPosition + textLen; nodeList_.add(nodeEntry); } -} - +}
\ No newline at end of file diff --git a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/IteratorLCSAlgorithm.java b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/IteratorLCSAlgorithm.java index c7959be59225..909b6f50d4b2 100644 --- a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/IteratorLCSAlgorithm.java +++ b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/IteratorLCSAlgorithm.java @@ -25,10 +25,11 @@ import org.openoffice.xmerge.merger.Iterator; import org.openoffice.xmerge.util.Debug; /** - * This is one of the implementations of <code>DiffAlgorithm</code> interface. - * Using Longest Common Subsequence (LCS). The algorithm here is based - * on the book "Introduction to Algorithms" by Thomas H.Cormen, - * Charles E.Leiserson and Ronald L.Riverst (MIT Press 1990) page 314. + * This is one of the implementations of {@code DiffAlgorithm} interface. + * + * <p>Using Longest Common Subsequence (LCS). The algorithm here is based on the + * book "Introduction to Algorithms" by Thomas H.Cormen, Charles E.Leiserson and + * Ronald L.Riverst (MIT Press 1990) page 314.</p> */ public class IteratorLCSAlgorithm implements DiffAlgorithm { @@ -67,12 +68,10 @@ public class IteratorLCSAlgorithm implements DiffAlgorithm { return diffArray; } - /** - * Debug function used to print out the nicely formatted - * difference table. + * Debug function used to print out the nicely formatted difference table. * - * @param diffTable The difference table to display. + * @param diffTable The difference table to display. */ private void printDiffTable(int[][] diffTable) { @@ -88,15 +87,15 @@ public class IteratorLCSAlgorithm implements DiffAlgorithm { } /** - * Create the difference table. - * The difference table is used internal to keep track what - * elements are common or different in the two sequences. + * Create the difference table. + * + * <p>The difference table is used internal to keep track what elements are + * common or different in the two sequences.</p> * - * @param orgSeq The original sequence to be used as a base. - * @param modSeq The modified sequence to compare. + * @param orgSeq The original sequence to be used as a base. + * @param modSeq The modified sequence to compare. * - * @return A difference table as a two-dimensional array of - * integers. + * @return A difference table as a two-dimensional array of integers. */ private int[][] createDiffTable(Iterator orgSeq, Iterator modSeq) { int orgSeqlen = orgSeq.elementCount() + 1; @@ -139,24 +138,22 @@ public class IteratorLCSAlgorithm implements DiffAlgorithm { return diffTable; } - /** - * Generate the <code>Difference</code> object result vector. - * This method will be called recursively to backtrack the difference - * table to get the difference result (and also the LCS). + * Generate the {@code Difference} object result vector. + * + * <p>This method will be called recursively to backtrack the difference + * table to get the difference result (and also the LCS).</p> * - * @param diffTable The difference table containing the - * <code>Difference</code> result. - * @param i The nth element in original sequence to - * compare. This method is called recursively - * with i and j decreased until 0. - * @param j The nth element in modified sequence to - * compare. - * @param diffVector A vector to output the <code>Difference</code> - * result. Can not use a return variable as it - * is a recursive method. The vector will contain - * <code>Difference</code> objects with operation - * and positions fill in. + * @param diffTable The difference table containing the {@code Difference} + * result. + * @param i The nth element in original sequence to compare. This + * method is called recursively with {@code i} and + * {@code j} decreased until {@code 0}. + * @param j The nth element in modified sequence to compare. + * @param diffVector A vector to output the {@code Difference} result. + * Can not use a return variable as it is a recursive + * method. The vector will contain {@code Difference} + * objects with operation and positions fill in. */ private void generateResult(int[][] diffTable, int i, int j, ArrayList<Difference> diffVector) { @@ -221,5 +218,4 @@ public class IteratorLCSAlgorithm implements DiffAlgorithm { } } } -} - +}
\ No newline at end of file diff --git a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/IteratorRowCompare.java b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/IteratorRowCompare.java index 746709840e28..f2689d1d83a4 100644 --- a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/IteratorRowCompare.java +++ b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/IteratorRowCompare.java @@ -28,30 +28,30 @@ import org.openoffice.xmerge.merger.Iterator; import org.openoffice.xmerge.converter.xml.OfficeConstants; /** - * A very simple and direct difference algorithm for row - * <code>Node</code> objects in a spreadsheet. + * A very simple and direct difference algorithm for row {@code Node} objects in + * a spreadsheet. * - * <p>Basically, it will compare objects in sequence and does not look ahead - * (unlike LCS).</p> + * <p>Basically, it will compare objects in sequence and does not look ahead + * (unlike LCS).</p> * - * <ol> - * <li> - * If two objects are the same, skip to next one. - * </li><li> - * Otherwise check whether the row repeated attribute is the same. - * </li><li> - * If the row repeated attribute is the same, then compare two rows - * and mark it as <i>change</i> if those rows are different. - * </li><li> - * If the row repeated attribute is different, then split the rows and - * continue to compare. - * </li><li> - * If there are more objects in the modseq than the original sequence, - * then all of the extra ones in the modified sequence are marked as add. + * <ol> + * <li> + * If two objects are the same, skip to next one. + * </li><li> + * Otherwise check whether the row repeated attribute is the same. + * </li><li> + * If the row repeated attribute is the same, then compare two rows and mark + * it as <i>change</i> if those rows are different. + * </li><li> + * If the row repeated attribute is different, then split the rows and + * continue to compare. + * </li><li> + * If there are more objects in the modseq than the original sequence, then + * all of the extra ones in the modified sequence are marked as add. * </li><li> * If there are more objects in the original sequence than the modified - * sequence, then all the extra one in the modified sequence are marked - * as delete. + * sequence, then all the extra one in the modified sequence are marked as + * delete. * </li> * </ol> * @@ -61,17 +61,18 @@ import org.openoffice.xmerge.converter.xml.OfficeConstants; public class IteratorRowCompare implements DiffAlgorithm { /** - * Compute the differences of the given two sequences. - * Refer to the class description. + * Compute the differences of the given two sequences. * - * Return an array of <code>Difference</code> objects. This method finds - * out the difference between two sequences. + * <p>Refer to the class description.</p> * - * @param orgSeq The original sequence. - * @param modSeq The modified (or changed) sequence to - * compare against with the origial. + * <p>Return an array of {@code Difference} objects. This method finds out + * the difference between two sequences.</p> * - * @return An array of Difference objects. + * @param orgSeq The original sequence. + * @param modSeq The modified (or changed) sequence to compare against + * with the original. + * + * @return An array of Difference objects. */ public Difference[] computeDiffs(Iterator orgSeq, Iterator modSeq) { @@ -190,7 +191,6 @@ public class IteratorRowCompare implements DiffAlgorithm { modSeq.refresh(); } - // convert the vector to array Difference[] diffArray = new Difference[diffVector.size()]; diffVector.toArray(diffArray); @@ -198,7 +198,6 @@ public class IteratorRowCompare implements DiffAlgorithm { return diffArray; } - private Element splitRepeatedRow(Element orgRow, int splitNum, int orgNum) { // NOTE: should we really want to do deep clone? // in most the case, it is an empty Row, but the @@ -229,5 +228,4 @@ public class IteratorRowCompare implements DiffAlgorithm { return splitRow; } -} - +}
\ No newline at end of file diff --git a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/NodeIterator.java b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/NodeIterator.java index 5a27ff05fa71..ed34c337f1ac 100644 --- a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/NodeIterator.java +++ b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/NodeIterator.java @@ -29,18 +29,17 @@ import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; - /** - * <p>This is an implementation of the <code>Iterator</code> interface. - * It will traverse the tree and find <code>Node</code> sequences.</p> + * This is an implementation of the {@code Iterator} interface. + * + * <p>It will traverse the tree and find {@code Node} sequences.</p> * - * <p>Note: Once the XML Tree is parsed, then the <code>Iterator</code> will - * be a snap shot of that tree. That means even the tree is modified later, - * than the cached paragraph <code>Node</code> list will not be updated - * accordingly. For this reason and for performance reasons this - * <code>Iterator</code> does not support any operation methods such as - * insert, remove or replace. The main purpose of this - * <code>Iterator</code> is to be used with difference, not with merge.</p> + * <p>Note: Once the XML Tree is parsed, then the {@code Iterator} will be a + * snap shot of that tree. That means even the tree is modified later, than the + * cached paragraph {@code Node} list will not be updated accordingly. For this + * reason and for performance reasons this {@code Iterator} does not support any + * operation methods such as insert, remove or replace. The main purpose of this + * {@code Iterator} is to be used with difference, not with merge.</p> */ public abstract class NodeIterator implements Iterator { @@ -49,12 +48,11 @@ public abstract class NodeIterator implements Iterator { private Node root; private ConverterCapabilities cc_ = null; - /** - * Standard constructor. + * Standard constructor. * - * @param cc The <code>ConverterCapabilities</code>. - * @param node The initial root <code>Node</code>. + * @param cc The {@code ConverterCapabilities}. + * @param node The initial root {@code Node}. */ public NodeIterator(ConverterCapabilities cc, Node node) { cc_ = cc; @@ -63,7 +61,6 @@ public abstract class NodeIterator implements Iterator { markTree(node); } - public Object next() { if (currentPosition < nodeList.size() - 1) { currentPosition++; @@ -73,7 +70,6 @@ public abstract class NodeIterator implements Iterator { } } - public Object previous() { if (currentPosition > 0) { currentPosition--; @@ -83,13 +79,11 @@ public abstract class NodeIterator implements Iterator { } } - public Object start() { currentPosition = 0; return currentElement(); } - public Object end() { int size = nodeList.size(); @@ -101,22 +95,17 @@ public abstract class NodeIterator implements Iterator { } } - public Object currentElement() { - if (currentPosition < 0 || currentPosition >= nodeList.size()) { return null; } - return nodeList.get(currentPosition); } - public int elementCount() { return nodeList.size(); } - public boolean equivalent(Object obj1, Object obj2) { boolean equal = false; if (!(obj1 instanceof Node && obj2 instanceof Node)) { @@ -131,22 +120,20 @@ public abstract class NodeIterator implements Iterator { return equal; } - public void refresh() { nodeList = new ArrayList<Node>(); markTree(root); currentPosition = 0; } - /** - * Used to compare two <code>Node</code> objects (type/name/value) - * and all their children <code>Node</code> objects. + * Used to compare two {@code Node} objects (type/name/value) and all their + * children {@code Node} objects. * - * @param node1 The first <code>Node</code> to compare. - * @param node2 The second <code>Node</code> to compare. + * @param node1 The first {@code Node} to compare. + * @param node2 The second {@code Node} to compare. * - * @return true if <code>Node</code> is equal, false otherwise. + * @return {@code true} if {@code Node} is equal, {@code false} otherwise. */ protected boolean compareNode(Node node1, Node node2) { boolean equal = false; @@ -201,17 +188,17 @@ public abstract class NodeIterator implements Iterator { return equal; } - /** - * Compare the children of two <code>Node</code> objects. This - * method can be intentionally overridden by any class that - * extend from <code>NodeIterator</code> so that it can have - * its own children comparison if necessary. + * Compare the children of two {@code Node} objects. + * + * <p>This method can be intentionally overridden by any class that extend + * from {@code NodeIterator} so that it can have its own children comparison + * if necessary.</p> * - * @param node1 The first <code>Node</code> to compare. - * @param node2 The second <code>Node</code> to compare. + * @param node1 The first {@code Node} to compare. + * @param node2 The second {@code Node} to compare. * - * @return true if children are equal, false otherwise. + * @return {@code true} if children are equal, {@code false} otherwise. */ protected boolean childrenEqual(Node node1, Node node2) { @@ -244,17 +231,17 @@ public abstract class NodeIterator implements Iterator { return equal; } - /** - * Compare attributes of two <code>Node</code> objects. This - * method can be intentionally overridden by any class that - * extends from <code>NodeIterator</code> so that it can have - * its own attribute comparison. + * Compare attributes of two {@code Node} objects. + * + * <p>This method can be intentionally overridden by any class that extends + * from {@code NodeIterator} so that it can have its own attribute comparison. + * </p> * - * @param node1 The first <code>Node</code> to compare. - * @param node2 The second <code>Node</code> to compare. + * @param node1 The first {@code Node} to compare. + * @param node2 The second {@code Node} to compare. * - * @return true if attributes are equal, false otherwise. + * @return {@code true} if attributes are equal, {@code false} otherwise. */ private boolean attributesEqual(Node node1, Node node2) { @@ -264,7 +251,7 @@ public abstract class NodeIterator implements Iterator { attrNode[0] = node1.getAttributes(); attrNode[1] = node2.getAttributes(); - // attribute node will be null if node is not an element node + // Attribute node will be null if node is not an element node // and attribute nodes are equal if both are not element node if (attrNode[0] == null || attrNode[1] == null) { if (attrNode[0] == null && attrNode[1] == null) { @@ -273,7 +260,7 @@ public abstract class NodeIterator implements Iterator { return equal; } - // compare the attributes from node1 vs node2 and node2 vs node1 + // Compare the attributes from node1 vs node2 and node2 vs node1 // though it's a little inefficient for the duplication of comparison // as the number of attributes is not so many, it should not be // a big problem. @@ -331,16 +318,17 @@ public abstract class NodeIterator implements Iterator { return equal; } - /** - * Check whether a <code>Node</code> is supported. This method - * can be intentionally overridden by any class that extends from - * <code>NodeIterator</code> so that it can specify which - * <code>Node</code> to support. + * Check whether a {@code Node} is supported. * - * @param node <code>Node</code> to check. + * <p>This method can be intentionally overridden by any class that extends + * from {@code NodeIterator} so that it can specify which {@code Node} to + * support.</p> * - * @return true if <code>Node</code> is supported, false otherwise. + * @param node {@code Node} to check. + * + * @return {@code true} if <code>Node</code> is supported, {@code false} + * otherwise. */ protected abstract boolean nodeSupported(Node node); @@ -367,5 +355,4 @@ public abstract class NodeIterator implements Iterator { } } } -} - +}
\ No newline at end of file diff --git a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/ObjectArrayIterator.java b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/ObjectArrayIterator.java index 9854d16a0b8a..ecfe89786c0d 100644 --- a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/ObjectArrayIterator.java +++ b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/ObjectArrayIterator.java @@ -21,25 +21,22 @@ package org.openoffice.xmerge.merger.diff; import org.openoffice.xmerge.merger.Iterator; /** - * <p>This is an implementation of the <code>Iterator</code> interface. - * It is based upon a simple <code>Object</code> array.</p> + * This is an implementation of the {@code Iterator} interface. + * + * <p>It is based upon a simple {@code Object} array.</p> * * <p>Note: this class is not thread safe for performance reasons.</p> */ public final class ObjectArrayIterator implements Iterator { - - /** - * The <code>Object</code> array. - */ + /** The {@code Object} array. */ private Object [] objArray; private int currentPosition; - /** - * Standard constructor. + * Standard constructor. * - * @param objArray The <code>Object</code> array. + * @param objArray The {@code Object} array. */ public ObjectArrayIterator(Object [] objArray) { if (objArray != null) { @@ -51,7 +48,6 @@ public final class ObjectArrayIterator implements Iterator { } } - public Object next() { if (currentPosition < objArray.length - 1) { currentPosition++; @@ -59,10 +55,8 @@ public final class ObjectArrayIterator implements Iterator { } else { return null; } - } - public Object previous() { if (currentPosition > 0) { currentPosition--; @@ -72,13 +66,11 @@ public final class ObjectArrayIterator implements Iterator { } } - public Object start() { currentPosition = 0; return currentElement(); } - public Object end() { if (objArray.length > 0) { currentPosition = objArray.length - 1; @@ -86,7 +78,6 @@ public final class ObjectArrayIterator implements Iterator { return currentElement(); } - public Object currentElement() { if (objArray.length > 0) { return objArray[currentPosition]; @@ -95,21 +86,19 @@ public final class ObjectArrayIterator implements Iterator { } } - /** - * Replace current <code>Object</code>. + * Replace current {@code Object}. * - * @param object <code>Object</code> to replace. + * @param object {@code Object} to replace. */ public void replace(Object object) { objArray[currentPosition] = object; } - /** - * Insert <code>Object</code> after current <code>Object</code>. + * Insert {@code Object} after current {@code Object}. * - * @param object <code>Object</code> to insert. + * @param object {@code Object} to insert. */ public void insert(Object object) { Object [] objArray2 = new Object[objArray.length+1]; @@ -130,9 +119,9 @@ public final class ObjectArrayIterator implements Iterator { } /** - * Append <code>Object</code> after current <code>Object</code>. + * Append {@code Object} after current {@code Object}. * - * @param object <code>Object</code> to append. + * @param object {@code Object} to append. */ public void append(Object object) { Object [] objArray2 = new Object[objArray.length + 1]; @@ -154,7 +143,7 @@ public final class ObjectArrayIterator implements Iterator { } /** - * Remove current <code>Object</code>. + * Remove current {@code Object}. */ public void remove() { Object [] objArray2 = new Object[objArray.length - 1]; @@ -187,5 +176,4 @@ public final class ObjectArrayIterator implements Iterator { public void refresh() { // do nothing } -} - +}
\ No newline at end of file diff --git a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/ParaNodeIterator.java b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/ParaNodeIterator.java index a5e8b9e6ff7e..2a1b4d22cb32 100644 --- a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/ParaNodeIterator.java +++ b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/ParaNodeIterator.java @@ -23,19 +23,18 @@ import org.w3c.dom.Node; import org.openoffice.xmerge.ConverterCapabilities; import org.openoffice.xmerge.converter.xml.OfficeConstants; - /** - * <p>This is an implementation of the <code>Iterator</code> interface. - * It will traverse the tree and find the Paragraph/Heading <code>Node</code> - * sequences.</p> + * This is an implementation of the {@code Iterator} interface. + * + * <p>It will traverse the tree and find the Paragraph/Heading {@code Node} + * sequences.</p> * - * <p>Note: Once the XML Tree is parsed, then the <code>Iterator</code> will - * be a snap shot of that tree. That means even the tree is modified later, - * than the cached paragraph <code>Node</code> list will not be updated - * accordingly. For this reason and for performance reasons this - * <code>Iterator</code> does not support any operation methods such as - * insert, remove or replace. The main purpose of this - * <code>Iterator</code> is to be used with difference, not with merge.</p> + * <p>Note: Once the XML Tree is parsed, then the {@code Iterator} will be a + * snap shot of that tree. That means even the tree is modified later, than the + * cached paragraph {@code Node} list will not be updated accordingly. For this + * reason and for performance reasons this {@code Iterator} does not support any + * operation methods such as insert, remove or replace. The main purpose of this + * {@code Iterator} is to be used with difference, not with merge.</p> */ public final class ParaNodeIterator extends NodeIterator { @@ -44,33 +43,30 @@ public final class ParaNodeIterator extends NodeIterator { private static final String SUPPORTED_TAG2 = OfficeConstants.TAG_HEADING; /** - * Standard constructor. + * Standard constructor. * - * @param cc The <code>ConverterCapabilities</code>. - * @param node The initial root <code>Node</code>. + * @param cc The {@code ConverterCapabilities}. + * @param node The initial root {@code Node}. */ public ParaNodeIterator(ConverterCapabilities cc, Node node) { // not using convertercapabilities unless it's needed in future. super(cc, node); } - /** - * Overwrite the parent <code>nodeSupported</code> method. + * Overwrite the parent <code>nodeSupported</code> method. * - * @param node <code>Node</code> to check. + * @param node {@code Node} to check. * - * @return true if the <code>Node</code> is supported, false - * otherwise. + * @return {@code true} if the {@code Node} is supported, {@code false} + * otherwise. */ @Override protected boolean nodeSupported(Node node) { - // can use an array later to check all possible tags for // future expansion return node.getNodeType() == Node.ELEMENT_NODE && (node.getNodeName().equals(SUPPORTED_TAG1) || node.getNodeName().equals(SUPPORTED_TAG2)); } -} - +}
\ No newline at end of file diff --git a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/RowIterator.java b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/RowIterator.java index 9425d4c1bb70..7d84f7a7812b 100644 --- a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/RowIterator.java +++ b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/RowIterator.java @@ -23,10 +23,11 @@ import org.w3c.dom.Node; import org.openoffice.xmerge.ConverterCapabilities; import org.openoffice.xmerge.converter.xml.OfficeConstants; - /** - * This is an implementation of the <code>Iterator</code> interface and extends - * <code>NodeIterator</code>. It will traverse the tree and find row sequences. + * This is an implementation of the {@code Iterator} interface and extends + * {@code NodeIterator}. + * + * <p>It will traverse the tree and find row sequences.</p> */ public final class RowIterator extends NodeIterator { @@ -35,22 +36,24 @@ public final class RowIterator extends NodeIterator { // considered to be not equivalent. /** - * Standard constructor. + * Standard constructor. * - * @param cc The <code>ConverterCapabilities</code>. - * @param node The initial root <code>Node</code>. + * @param cc The {@code ConverterCapabilities}. + * @param node The initial root {@code Node}. */ public RowIterator(ConverterCapabilities cc, Node node) { super(cc, node); } /** - * Overwrite the parent <code>nodeSupported</code> method. Only - * row <code>Node</code> objects are supported. + * Overwrite the parent {@code nodeSupported} method. * - * @param node <code>Node</code> to check. + * <p>Only row {@code Node} objects are supported.</p> * - * @return true if the <code>Node</code> is supported, false otherwise. + * @param node {@code Node} to check. + * + * @return {@code true} if the {@code Node} is supported, {@code false} + * otherwise. */ @Override protected boolean nodeSupported(Node node) { @@ -60,5 +63,4 @@ public final class RowIterator extends NodeIterator { return node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals(OfficeConstants.TAG_TABLE_ROW); } -} - +}
\ No newline at end of file diff --git a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/TextNodeEntry.java b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/TextNodeEntry.java index d20a0055e9c3..ebe234fdadf7 100644 --- a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/TextNodeEntry.java +++ b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/TextNodeEntry.java @@ -21,10 +21,11 @@ package org.openoffice.xmerge.merger.diff; import org.w3c.dom.Node; /** - * A small class to hold the start/end character position and the - * <code>Node</code> pointer in a text <code>Node</code>. It is - * mainly used for character parser to make a list of text - * <code>Node</code> cache entries. + * A small class to hold the start/end character position and the {@code Node} + * pointer in a text {@code Node}. + * + * <p>It is mainly used for character parser to make a list of text {@code Node} + * cache entries.</p> */ public class TextNodeEntry { @@ -33,11 +34,11 @@ public class TextNodeEntry { private Node node_; /** - * Constructor + * Constructor * - * @param startChar The start character position. - * @param endChar The end character position. - * @param node The text <code>Node</code>. + * @param startChar The start character position. + * @param endChar The end character position. + * @param node The text {@code Node}. */ public TextNodeEntry(int startChar, int endChar, Node node) { startChar_ = startChar; @@ -46,32 +47,29 @@ public class TextNodeEntry { } /** - * Returns the start character. + * Returns the start character. * - * @return The start character. + * @return The start character. */ public int startChar() { return startChar_; } - /** - * Returns the end character. + * Returns the end character. * - * @return The end character. + * @return The end character. */ public int endChar() { return endChar_; } - /** - * Returns the <code>Node</code>. + * Returns the {@code Node}. * - * @return The <code>Node</code>. + * @return The {@code Node}. */ public Node node() { return node_; } -} - +}
\ No newline at end of file diff --git a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/TextNodeIterator.java b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/TextNodeIterator.java index 791122c398dc..fa7c6086c36b 100644 --- a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/TextNodeIterator.java +++ b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/diff/TextNodeIterator.java @@ -22,43 +22,42 @@ import org.w3c.dom.Node; import org.openoffice.xmerge.converter.xml.OfficeConstants; - /** - * <p>This is an implementation of the <code>Iterator</code> interface. - * It will traverse the tree and find text/space/tab <code>Node</code> - * sequences.</p> + * This is an implementation of the {@code Iterator} interface. + * + * <p>It will traverse the tree and find text/space/tab {@code Node} sequences. + * </p> * - * <p>Note: Once the XML Tree is parsed, then the <code>Iterator</code> - * will be a snap shot of that tree. That means even the tree is modified - * later, than the cached paragraph <code>Node</code> list will not be - * updated accordingly. For this reason and for performance reasons - * this <code>Iterator</code> does not support any operation methods - * such as insert, remove or replace. The main purpose of this - * <code>Iterator</code> is to be used with difference, not with merge.</p> + * <p>Note: Once the XML Tree is parsed, then the {@code Iterator} will be a + * snap shot of that tree. That means even the tree is modified later, than the + * cached paragraph {@code Node} list will not be updated accordingly. For this + * reason and for performance reasons this {@code Iterator} does not support + * any operation methods such as insert, remove or replace. The main purpose of + * this {@code Iterator} is to be used with difference, not with merge.</p> */ public final class TextNodeIterator extends NodeIterator { /** - * Standard constructor. + * Standard constructor. * - * @param node The initial root <code>Node</code>. + * @param node The initial root {@code Node}. */ public TextNodeIterator(Node node) { super(null, node); } /** - * Overwrite the parent <code>nodeSupported</code> method. Only text - * <code>Node</code> objects are supported. + * Overwrite the parent {@code nodeSupported} method. + * + * <p>Only text {@code Node} objects are supported.</p> * - * @param node <code>Node</code> to check. + * @param node {@code Node} to check. * - * @return true if the <code>Node</code> is supported, false - * otherwise. + * @return {@code true} if the {@code Node} is supported, {@code false} + * otherwise. */ @Override protected boolean nodeSupported(Node node) { - // can use an array later to check all possible tags for // future expansion return node.getNodeType() == Node.TEXT_NODE || @@ -66,5 +65,4 @@ public final class TextNodeIterator extends NodeIterator { node.getNodeName().equals(OfficeConstants.TAG_TAB_STOP) || node.getNodeName().equals(OfficeConstants.TAG_LINE_BREAK); } -} - +}
\ No newline at end of file diff --git a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/merge/CharacterBaseParagraphMerge.java b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/merge/CharacterBaseParagraphMerge.java index 0b48d7a78655..8f656337e635 100644 --- a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/merge/CharacterBaseParagraphMerge.java +++ b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/merge/CharacterBaseParagraphMerge.java @@ -28,23 +28,21 @@ import org.openoffice.xmerge.merger.diff.TextNodeEntry; import org.openoffice.xmerge.util.Debug; /** - * This is an implementation of the <code>NodeMergeAlgorithm</code> - * interface. It is used to merge two paragraph <code>Node</code> - * objects based on character comparisons. + * This is an implementation of the {@code NodeMergeAlgorithm} interface. + * + * <p>It is used to merge two paragraph {@code Node} objects based on character + * comparisons.</p> */ -public final class CharacterBaseParagraphMerge - implements NodeMergeAlgorithm { - - +public final class CharacterBaseParagraphMerge implements NodeMergeAlgorithm { /** - * Merge two paragraph <code>Node</code> by using Longest Common - * Subsequence (LCS) character algorithm defined in {@link - * org.openoffice.xmerge.merger.diff.CharArrayLCSAlgorithm - * CharArrayLCSAlgorithm} + * Merge two paragraph {@code Node} by using Longest Common Subsequence + * (LCS) character algorithm defined in {@link + * org.openoffice.xmerge.merger.diff.CharArrayLCSAlgorithm + * CharArrayLCSAlgorithm}. * - * @param orgPara The original paragraph <code>Node</code>. - * @param modPara The modified paragraph <code>Node</code>. + * @param orgPara The original paragraph {@code Node}. + * @param modPara The modified paragraph {@code Node}. */ public void merge(Node orgPara, Node modPara) { CharacterParser orgParser = new CharacterParser(orgPara); @@ -66,7 +64,6 @@ public final class CharacterBaseParagraphMerge applyDifference(orgParser, modParser, diffResult); } - private void applyDifference(CharacterParser orgParser, CharacterParser modParser, Difference[] diffs) { @@ -135,15 +132,14 @@ public final class CharacterBaseParagraphMerge } private void coreMerge(int startDiffNum, int endDiffNum, Difference[] diffs, - CharacterParser modParser, - TextNodeEntry orgTextNode, int extraChar) { + CharacterParser modParser, + TextNodeEntry orgTextNode, int extraChar) { Node orgNode = orgTextNode.node(); char[] modTextArray = modParser.getCharArray(); String tmpString; // Handle situation where getNodeValue returns null - if (orgNode.getNodeValue() != null) tmpString = orgNode.getNodeValue(); else @@ -167,11 +163,9 @@ public final class CharacterBaseParagraphMerge int lastDiffPosition = -1; // starting to diff - for (int j = startDiffNum; j < endDiffNum; j++) { // copy any contents before the diff - if (diffs[j].getOrgPosition() > orgTextPosition) { // need to flush first if (cacheLength > 0) { @@ -199,7 +193,6 @@ public final class CharacterBaseParagraphMerge // for any deleted characters, just skip without copy // but still need to take care the cached characters - if (diffs[j].getOperation() == Difference.DELETE) { orgTextPosition++; @@ -217,7 +210,6 @@ public final class CharacterBaseParagraphMerge continue; - // check whether we should flush the cache. // For changed diffs, only continuous changes can be cached // For Add diffs, only same insertion point can be cached @@ -288,5 +280,4 @@ public final class CharacterBaseParagraphMerge orgNode.setNodeValue(newString); } } -} - +}
\ No newline at end of file diff --git a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/merge/DocumentMerge.java b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/merge/DocumentMerge.java index a17aae751087..1d37e4cabd5f 100644 --- a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/merge/DocumentMerge.java +++ b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/merge/DocumentMerge.java @@ -30,11 +30,12 @@ import org.openoffice.xmerge.merger.Difference; import org.openoffice.xmerge.util.XmlUtil; /** - * This is an implementation of the <code>MergeAlgorithm</code> interface. - * This class will merge two <code>Document</code> classes. It utilizes the + * This is an implementation of the {@code MergeAlgorithm} interface. + * + * <p>This class will merge two {@code Document} classes. It utilizes the * appropriate class which implements {@link - * org.openoffice.xmerge.merger.NodeMergeAlgorithm - * NodeMergeAlgorithm} to perform the merge. + * org.openoffice.xmerge.merger.NodeMergeAlgorithm NodeMergeAlgorithm} to + * perform the merge.</p> */ public class DocumentMerge implements MergeAlgorithm { @@ -43,23 +44,20 @@ public class DocumentMerge implements MergeAlgorithm { /** The capabilities of this converter. */ protected ConverterCapabilities cc_; - /** - * Constructor + * Constructor. * - * @param cc The <code>ConverterCapabilities</code>. - * @param merge The <code>NodeMergeAlgorithm</code>. + * @param cc The {@code ConverterCapabilities}. + * @param merge The {@code NodeMergeAlgorithm}. */ public DocumentMerge(ConverterCapabilities cc, NodeMergeAlgorithm merge) { cc_ = cc; subDocumentMerge = merge; } - public void applyDifference(Iterator orgSeq, Iterator modSeq, Difference[] differences) throws MergeException { - // a quick test whether the differences array is in ascending order int currentPosition = -1; boolean haveDeleteOperation = false; @@ -170,11 +168,10 @@ public class DocumentMerge implements MergeAlgorithm { } } - /** - * Removes the specified <code>Node</code>. + * Removes the specified {@code Node}. * - * @param node <code>Node</code> to remove. + * @param node {@code Node} to remove. */ protected void removeNode(Node node) { @@ -183,10 +180,10 @@ public class DocumentMerge implements MergeAlgorithm { } /** - * Appends <code>Node</code> after the specified <code>Node</code>. + * Appends {@code Node} after the specified {@code Node}. * - * @param oldNode <code>Node</code> to append after. - * @param newNode <code>Node</code> to append. + * @param oldNode {@code Node} to append after. + * @param newNode {@code Node} to append. */ private void appendNode(Node oldNode, Node newNode) { Node clonedNode = XmlUtil.deepClone(oldNode, newNode); @@ -194,12 +191,11 @@ public class DocumentMerge implements MergeAlgorithm { parent.appendChild(clonedNode); } - /** - * Insert <code>Node</code> before the specified <code>Node</code>. + * Insert {@code Node} before the specified {@code Node}. * - * @param oldNode <code>Node</code> to insert before. - * @param newNode <code>Node</code> to insert. + * @param oldNode {@code Node} to insert before. + * @param newNode {@code Node} to insert. */ private void insertNode(Node oldNode, Node newNode) { Node clonedNode = XmlUtil.deepClone(oldNode, newNode); @@ -207,12 +203,11 @@ public class DocumentMerge implements MergeAlgorithm { parent.insertBefore(clonedNode, oldNode); } - /** - * Replace <code>Element</code>. + * Replace <code>Element</code>. * - * @param currElem <code>Element</code> to be replaced. - * @param newElem <code>Element</code> to replace. + * @param currElem {@code Element} to be replaced. + * @param newElem {@code Element} to replace. */ private void replaceElement(Element currElem, Element newElem) { @@ -220,5 +215,4 @@ public class DocumentMerge implements MergeAlgorithm { Node parent = currElem.getParentNode(); parent.replaceChild(clonedNode, currElem); } -} - +}
\ No newline at end of file diff --git a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/merge/PositionBaseRowMerge.java b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/merge/PositionBaseRowMerge.java index 144c658a2dca..b3bff5b1d81b 100644 --- a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/merge/PositionBaseRowMerge.java +++ b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/merge/PositionBaseRowMerge.java @@ -30,28 +30,26 @@ import org.openoffice.xmerge.merger.diff.CellNodeIterator; import org.openoffice.xmerge.converter.xml.OfficeConstants; import org.openoffice.xmerge.util.XmlUtil; - /** - * This is an implementation of the <code>NodeMergeAlgorithm</code> - * interface. It is used to merge two rows using a positional - * comparison base method. + * This is an implementation of the {@code NodeMergeAlgorithm} interface. + * + * <p>It is used to merge two rows using a positional comparison base method. + * </p> */ public final class PositionBaseRowMerge implements NodeMergeAlgorithm { - /** The capabilities of this converter. */ + /** The capabilities of this converter. */ private ConverterCapabilities cc_; - /** - * Constructor. + * Constructor. * - * @param cc The <code>ConverterCapabilities</code>. + * @param cc The {@code ConverterCapabilities}. */ public PositionBaseRowMerge(ConverterCapabilities cc) { cc_ = cc; } - public void merge(Node orgRow, Node modRow) { Iterator orgCells = new CellNodeIterator(cc_, orgRow); @@ -60,7 +58,6 @@ public final class PositionBaseRowMerge implements NodeMergeAlgorithm { mergeCellSequences(orgCells, modCells); } - // used to compare the cell 1 by 1 private void mergeCellSequences(Iterator orgSeq, Iterator modSeq) { @@ -72,7 +69,6 @@ public final class PositionBaseRowMerge implements NodeMergeAlgorithm { while (orgSeqObject != null) { - needMerge = true; if (modSeqObject == null) { @@ -163,9 +159,8 @@ public final class PositionBaseRowMerge implements NodeMergeAlgorithm { } } - - private Element splitColRepeatedCell(Element orgCell, - int splitNum, int orgNum) { + private Element splitColRepeatedCell(Element orgCell, int splitNum, + int orgNum) { // NOTE: should we really want to do deep clone? // in most the case, it is an empty cell, but the // specification didn't forbid any node to use multiple @@ -196,7 +191,6 @@ public final class PositionBaseRowMerge implements NodeMergeAlgorithm { return splitCell; } - private void mergeCells(Element orgCell, Element modCell) { // remove all the supported attributes and possible text child for @@ -247,5 +241,4 @@ public final class PositionBaseRowMerge implements NodeMergeAlgorithm { } } } -} - +}
\ No newline at end of file diff --git a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/merge/SheetMerge.java b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/merge/SheetMerge.java index 60e19e3d6712..f21be1591543 100644 --- a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/merge/SheetMerge.java +++ b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/merge/SheetMerge.java @@ -25,43 +25,41 @@ import org.openoffice.xmerge.ConverterCapabilities; import org.openoffice.xmerge.merger.NodeMergeAlgorithm; /** - * This class extends the <code>DocumentMerge</code> class. - * This class will merge two spreadsheet documents. - * The main difference between this implementation and - * <code>DocumentMerge</code> - * is that this merge will try to maintain unsupported features by - * examining the cell <code>node</code> objects one by one when it - * removes a node from the original <code>Iterator</code>. + * This class extends the {@code DocumentMerge} class. + * + * <p>This class will merge two spreadsheet documents.</p> + * + * <p>The main difference between this implementation and {@code DocumentMerge} + * is that this merge will try to maintain unsupported features by examining the + * cell {@code node} objects one by one when it removes a node from the original + * {@code Iterator}.</p> */ public final class SheetMerge extends DocumentMerge { /** - * Constructor. + * Constructor. * - * @param cc The <code>ConverterCapabilities</code>. - * @param merge The <code>NodeMergeAlgorithm</code>. + * @param cc The {@code ConverterCapabilities}. + * @param merge The {@code NodeMergeAlgorithm}. */ public SheetMerge(ConverterCapabilities cc, NodeMergeAlgorithm merge) { super(cc, merge); } - /** - * Remove specified <code>Node</code>. + * Remove specified {@code Node}. * - * @param node <code>Node</code> to remove. + * @param node {@code Node} to remove. */ @Override protected void removeNode(Node node) { - clearRow(node); } - /** - * Clear the row corresponding to the <code>Node</code> + * Clear the row corresponding to the {@code Node}. * - * @param node <code>Node</code> containing the row to clear. + * @param node {@code Node} containing the row to clear. */ private void clearRow(Node node) { NodeList children = node.getChildNodes(); @@ -75,5 +73,4 @@ public final class SheetMerge extends DocumentMerge { SheetUtil.emptyCell(cc_, children.item(i)); } } -} - +}
\ No newline at end of file diff --git a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/merge/SheetUtil.java b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/merge/SheetUtil.java index cbad7ccfdb61..2f5a8ebe9bb8 100644 --- a/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/merge/SheetUtil.java +++ b/xmerge/source/xmerge/java/org/openoffice/xmerge/merger/merge/SheetUtil.java @@ -26,27 +26,26 @@ import org.w3c.dom.NamedNodeMap; import org.openoffice.xmerge.ConverterCapabilities; import org.openoffice.xmerge.converter.xml.OfficeConstants; - /** - * Utility methods to handle sheet XML tree. + * Utility methods to handle sheet XML tree. */ public class SheetUtil { /** - * Empty the content of a cell value. + * Empty the content of a cell value. * - * <p>This includes the following:</p> + * <p>This includes the following:</p> * - * <ul> - * <li> - * Remove all of the supported attributes. - * </li><li> - * Remove the first <i>text:p</i> <code>Node</code> for most of the cells. - * </li> - * </ul> + * <ul> + * <li> + * Remove all of the supported attributes. + * </li><li> + * Remove the first <i>text:p</i> {@code Node} for most of the cells. + * </li> + * </ul> * - * @param cc The <code>ConverterCapabilities</code>. - * @param node The <code>Node</code>. + * @param cc The {@code ConverterCapabilities}. + * @param node The {@code Node}. */ public static void emptyCell(ConverterCapabilities cc, Node node) { @@ -97,5 +96,4 @@ public class SheetUtil { } } } -} - +}
\ No newline at end of file |