Modified: xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Cur.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Cur.java?rev=1877931&r1=1877930&r2=1877931&view=diff ============================================================================== --- xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Cur.java (original) +++ xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Cur.java Tue May 19 20:10:55 2020 @@ -15,110 +15,39 @@ package org.apache.xmlbeans.impl.store; -import org.w3c.dom.Attr; -import org.w3c.dom.CDATASection; -import org.w3c.dom.CharacterData; -import org.w3c.dom.Comment; +import org.apache.xmlbeans.*; +import org.apache.xmlbeans.XmlCursor.XmlBookmark; +import org.apache.xmlbeans.impl.soap.*; +import org.apache.xmlbeans.impl.store.DomImpl.Dom; +import org.apache.xmlbeans.impl.store.Locale.LoadContext; +import org.apache.xmlbeans.impl.values.TypeStoreUser; import org.w3c.dom.Document; import org.w3c.dom.DocumentFragment; -import org.w3c.dom.DocumentType; -import org.w3c.dom.DOMException; -import org.w3c.dom.DOMImplementation; -import org.w3c.dom.Element; -import org.w3c.dom.EntityReference; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.w3c.dom.ProcessingInstruction; -import org.w3c.dom.Text; -import org.w3c.dom.DOMImplementation; - -// DOM Level 3 -import org.w3c.dom.UserDataHandler; -import org.w3c.dom.DOMConfiguration; -import org.w3c.dom.TypeInfo; - - -import javax.xml.transform.Source; +import javax.xml.namespace.QName; import java.io.PrintStream; - -import java.util.Iterator; import java.util.Map; -import java.util.ArrayList; -import java.util.List; -import org.apache.xmlbeans.impl.soap.Detail; -import org.apache.xmlbeans.impl.soap.DetailEntry; -import org.apache.xmlbeans.impl.soap.MimeHeaders; -import org.apache.xmlbeans.impl.soap.Name; -import org.apache.xmlbeans.impl.soap.SOAPBody; -import org.apache.xmlbeans.impl.soap.SOAPBodyElement; -import org.apache.xmlbeans.impl.soap.SOAPElement; -import org.apache.xmlbeans.impl.soap.SOAPEnvelope; -import org.apache.xmlbeans.impl.soap.SOAPException; -import org.apache.xmlbeans.impl.soap.SOAPFactory; -import org.apache.xmlbeans.impl.soap.SOAPFault; -import org.apache.xmlbeans.impl.soap.SOAPFaultElement; -import org.apache.xmlbeans.impl.soap.SOAPHeader; -import org.apache.xmlbeans.impl.soap.SOAPHeaderElement; -import org.apache.xmlbeans.impl.soap.SOAPPart; -import org.apache.xmlbeans.impl.store.Xobj.Bookmark; - -import org.apache.xmlbeans.impl.store.Locale.LoadContext; - -import org.apache.xmlbeans.impl.store.DomImpl.Dom; -import org.apache.xmlbeans.impl.store.DomImpl.CharNode; -import org.apache.xmlbeans.impl.store.DomImpl.TextNode; -import org.apache.xmlbeans.impl.store.DomImpl.CdataNode; -import org.apache.xmlbeans.impl.store.DomImpl.SaajTextNode; -import org.apache.xmlbeans.impl.store.DomImpl.SaajCdataNode; - -import org.apache.xmlbeans.CDataBookmark; -import org.apache.xmlbeans.XmlBeans; -import org.apache.xmlbeans.XmlLineNumber; -import org.apache.xmlbeans.SchemaField; -import org.apache.xmlbeans.SchemaType; -import org.apache.xmlbeans.SchemaTypeLoader; -import org.apache.xmlbeans.XmlCursor; -import org.apache.xmlbeans.XmlObject; -import org.apache.xmlbeans.XmlOptions; -import org.apache.xmlbeans.XmlException; -import org.apache.xmlbeans.QNameSet; -import org.apache.xmlbeans.XmlDocumentProperties; -import org.apache.xmlbeans.XmlCursor.XmlBookmark; - -import org.apache.xmlbeans.impl.values.TypeStore; -import org.apache.xmlbeans.impl.values.TypeStoreUser; -import org.apache.xmlbeans.impl.values.TypeStoreVisitor; -import org.apache.xmlbeans.impl.values.TypeStoreUserFactory; - -import javax.xml.namespace.QName; - -import org.apache.xmlbeans.impl.common.ValidatorListener; -import org.apache.xmlbeans.impl.common.XmlLocale; -import org.apache.xmlbeans.impl.common.QNameHelper; +// DOM Level 3 -final class Cur -{ - static final int TEXT = 0; // Must be 0 - static final int ROOT = 1; - static final int ELEM = 2; - static final int ATTR = 3; - static final int COMMENT = 4; +final class Cur { + static final int TEXT = 0; // Must be 0 + static final int ROOT = 1; + static final int ELEM = 2; + static final int ATTR = 3; + static final int COMMENT = 4; static final int PROCINST = 5; - static final int POOLED = 0; - static final int REGISTERED = 1; - static final int EMBEDDED = 2; - static final int DISPOSED = 3; + static final int POOLED = 0; + static final int REGISTERED = 1; + static final int EMBEDDED = 2; + static final int DISPOSED = 3; static final int END_POS = -1; - static final int NO_POS = -2; + static final int NO_POS = -2; - Cur ( Locale l ) - { + Cur(Locale l) { _locale = l; _pos = NO_POS; @@ -133,120 +62,199 @@ final class Cur _selectionCount = 0; } - boolean isPositioned ( ) { assert isNormal(); return _xobj != null; } + boolean isPositioned() { + assert isNormal(); + return _xobj != null; + } + + static boolean kindIsContainer(int k) { + return k == ELEM || k == ROOT; + } - static boolean kindIsContainer ( int k ) { return k == ELEM || k == ROOT; } - static boolean kindIsFinish ( int k ) { return k == -ELEM || k == -ROOT; } + static boolean kindIsFinish(int k) { + return k == -ELEM || k == -ROOT; + } - int kind ( ) - { + int kind() { assert isPositioned(); int kind = _xobj.kind(); - return _pos == 0 ? kind : (_pos == END_POS ? - kind : TEXT); + return _pos == 0 ? kind : (_pos == END_POS ? -kind : TEXT); } - boolean isRoot ( ) { assert isPositioned(); return _pos == 0 && _xobj.kind() == ROOT; } - boolean isElem ( ) { assert isPositioned(); return _pos == 0 && _xobj.kind() == ELEM; } - boolean isAttr ( ) { assert isPositioned(); return _pos == 0 && _xobj.kind() == ATTR; } - boolean isComment ( ) { assert isPositioned(); return _pos == 0 && _xobj.kind() == COMMENT; } - boolean isProcinst ( ) { assert isPositioned(); return _pos == 0 && _xobj.kind() == PROCINST; } - boolean isText ( ) { assert isPositioned(); return _pos > 0; } - boolean isEnd ( ) { assert isPositioned(); return _pos == END_POS && _xobj.kind() ==ELEM;} - boolean isEndRoot ( ) { assert isPositioned(); return _pos == END_POS && _xobj.kind() ==ROOT;} - boolean isNode ( ) { assert isPositioned(); return _pos == 0; } - boolean isContainer ( ) { assert isPositioned(); return _pos == 0 && kindIsContainer( _xobj.kind() ); } - boolean isFinish ( ) { assert isPositioned(); return _pos == END_POS && kindIsContainer( _xobj.kind() ); } - boolean isUserNode ( ) { assert isPositioned(); int k = kind(); return k == ELEM || k == ROOT || (k == ATTR && !isXmlns()); } + boolean isRoot() { + assert isPositioned(); + return _pos == 0 && _xobj.kind() == ROOT; + } - boolean isContainerOrFinish ( ) - { + boolean isElem() { assert isPositioned(); + return _pos == 0 && _xobj.kind() == ELEM; + } - if (_pos!=0 && _pos!= END_POS) + boolean isAttr() { + assert isPositioned(); + return _pos == 0 && _xobj.kind() == ATTR; + } + + boolean isComment() { + assert isPositioned(); + return _pos == 0 && _xobj.kind() == COMMENT; + } + + boolean isProcinst() { + assert isPositioned(); + return _pos == 0 && _xobj.kind() == PROCINST; + } + + boolean isText() { + assert isPositioned(); + return _pos > 0; + } + + boolean isEnd() { + assert isPositioned(); + return _pos == END_POS && _xobj.kind() == ELEM; + } + + boolean isEndRoot() { + assert isPositioned(); + return _pos == END_POS && _xobj.kind() == ROOT; + } + + boolean isNode() { + assert isPositioned(); + return _pos == 0; + } + + boolean isContainer() { + assert isPositioned(); + return _pos == 0 && kindIsContainer(_xobj.kind()); + } + + boolean isFinish() { + assert isPositioned(); + return _pos == END_POS && kindIsContainer(_xobj.kind()); + } + + boolean isUserNode() { + assert isPositioned(); + int k = kind(); + return k == ELEM || k == ROOT || (k == ATTR && !isXmlns()); + } + + boolean isContainerOrFinish() { + assert isPositioned(); + + if (_pos != 0 && _pos != END_POS) return false; int kind = _xobj.kind(); return kind == ELEM || kind == -ELEM || kind == ROOT || kind == -ROOT; } - boolean isNormalAttr ( ) { return isNode() && _xobj.isNormalAttr(); } - boolean isXmlns ( ) { return isNode() && _xobj.isXmlns(); } + boolean isNormalAttr() { + return isNode() && _xobj.isNormalAttr(); + } + + boolean isXmlns() { + return isNode() && _xobj.isXmlns(); + } + + boolean isTextCData() { + return _xobj.hasBookmark(CDataBookmark.class, _pos); + } + + QName getName() { + assert isNode() || isEnd(); + return _xobj._name; + } + + String getLocal() { + return getName().getLocalPart(); + } + + String getUri() { + return getName().getNamespaceURI(); + } - boolean isTextCData ( ) { return _xobj.hasBookmark(CDataBookmark.class, _pos); } + String getXmlnsPrefix() { + assert isXmlns(); + return _xobj.getXmlnsPrefix(); + } - QName getName ( ) { assert isNode() || isEnd(); return _xobj._name; } - String getLocal ( ) { return getName().getLocalPart(); } - String getUri ( ) { return getName().getNamespaceURI(); } + String getXmlnsUri() { + assert isXmlns(); + return _xobj.getXmlnsUri(); + } - String getXmlnsPrefix ( ) { assert isXmlns(); return _xobj.getXmlnsPrefix(); } - String getXmlnsUri ( ) { assert isXmlns(); return _xobj.getXmlnsUri(); } + boolean isDomDocRoot() { + return isRoot() && _xobj.getDom() instanceof Document; + } + + boolean isDomFragRoot() { + return isRoot() && _xobj.getDom() instanceof DocumentFragment; + } - boolean isDomDocRoot ( ) { return isRoot() && _xobj.getDom() instanceof Document; } - boolean isDomFragRoot ( ) { return isRoot() && _xobj.getDom() instanceof DocumentFragment; } + int cchRight() { + assert isPositioned(); + return _xobj.cchRight(_pos); + } - int cchRight ( ) { assert isPositioned(); return _xobj.cchRight( _pos ); } - int cchLeft ( ) { assert isPositioned(); return _xobj.cchLeft ( _pos ); } + int cchLeft() { + assert isPositioned(); + return _xobj.cchLeft(_pos); + } // // Creation methods // - void createRoot ( ) - { + void createRoot() { createDomDocFragRoot(); } - void createDomDocFragRoot ( ) - { - moveTo( new Xobj.DocumentFragXobj( _locale ) ); + void createDomDocFragRoot() { + moveTo(new DocumentFragXobj(_locale)); } - void createDomDocumentRoot ( ) - { - moveTo( createDomDocumentRootXobj( _locale ) ); + void createDomDocumentRoot() { + moveTo(createDomDocumentRootXobj(_locale)); } - void createAttr ( QName name ) - { - createHelper( new Xobj.AttrXobj( _locale, name ) ); + void createAttr(QName name) { + createHelper(new AttrXobj(_locale, name)); } - void createComment ( ) - { - createHelper( new Xobj.CommentXobj( _locale ) ); + void createComment() { + createHelper(new CommentXobj(_locale)); } - void createProcinst ( String target ) - { - createHelper( new Xobj.ProcInstXobj( _locale, target ) ); + void createProcinst(String target) { + createHelper(new ProcInstXobj(_locale, target)); } - void createElement ( QName name ) - { - createElement( name, null ); + void createElement(QName name) { + createElement(name, null); } - void createElement ( QName name, QName parentName ) - { - createHelper( createElementXobj( _locale, name, parentName ) ); + void createElement(QName name, QName parentName) { + createHelper(createElementXobj(_locale, name, parentName)); } - static Xobj createDomDocumentRootXobj ( Locale l ) - { + static Xobj createDomDocumentRootXobj(Locale l) { return createDomDocumentRootXobj(l, false); } - static Xobj createDomDocumentRootXobj ( Locale l , boolean fragment) - { + static Xobj createDomDocumentRootXobj(Locale l, boolean fragment) { Xobj xo; if (l._saaj == null) if (fragment) - xo = new Xobj.DocumentFragXobj( l ); + xo = new DocumentFragXobj(l); else - xo = new Xobj.DocumentXobj( l ); + xo = new DocumentXobj(l); else - xo = new Xobj.SoapPartDocXobj( l ); + xo = new SoapPartDocXobj(l); if (l._ownerDoc == null) l._ownerDoc = xo.getDom(); @@ -254,49 +262,45 @@ final class Cur return xo; } - static Xobj createElementXobj ( Locale l, QName name, QName parentName ) - { + static Xobj createElementXobj(Locale l, QName name, QName parentName) { if (l._saaj == null) - return new Xobj.ElementXobj( l, name ); + return new ElementXobj(l, name); - Class c = l._saaj.identifyElement( name, parentName ); + Class c = l._saaj.identifyElement(name, parentName); - if (c == SOAPElement.class) return new Xobj.SoapElementXobj ( l, name ); - if (c == SOAPBody.class) return new Xobj.SoapBodyXobj ( l, name ); - if (c == SOAPBodyElement.class) return new Xobj.SoapBodyElementXobj ( l, name ); - if (c == SOAPEnvelope.class) return new Xobj.SoapEnvelopeXobj ( l, name ); - if (c == SOAPHeader.class) return new Xobj.SoapHeaderXobj ( l, name ); - if (c == SOAPHeaderElement.class) return new Xobj.SoapHeaderElementXobj ( l, name ); - if (c == SOAPFaultElement.class) return new Xobj.SoapFaultElementXobj ( l, name ); - if (c == Detail.class) return new Xobj.DetailXobj ( l, name ); - if (c == DetailEntry.class) return new Xobj.DetailEntryXobj ( l, name ); - if (c == SOAPFault.class) return new Xobj.SoapFaultXobj ( l, name ); + if (c == SOAPElement.class) return new SoapElementXobj(l, name); + if (c == SOAPBody.class) return new SoapBodyXobj(l, name); + if (c == SOAPBodyElement.class) return new SoapBodyElementXobj(l, name); + if (c == SOAPEnvelope.class) return new SoapEnvelopeXobj(l, name); + if (c == SOAPHeader.class) return new SoapHeaderXobj(l, name); + if (c == SOAPHeaderElement.class) return new SoapHeaderElementXobj(l, name); + if (c == SOAPFaultElement.class) return new SoapFaultElementXobj(l, name); + if (c == Detail.class) return new DetailXobj(l, name); + if (c == DetailEntry.class) return new DetailEntryXobj(l, name); + if (c == SOAPFault.class) return new SoapFaultXobj(l, name); - throw new IllegalStateException( "Unknown SAAJ element class: " + c ); + throw new IllegalStateException("Unknown SAAJ element class: " + c); } - private void createHelper ( Xobj x ) - { + private void createHelper(Xobj x) { assert x._locale == _locale; // insert the new Xobj into an exisiting tree. - if (isPositioned()) - { - Cur from = tempCur( x, 0 ); - from.moveNode( this ); + if (isPositioned()) { + Cur from = tempCur(x, 0); + from.moveNode(this); from.release(); } - moveTo( x ); + moveTo(x); } // // General operations // - boolean isSamePos ( Cur that ) - { + boolean isSamePos(Cur that) { assert isNormal() && (that == null || that.isNormal()); return _xobj == that._xobj && _pos == that._pos; @@ -304,36 +308,31 @@ final class Cur // is this just after the end of that (that must be the start of a node) - boolean isJustAfterEnd ( Cur that ) - { + boolean isJustAfterEnd(Cur that) { assert isNormal() && that != null && that.isNormal() && that.isNode(); - return that._xobj.isJustAfterEnd( _xobj, _pos ); + return that._xobj.isJustAfterEnd(_xobj, _pos); } - boolean isJustAfterEnd ( Xobj x ) - { - return x.isJustAfterEnd( _xobj, _pos ); + boolean isJustAfterEnd(Xobj x) { + return x.isJustAfterEnd(_xobj, _pos); } - boolean isAtEndOf ( Cur that ) - { + boolean isAtEndOf(Cur that) { assert that != null && that.isNormal() && that.isNode(); return _xobj == that._xobj && _pos == END_POS; } - boolean isInSameTree ( Cur that ) - { + boolean isInSameTree(Cur that) { assert isPositioned() && that.isPositioned(); - return _xobj.isInSameTree( that._xobj ); + return _xobj.isInSameTree(that._xobj); } // Retunr -1, 0 or 1 for relative cursor positions. Return 2 is not in sames trees. - int comparePosition ( Cur that ) - { + int comparePosition(Cur that) { assert isPositioned() && that.isPositioned(); // If in differnet locales, then can't comapre @@ -344,10 +343,10 @@ final class Cur // No need to denormalize, but I want positions which I can compare (no END_POS) Xobj xThis = _xobj; - int pThis = _pos == END_POS ? xThis.posAfter() - 1 : _pos; + int pThis = _pos == END_POS ? xThis.posAfter() - 1 : _pos; Xobj xThat = that._xobj; - int pThat = that._pos == END_POS ? xThat.posAfter() - 1 : that._pos; + int pThat = that._pos == END_POS ? xThat.posAfter() - 1 : that._pos; // There are several cases: // @@ -360,49 +359,59 @@ final class Cur // cursors are on, checkin for case 2 // - if (xThis == xThat) - return pThis < pThat ? -1 : pThis == pThat ? 0 : 1; + if (xThis == xThat) { + return Integer.compare(pThis, pThat); + } // Compute the depth of xThis. See if I hit xThat (case 2) int dThis = 0; - for ( Xobj x = xThis._parent ; x != null ; x = x._parent ) - { + for (Xobj x = xThis._parent; x != null; x = x._parent) { dThis++; - if (x == xThat) + if (x == xThat) { return pThat < xThat.posAfter() - 1 ? 1 : -1; + } } // Compute the depth of xThat. See if I hit xThis (case 2) int dThat = 0; - for ( Xobj x = xThat._parent ; x != null ; x = x._parent ) - { + for (Xobj x = xThat._parent; x != null; x = x._parent) { dThat++; - if (x == xThis) + if (x == xThis) { return pThis < xThis.posAfter() - 1 ? -1 : 1; + } } // Must be case 3 or 4 now. Find a common parent. If none, then it's case 4 - while ( dThis > dThat ) { dThis--; xThis = xThis._parent; } - while ( dThat > dThis ) { dThat--; xThat = xThat._parent; } + while (dThis > dThat) { + dThis--; + assert(xThis != null); + xThis = xThis._parent; + } + while (dThat > dThis) { + dThat--; + assert(xThat != null); + xThat = xThat._parent; + } assert dThat == dThis; - if (dThat == 0) + if (dThat == 0) { return 2; + } - assert xThis._parent != null && xThat._parent != null; + assert xThis != null && xThis._parent != null && xThat != null && xThat._parent != null; - while ( xThis._parent != xThat._parent ) - { - if ((xThis = xThis._parent) == null) + while (xThis._parent != xThat._parent) { + if ((xThis = xThis._parent) == null) { return 2; + } xThat = xThat._parent; } @@ -410,53 +419,52 @@ final class Cur // Now, see where xThis and XThat are relative to eachother in the childlist. Apply // some quick common checks before iterating. - if (xThis._prevSibling == null || xThat._nextSibling == null) + if (xThis._prevSibling == null || xThat._nextSibling == null) { return -1; + } - if (xThis._nextSibling == null || xThat._prevSibling == null) + if (xThis._nextSibling == null || xThat._prevSibling == null) { return 1; + } - while ( xThis != null ) - if ((xThis = xThis._prevSibling) == xThat) + while (xThis != null) { + if ((xThis = xThis._prevSibling) == xThat) { return 1; + } + } return -1; } - void setName ( QName newName ) - { + void setName(QName newName) { assert isNode() && newName != null; - _xobj.setName( newName ); + _xobj.setName(newName); } - void moveTo ( Xobj x ) - { - moveTo( x, 0 ); + void moveTo(Xobj x) { + moveTo(x, 0); } - void moveTo ( Xobj x, int p ) - { + void moveTo(Xobj x, int p) { // This cursor may not be normalized upon entry, don't assert isNormal() here assert x == null || _locale == x._locale; assert x != null || p == NO_POS; - assert x == null || x.isNormal( p ) || ( x.isVacant() && x._cchValue==0 && x._user == null ); + assert x == null || x.isNormal(p) || (x.isVacant() && x._cchValue == 0 && x._user == null); assert _state == REGISTERED || _state == EMBEDDED; - assert _state == EMBEDDED || (_xobj == null || !isOnList( _xobj._embedded )); - assert _state == REGISTERED || (_xobj != null && isOnList( _xobj._embedded )); + assert _state == EMBEDDED || (_xobj == null || !isOnList(_xobj._embedded)); + assert _state == REGISTERED || (_xobj != null && isOnList(_xobj._embedded)); - moveToNoCheck( x, p ); + moveToNoCheck(x, p); - assert isNormal() || ( _xobj.isVacant() && _xobj._cchValue==0 && _xobj._user == null ); + assert isNormal() || (_xobj.isVacant() && _xobj._cchValue == 0 && _xobj._user == null); } - void moveToNoCheck ( Xobj x, int p ) - { - if (_state == EMBEDDED && x != _xobj) - { - _xobj._embedded = listRemove( _xobj._embedded ); - _locale._registered = listInsert( _locale._registered ); + void moveToNoCheck(Xobj x, int p) { + if (_state == EMBEDDED && x != _xobj) { + _xobj._embedded = listRemove(_xobj._embedded); + _locale._registered = listInsert(_locale._registered); _state = REGISTERED; } @@ -464,429 +472,396 @@ final class Cur _pos = p; } - void moveToCur ( Cur to ) - { + void moveToCur(Cur to) { assert isNormal() && (to == null || to.isNormal()); - if (to == null) - moveTo( null, NO_POS ); - else - moveTo( to._xobj, to._pos ); + if (to == null) { + moveTo(null, NO_POS); + } else { + moveTo(to._xobj, to._pos); + } } - void moveToDom ( Dom d ) - { + void moveToDom(Dom d) { assert _locale == d.locale(); - assert d instanceof Xobj || d instanceof Xobj.SoapPartDom; + assert d instanceof Xobj || d instanceof SoapPartDom; - moveTo( d instanceof Xobj ? (Xobj) d : ((Xobj.SoapPartDom) d)._docXobj ); + moveTo(d instanceof Xobj ? (Xobj) d : ((SoapPartDom) d)._docXobj); } - static final class Locations - { + static final class Locations { private static final int NULL = -1; - Locations ( Locale l ) - { + Locations(Locale l) { _locale = l; - _xobjs = new Xobj [ _initialSize ]; - _poses = new int [ _initialSize ]; - _curs = new Cur [ _initialSize ]; - _next = new int [ _initialSize ]; - _prev = new int [ _initialSize ]; - _nextN = new int [ _initialSize ]; - _prevN = new int [ _initialSize ]; - - for ( int i = _initialSize - 1 ; i >= 0 ; i-- ) - { - assert _xobjs[ i ] == null; - _poses [ i ] = NO_POS; - _next [ i ] = i + 1; - _prev [ i ] = NULL; - _nextN [ i ] = NULL; - _prevN [ i ] = NULL; + _xobjs = new Xobj[_initialSize]; + _poses = new int[_initialSize]; + _curs = new Cur[_initialSize]; + _next = new int[_initialSize]; + _prev = new int[_initialSize]; + _nextN = new int[_initialSize]; + _prevN = new int[_initialSize]; + + for (int i = _initialSize - 1; i >= 0; i--) { + assert _xobjs[i] == null; + _poses[i] = NO_POS; + _next[i] = i + 1; + _prev[i] = NULL; + _nextN[i] = NULL; + _prevN[i] = NULL; } - _next [ _initialSize - 1 ] = NULL; + _next[_initialSize - 1] = NULL; _free = 0; _naked = NULL; } - boolean isSamePos ( int i, Cur c ) - { - if (_curs[ i ] == null) - return c._xobj == _xobjs[ i ] && c._pos == _poses[ i ]; - else - return c.isSamePos( _curs[ i ] ); + boolean isSamePos(int i, Cur c) { + if (_curs[i] == null) { + return c._xobj == _xobjs[i] && c._pos == _poses[i]; + } else { + return c.isSamePos(_curs[i]); + } } - boolean isAtEndOf ( int i, Cur c ) - { - assert _curs[ i ] != null || _poses[ i ] == 0; - assert _curs[ i ] == null || _curs[ i ].isNode(); + boolean isAtEndOf(int i, Cur c) { + assert _curs[i] != null || _poses[i] == 0; + assert _curs[i] == null || _curs[i].isNode(); - if (_curs[ i ] == null) - return c._xobj == _xobjs[ i ] && c._pos == END_POS; - else - return c.isAtEndOf( _curs[ i ] ); + if (_curs[i] == null) { + return c._xobj == _xobjs[i] && c._pos == END_POS; + } else { + return c.isAtEndOf(_curs[i]); + } } - void moveTo ( int i, Cur c ) - { - if (_curs[ i ] == null) - c.moveTo( _xobjs[ i ], _poses[ i ] ); - else - c.moveToCur( _curs[ i ] ); + void moveTo(int i, Cur c) { + if (_curs[i] == null) { + c.moveTo(_xobjs[i], _poses[i]); + } else { + c.moveToCur(_curs[i]); + } } - int insert ( int head, int before, int i ) - { - return insert( head, before, i, _next, _prev ); + int insert(int head, int before, int i) { + return insert(head, before, i, _next, _prev); } - int remove ( int head, int i ) - { - Cur c = _curs[ i ]; + int remove(int head, int i) { + Cur c = _curs[i]; - assert c != null || _xobjs[ i ] != null; - assert c != null || _xobjs[ i ] != null; + assert c != null || _xobjs[i] != null; + assert c != null || _xobjs[i] != null; - if (c != null) - { - _curs[ i ].release(); - _curs[ i ] = null; + if (c != null) { + _curs[i].release(); + _curs[i] = null; - assert _xobjs[ i ] == null; - assert _poses [ i ] == NO_POS; - } - else - { - assert _xobjs[ i ] != null && _poses[ i ] != NO_POS; + assert _xobjs[i] == null; + assert _poses[i] == NO_POS; + } else { + assert _xobjs[i] != null && _poses[i] != NO_POS; - _xobjs[ i ] = null; - _poses[ i ] = NO_POS; + _xobjs[i] = null; + _poses[i] = NO_POS; - _naked = remove( _naked, i, _nextN, _prevN ); + _naked = remove(_naked, i, _nextN, _prevN); } - head = remove( head, i, _next, _prev ); + head = remove(head, i, _next, _prev); - _next[ i ] = _free; + _next[i] = _free; _free = i; return head; } - int allocate ( Cur addThis ) - { + int allocate(Cur addThis) { assert addThis.isPositioned(); - if (_free == NULL) + if (_free == NULL) { makeRoom(); + } int i = _free; - _free = _next [ i ]; + _free = _next[i]; - _next [ i ] = NULL; - assert _prev [ i ] == NULL; + _next[i] = NULL; + assert _prev[i] == NULL; - assert _curs [ i ] == null; - assert _xobjs[ i ] == null; - assert _poses[ i ] == NO_POS; + assert _curs[i] == null; + assert _xobjs[i] == null; + assert _poses[i] == NO_POS; - _xobjs [ i ] = addThis._xobj; - _poses [ i ] = addThis._pos; + _xobjs[i] = addThis._xobj; + _poses[i] = addThis._pos; - _naked = insert( _naked, NULL, i, _nextN, _prevN ); + _naked = insert(_naked, NULL, i, _nextN, _prevN); return i; } - private static int insert ( int head, int before, int i, int[] next, int[] prev ) - { - if (head == NULL) - { + private static int insert(int head, int before, int i, int[] next, int[] prev) { + if (head == NULL) { assert before == NULL; - prev[ i ] = i; + prev[i] = i; head = i; - } - else if (before != NULL) - { - prev[ i ] = prev[ before ]; - next[ i ] = before; - prev[ before ] = i; + } else if (before != NULL) { + prev[i] = prev[before]; + next[i] = before; + prev[before] = i; if (head == before) head = i; - } - else - { - prev[ i ] = prev[ head ]; - assert next[ i ] == NULL; - next[ prev[ head ] ] = i; - prev[ head ] = i; + } else { + prev[i] = prev[head]; + assert next[i] == NULL; + next[prev[head]] = i; + prev[head] = i; } return head; } - private static int remove ( int head, int i, int[] next, int[] prev ) - { - if (prev[ i ] == i) - { + private static int remove(int head, int i, int[] next, int[] prev) { + if (prev[i] == i) { assert head == i; head = NULL; - } - else - { - if (head == i) - head = next[ i ]; - else - next[ prev [ i ] ] = next[ i ]; - - if (next[ i ] == NULL) - prev[ head ] = prev[ i ]; - else - { - prev[ next[ i ] ] = prev[ i ]; - next[ i ] = NULL; + } else { + if (head == i) { + head = next[i]; + } else { + next[prev[i]] = next[i]; + } + + if (next[i] == NULL) { + prev[head] = prev[i]; + } else { + prev[next[i]] = prev[i]; + next[i] = NULL; } } - prev[ i ] = NULL; - assert next[ i ] == NULL; + prev[i] = NULL; + assert next[i] == NULL; return head; } - void notifyChange ( ) - { - for ( int i ; (i = _naked) != NULL ; ) - { - assert _curs[ i ] == null && _xobjs[ i ] != null && _poses[ i ] != NO_POS; + void notifyChange() { + for (int i; (i = _naked) != NULL; ) { + assert _curs[i] == null && _xobjs[i] != null && _poses[i] != NO_POS; - _naked = remove( _naked, i, _nextN, _prevN ); + _naked = remove(_naked, i, _nextN, _prevN); - _curs[ i ] = _locale.getCur(); - _curs[ i ].moveTo( _xobjs[ i ], _poses[ i ] ); + _curs[i] = _locale.getCur(); + _curs[i].moveTo(_xobjs[i], _poses[i]); - _xobjs[ i ] = null; - _poses[ i ] = NO_POS; + _xobjs[i] = null; + _poses[i] = NO_POS; } } - int next ( int i ) { return _next[ i ]; } - int prev ( int i ) { return _prev[ i ]; } + int next(int i) { + return _next[i]; + } - private void makeRoom ( ) - { + int prev(int i) { + return _prev[i]; + } + + private void makeRoom() { assert _free == NULL; int l = _xobjs.length; - Xobj [] oldXobjs = _xobjs; - int [] oldPoses = _poses; - Cur [] oldCurs = _curs; - int [] oldNext = _next; - int [] oldPrev = _prev; - int [] oldNextN = _nextN; - int [] oldPrevN = _prevN; - - _xobjs = new Xobj [ l * 2 ]; - _poses = new int [ l * 2 ]; - _curs = new Cur [ l * 2 ]; - _next = new int [ l * 2 ]; - _prev = new int [ l * 2 ]; - _nextN = new int [ l * 2 ]; - _prevN = new int [ l * 2 ]; - - System.arraycopy( oldXobjs, 0, _xobjs, 0, l ); - System.arraycopy( oldPoses, 0, _poses, 0, l ); - System.arraycopy( oldCurs, 0, _curs, 0, l ); - System.arraycopy( oldNext, 0, _next, 0, l ); - System.arraycopy( oldPrev, 0, _prev, 0, l ); - System.arraycopy( oldNextN, 0, _nextN, 0, l ); - System.arraycopy( oldPrevN, 0, _prevN, 0, l ); - - for ( int i = l * 2 - 1 ; i >= l ; i-- ) - { - _next [ i ] = i + 1; - _prev [ i ] = NULL; - _nextN [ i ] = NULL; - _prevN [ i ] = NULL; - _poses [ i ] = NO_POS; + Xobj[] oldXobjs = _xobjs; + int[] oldPoses = _poses; + Cur[] oldCurs = _curs; + int[] oldNext = _next; + int[] oldPrev = _prev; + int[] oldNextN = _nextN; + int[] oldPrevN = _prevN; + + _xobjs = new Xobj[l * 2]; + _poses = new int[l * 2]; + _curs = new Cur[l * 2]; + _next = new int[l * 2]; + _prev = new int[l * 2]; + _nextN = new int[l * 2]; + _prevN = new int[l * 2]; + + System.arraycopy(oldXobjs, 0, _xobjs, 0, l); + System.arraycopy(oldPoses, 0, _poses, 0, l); + System.arraycopy(oldCurs, 0, _curs, 0, l); + System.arraycopy(oldNext, 0, _next, 0, l); + System.arraycopy(oldPrev, 0, _prev, 0, l); + System.arraycopy(oldNextN, 0, _nextN, 0, l); + System.arraycopy(oldPrevN, 0, _prevN, 0, l); + + for (int i = l * 2 - 1; i >= l; i--) { + _next[i] = i + 1; + _prev[i] = NULL; + _nextN[i] = NULL; + _prevN[i] = NULL; + _poses[i] = NO_POS; } - _next [ l * 2 - 1 ] = NULL; + _next[l * 2 - 1] = NULL; _free = l; } private static final int _initialSize = 32; - private Locale _locale; + private final Locale _locale; - private Xobj [] _xobjs; - private int [] _poses; - private Cur [] _curs; - private int [] _next; - private int [] _prev; - private int [] _nextN; - private int [] _prevN; + private Xobj[] _xobjs; + private int[] _poses; + private Cur[] _curs; + private int[] _next; + private int[] _prev; + private int[] _nextN; + private int[] _prevN; private int _free; // Unused entries private int _naked; // Entries without Curs } - void push ( ) - { + void push() { assert isPositioned(); - int i = _locale._locations.allocate( this ); - _stackTop = _locale._locations.insert( _stackTop, _stackTop, i ); - } - - void pop ( boolean stay ) - { - if (stay) - popButStay(); - else - pop(); + int i = _locale._locations.allocate(this); + _stackTop = _locale._locations.insert(_stackTop, _stackTop, i); } - void popButStay ( ) - { - if (_stackTop != Locations.NULL) - _stackTop = _locale._locations.remove( _stackTop, _stackTop ); + void popButStay() { + if (_stackTop != Locations.NULL) { + _stackTop = _locale._locations.remove(_stackTop, _stackTop); + } } - boolean pop ( ) - { - if (_stackTop == Locations.NULL) + boolean pop() { + if (_stackTop == Locations.NULL) { return false; + } - _locale._locations.moveTo( _stackTop, this ); - _stackTop = _locale._locations.remove( _stackTop, _stackTop ); + _locale._locations.moveTo(_stackTop, this); + _stackTop = _locale._locations.remove(_stackTop, _stackTop); return true; } - boolean isAtLastPush ( ) - { + boolean isAtLastPush() { assert _stackTop != Locations.NULL; - return _locale._locations.isSamePos( _stackTop, this ); + return _locale._locations.isSamePos(_stackTop, this); } - boolean isAtEndOfLastPush ( ) - { + boolean isAtEndOfLastPush() { assert _stackTop != Locations.NULL; - return _locale._locations.isAtEndOf( _stackTop, this ); + return _locale._locations.isAtEndOf(_stackTop, this); } - void addToSelection ( Cur that ) - { + void addToSelection(Cur that) { assert that != null && that.isNormal(); assert isPositioned() && that.isPositioned(); - int i = _locale._locations.allocate( that ); - _selectionFirst = _locale._locations.insert( _selectionFirst, Locations.NULL, i ); + int i = _locale._locations.allocate(that); + _selectionFirst = _locale._locations.insert(_selectionFirst, Locations.NULL, i); _selectionCount++; } - void addToSelection ( ) - { + void addToSelection() { assert isPositioned(); - int i = _locale._locations.allocate( this ); - _selectionFirst = _locale._locations.insert( _selectionFirst, Locations.NULL, i ); + int i = _locale._locations.allocate(this); + _selectionFirst = _locale._locations.insert(_selectionFirst, Locations.NULL, i); _selectionCount++; } - private int selectionIndex ( int i ) - { + private int selectionIndex(int i) { assert _selectionN >= -1 && i >= 0 && i < _selectionCount; - if (_selectionN == -1) - { + if (_selectionN == -1) { _selectionN = 0; _selectionLoc = _selectionFirst; } - while ( _selectionN < i ) - { - _selectionLoc = _locale._locations.next( _selectionLoc ); + while (_selectionN < i) { + _selectionLoc = _locale._locations.next(_selectionLoc); _selectionN++; } - while ( _selectionN > i ) - { - _selectionLoc = _locale._locations.prev( _selectionLoc ); + while (_selectionN > i) { + _selectionLoc = _locale._locations.prev(_selectionLoc); _selectionN--; } return _selectionLoc; } - void removeSelection ( int i ) - { - assert i >= 0 && i < _selectionCount; + void removeFirstSelection() { + final int i = 0; + assert i < _selectionCount; - int j = selectionIndex( i ); + int j = selectionIndex(i); // Update the nth selection indices to accomodate the deletion - if (i < _selectionN) + if (i < _selectionN) { _selectionN--; - else if (i == _selectionN) - { + } else if (i == _selectionN) { _selectionN--; - - if (i == 0) - _selectionLoc = Locations.NULL; - else - _selectionLoc = _locale._locations.prev( _selectionLoc ); + _selectionLoc = Locations.NULL; } - _selectionFirst = _locale._locations.remove( _selectionFirst, j ); + _selectionFirst = _locale._locations.remove(_selectionFirst, j); _selectionCount--; } - int selectionCount ( ) - { + int selectionCount() { return _selectionCount; } - void moveToSelection ( int i ) - { + void moveToSelection(int i) { assert i >= 0 && i < _selectionCount; - _locale._locations.moveTo( selectionIndex( i ), this ); + _locale._locations.moveTo(selectionIndex(i), this); } - void clearSelection ( ) - { + void clearSelection() { assert _selectionCount >= 0; - while ( _selectionCount > 0 ) - removeSelection( 0 ); + while (_selectionCount > 0) { + removeFirstSelection(); + } + } + + boolean toParent() { + return toParent(false); } - boolean toParent ( ) { return toParent( false ); } - boolean toParentRaw ( ) { return toParent( true ); } + boolean toParentRaw() { + return toParent(true); + } - Xobj getParent ( ) { return getParent( false ); } - Xobj getParentRaw ( ) { return getParent( true ); } + Xobj getParent() { + return getParent(false); + } - boolean hasParent ( ) - { + Xobj getParentRaw() { + return getParent(true); + } + + boolean hasParent() { assert isPositioned(); if (_pos == END_POS || (_pos >= 1 && _pos < _xobj.posAfter())) @@ -897,8 +872,7 @@ final class Cur return _xobj._parent != null; } - Xobj getParentNoRoot() - { + Xobj getParentNoRoot() { assert isPositioned(); if (_pos == END_POS || (_pos >= 1 && _pos < _xobj.posAfter())) @@ -912,8 +886,7 @@ final class Cur return null; } - Xobj getParent ( boolean raw ) - { + Xobj getParent(boolean raw) { assert isPositioned(); if (_pos == END_POS || (_pos >= 1 && _pos < _xobj.posAfter())) @@ -934,31 +907,27 @@ final class Cur Xobj root = r._xobj; r.next(); - moveNode( r ); + moveNode(r); r.release(); return root; } - boolean toParent ( boolean raw ) - { - Xobj parent = getParent( raw ); + boolean toParent(boolean raw) { + Xobj parent = getParent(raw); if (parent == null) return false; - moveTo( parent ); + moveTo(parent); return true; } - void toRoot () - { + void toRoot() { Xobj xobj = _xobj; - while (!xobj.isRoot()) - { - if (xobj._parent==null) - { + while (!xobj.isRoot()) { + if (xobj._parent == null) { Cur r = _locale.tempCur(); r.createRoot(); @@ -966,7 +935,7 @@ final class Cur Xobj root = r._xobj; r.next(); - moveNode( r ); + moveNode(r); r.release(); xobj = root; @@ -977,121 +946,104 @@ final class Cur moveTo(xobj); } - boolean hasText ( ) - { + boolean hasText() { assert isNode(); return _xobj.hasTextEnsureOccupancy(); } - boolean hasAttrs ( ) - { + boolean hasAttrs() { assert isNode(); return _xobj.hasAttrs(); } - boolean hasChildren ( ) - { + boolean hasChildren() { assert isNode(); return _xobj.hasChildren(); } - boolean toFirstChild ( ) - { + boolean toFirstChild() { assert isNode(); if (!_xobj.hasChildren()) return false; - for ( Xobj x = _xobj._firstChild ; ; x = x._nextSibling ) - { - if (!x.isAttr()) - { - moveTo( x ); + for (Xobj x = _xobj._firstChild; ; x = x._nextSibling) { + if (!x.isAttr()) { + moveTo(x); return true; } } } - protected boolean toLastChild ( ) - { + protected boolean toLastChild() { assert isNode(); if (!_xobj.hasChildren()) return false; - moveTo( _xobj._lastChild ); + moveTo(_xobj._lastChild); return true; } - boolean toNextSibling ( ) - { + boolean toNextSibling() { assert isNode(); - if (_xobj.isAttr()) - { - if (_xobj._nextSibling != null && _xobj._nextSibling.isAttr()) - { - moveTo( _xobj._nextSibling ); + if (_xobj.isAttr()) { + if (_xobj._nextSibling != null && _xobj._nextSibling.isAttr()) { + moveTo(_xobj._nextSibling); return true; } - } - else if (_xobj._nextSibling != null) - { - moveTo( _xobj._nextSibling ); + } else if (_xobj._nextSibling != null) { + moveTo(_xobj._nextSibling); return true; } return false; } - void setValueAsQName ( QName qname ) - { + void setValueAsQName(QName qname) { assert isNode(); - String value = qname.getLocalPart(); - String ns = qname.getNamespaceURI(); + String value = qname.getLocalPart(); + String ns = qname.getNamespaceURI(); String prefix = prefixForNamespace( - ns, qname.getPrefix().length() > 0 ? qname.getPrefix() : null, true ); + ns, qname.getPrefix().length() > 0 ? qname.getPrefix() : null, true); if (prefix.length() > 0) value = prefix + ":" + value; - setValue( value ); + setValue(value); } - void setValue ( String value ) - { + void setValue(String value) { assert isNode(); - moveNodeContents( null, false ); + moveNodeContents(null, false); next(); - insertString( value ); + insertString(value); toParent(); } - void removeFollowingAttrs ( ) - { + void removeFollowingAttrs() { assert isAttr(); QName attrName = getName(); push(); - if (toNextAttr()) - { - while ( isAttr() ) - { - if (getName().equals( attrName )) - moveNode( null ); + if (toNextAttr()) { + while (isAttr()) { + if (getName().equals(attrName)) + moveNode(null); else if (!toNextAttr()) break; } @@ -1100,131 +1052,121 @@ final class Cur pop(); } - String getAttrValue ( QName name ) - { + String getAttrValue(QName name) { String s = null; push(); - if (toAttr( name )) + if (toAttr(name)) { s = getValueAsString(); + } pop(); return s; } - void setAttrValueAsQName ( QName name, QName value ) - { + void setAttrValueAsQName(QName value) { assert isContainer(); - if (value == null) - { - _xobj.removeAttr( name ); - } - else - { - if (toAttr( name )) - { - removeFollowingAttrs(); - } - else - { - next(); - createAttr( name ); - } + final QName name = Locale._xsiType; - setValueAsQName( value ); + if (value == null) { + _xobj.removeAttr(name); + return; + } - toParent(); + if (toAttr(name)) { + removeFollowingAttrs(); + } else { + next(); + createAttr(name); } + setValueAsQName(value); + toParent(); } - boolean removeAttr ( QName name ) - { + boolean removeAttr(QName name) { assert isContainer(); - return _xobj.removeAttr( name ); + return _xobj.removeAttr(name); } - void setAttrValue ( QName name, String value ) - { + void setAttrValue(QName name, String value) { assert isContainer(); - _xobj.setAttr( name, value ); + _xobj.setAttr(name, value); } - boolean toAttr ( QName name ) - { + boolean toAttr(QName name) { assert isNode(); - Xobj a = _xobj.getAttr( name ); + Xobj a = _xobj.getAttr(name); if (a == null) return false; - moveTo( a ); + moveTo(a); return true; } - boolean toFirstAttr ( ) - { + boolean toFirstAttr() { assert isNode(); Xobj firstAttr = _xobj.firstAttr(); - if (firstAttr == null) + if (firstAttr == null) { return false; + } - moveTo( firstAttr ); + moveTo(firstAttr); return true; } - boolean toLastAttr ( ) - { + boolean toLastAttr() { assert isNode(); - if (!toFirstAttr()) + if (!toFirstAttr()) { return false; + } - while ( toNextAttr() ) - ; + //noinspection StatementWithEmptyBody + while (toNextAttr()) ; return true; } - boolean toNextAttr ( ) - { + boolean toNextAttr() { assert isAttr() || isContainer(); Xobj nextAttr = _xobj.nextAttr(); - if (nextAttr == null) + if (nextAttr == null) { return false; + } - moveTo( nextAttr ); + moveTo(nextAttr); return true; } - boolean toPrevAttr ( ) - { - if (isAttr()) - { - if (_xobj._prevSibling == null) - moveTo( _xobj.ensureParent() ); - else - moveTo( _xobj._prevSibling ); + @SuppressWarnings("UnusedReturnValue") + boolean toPrevAttr() { + if (isAttr()) { + if (_xobj._prevSibling == null) { + moveTo(_xobj.ensureParent()); + } else { + moveTo(_xobj._prevSibling); + } return true; } prev(); - if (!isContainer()) - { + if (!isContainer()) { next(); return false; } @@ -1232,15 +1174,17 @@ final class Cur return toLastAttr(); } - boolean skipWithAttrs ( ) - { + @SuppressWarnings("UnusedReturnValue") + boolean skipWithAttrs() { assert isNode(); - if (skip()) + if (skip()) { return true; + } - if (_xobj.isRoot()) + if (_xobj.isRoot()) { return false; + } assert _xobj.isAttr(); @@ -1251,63 +1195,54 @@ final class Cur return true; } - boolean skip ( ) - { + boolean skip() { assert isNode(); if (_xobj.isRoot()) return false; - if (_xobj.isAttr()) - { + if (_xobj.isAttr()) { if (_xobj._nextSibling == null || !_xobj._nextSibling.isAttr()) return false; - moveTo( _xobj._nextSibling, 0 ); - } - else - moveTo( getNormal( _xobj, _xobj.posAfter() ), _posTemp ); + moveTo(_xobj._nextSibling, 0); + } else + moveTo(getNormal(_xobj, _xobj.posAfter()), _posTemp); return true; } - void toEnd ( ) - { + void toEnd() { assert isNode(); - moveTo( _xobj, END_POS ); + moveTo(_xobj, END_POS); } - void moveToCharNode ( CharNode node ) - { + void moveToCharNode(CharNode node) { assert node.getDom() != null && node.getDom().locale() == _locale; - moveToDom( node.getDom() ); + moveToDom(node.getDom()); CharNode n; _xobj.ensureOccupancy(); n = _xobj._charNodesValue = - updateCharNodes( _locale, _xobj, _xobj._charNodesValue, _xobj._cchValue ); + updateCharNodes(_locale, _xobj, _xobj._charNodesValue, _xobj._cchValue); - for ( ; n != null ; n = n._next ) - { - if (node == n) - { - moveTo( getNormal( _xobj, n._off + 1 ), _posTemp ); + for (; n != null; n = n._next) { + if (node == n) { + moveTo(getNormal(_xobj, n._off + 1), _posTemp); return; } } n = _xobj._charNodesAfter = - updateCharNodes( _locale, _xobj, _xobj._charNodesAfter, _xobj._cchAfter ); + updateCharNodes(_locale, _xobj, _xobj._charNodesAfter, _xobj._cchAfter); - for ( ; n != null ; n = n._next ) - { - if (node == n) - { - moveTo( getNormal( _xobj, n._off + _xobj._cchValue + 2 ), _posTemp ); + for (; n != null; n = n._next) { + if (node == n) { + moveTo(getNormal(_xobj, n._off + _xobj._cchValue + 2), _posTemp); return; } } @@ -1315,40 +1250,42 @@ final class Cur assert false; } - boolean prevWithAttrs ( ) - { - if (prev()) + @SuppressWarnings("UnusedReturnValue") + boolean prevWithAttrs() { + if (prev()) { return true; + } - if (!isAttr()) + if (!isAttr()) { return false; + } toParent(); return true; } - boolean prev ( ) - { + boolean prev() { assert isPositioned(); - if (_xobj.isRoot() && _pos == 0) + if (_xobj.isRoot() && _pos == 0) { return false; + } - if (_xobj.isAttr() && _pos == 0 && _xobj._prevSibling == null) + if (_xobj.isAttr() && _pos == 0 && _xobj._prevSibling == null) { return false; + } Xobj x = getDenormal(); - int p = _posTemp; + int p = _posTemp; - assert p > 0 && p != END_POS; + assert p > 0; int pa = x.posAfter(); - if (p > pa) + if (p > pa) { p = pa; - else if (p == pa) - { + } else if (p == pa) { // Text after an attr is allowed only on the last attr, // and that text belongs to the parent container.. // @@ -1356,122 +1293,104 @@ final class Cur // inside the container, and we need to skip the attrs. if (x.isAttr() && - (x._cchAfter > 0 || x._nextSibling == null || !x._nextSibling.isAttr())) - { + (x._cchAfter > 0 || x._nextSibling == null || !x._nextSibling.isAttr())) { x = x.ensureParent(); p = 0; - } - else + } else { p = END_POS; - } - else if (p == pa - 1) - { + } + } else if (p == pa - 1) { x.ensureOccupancy(); p = x._cchValue > 0 ? 1 : 0; - } - else if (p > 1) + } else if (p > 1) { p = 1; - else - { + } else { + //noinspection ConstantConditions assert p == 1; p = 0; } - moveTo( getNormal( x, p ), _posTemp ); + moveTo(getNormal(x, p), _posTemp); return true; } - boolean next ( boolean withAttrs ) - { + @SuppressWarnings("UnusedReturnValue") + boolean next(boolean withAttrs) { return withAttrs ? nextWithAttrs() : next(); } - boolean nextWithAttrs ( ) - { + boolean nextWithAttrs() { int k = kind(); - if (kindIsContainer( k )) - { - if (toFirstAttr()) + if (kindIsContainer(k)) { + if (toFirstAttr()) { return true; - } - else if (k == -ATTR) - { - if (next()) + } + } else if (k == -ATTR) { + if (next()) { return true; + } toParent(); - if (!toParentRaw()) + if (!toParentRaw()) { return false; + } } return next(); } - boolean next ( ) - { + boolean next() { assert isNormal(); Xobj x = _xobj; - int p = _pos; + int p = _pos; int pa = x.posAfter(); - if (p >= pa) + if (p >= pa) { p = _xobj.posMax(); - else if (p == END_POS) - { - if (x.isRoot() || (x.isAttr() && (x._nextSibling == null || !x._nextSibling.isAttr()))) + } else if (p == END_POS) { + if (x.isRoot() || (x.isAttr() && (x._nextSibling == null || !x._nextSibling.isAttr()))) { return false; + } p = pa; - } - else if (p > 0) - { + } else if (p > 0) { assert x._firstChild == null || !x._firstChild.isAttr(); - if (x._firstChild != null) - { + if (x._firstChild != null) { x = x._firstChild; p = 0; - } - else + } else { p = END_POS; - } - else - { + } + } else { assert p == 0; x.ensureOccupancy(); p = 1; - if (x._cchValue == 0) - { - if (x._firstChild != null) - { - if (x._firstChild.isAttr()) - { + if (x._cchValue == 0) { + if (x._firstChild != null) { + if (x._firstChild.isAttr()) { Xobj a = x._firstChild; - while ( a._nextSibling != null && a._nextSibling.isAttr() ) + while (a._nextSibling != null && a._nextSibling.isAttr()) { a = a._nextSibling; + } - if (a._cchAfter > 0) - { + if (a._cchAfter > 0) { x = a; p = a.posAfter(); - } - else if (a._nextSibling != null) - { + } else if (a._nextSibling != null) { x = a._nextSibling; p = 0; } - } - else - { + } else { x = x._firstChild; p = 0; } @@ -1479,13 +1398,12 @@ final class Cur } } - moveTo( getNormal( x, p ), _posTemp ); + moveTo(getNormal(x, p), _posTemp); return true; } - int prevChars ( int cch ) - { + int prevChars(int cch) { assert isPositioned(); int cchLeft = cchLeft(); @@ -1496,13 +1414,12 @@ final class Cur // Dang, I love this stmt :-) if (cch != 0) - moveTo( getNormal( getDenormal(), _posTemp - cch ), _posTemp ); + moveTo(getNormal(getDenormal(), _posTemp - cch), _posTemp); return cch; } - int nextChars ( int cch ) - { + int nextChars(int cch) { assert isPositioned(); int cchRight = cchRight(); @@ -1510,25 +1427,23 @@ final class Cur if (cchRight == 0) return 0; - if (cch < 0 || cch >= cchRight) - { + if (cch < 0 || cch >= cchRight) { // Use next to not skip over children next(); return cchRight; } - moveTo( getNormal( _xobj, _pos + cch ), _posTemp ); + moveTo(getNormal(_xobj, _pos + cch), _posTemp); return cch; } - void setCharNodes ( CharNode nodes ) - { + void setCharNodes(CharNode nodes) { assert nodes == null || _locale == nodes.locale(); assert isPositioned(); Xobj x = getDenormal(); - int p = _posTemp; + int p = _posTemp; assert !x.isRoot() || (p > 0 && p < x.posAfter()); @@ -1537,15 +1452,14 @@ final class Cur else x._charNodesValue = nodes; - for ( ; nodes != null ; nodes = nodes._next ) - nodes.setDom( (Dom) x ); + for (; nodes != null; nodes = nodes._next) + nodes.setDom((Dom) x); // No Need to notify text change or alter version, text nodes are // not part of the infoset } - CharNode getCharNodes ( ) - { + CharNode getCharNodes() { assert isPositioned(); assert !isRoot(); @@ -1553,36 +1467,32 @@ final class Cur CharNode nodes; - if (_posTemp >= x.posAfter()) - { + if (_posTemp >= x.posAfter()) { nodes = x._charNodesAfter = - updateCharNodes( _locale, x, x._charNodesAfter, x._cchAfter ); - } - else - { + updateCharNodes(_locale, x, x._charNodesAfter, x._cchAfter); + } else { x.ensureOccupancy(); nodes = x._charNodesValue = - updateCharNodes( _locale, x, x._charNodesValue, x._cchValue ); + updateCharNodes(_locale, x, x._charNodesValue, x._cchValue); } return nodes; } - // private - static CharNode updateCharNodes ( Locale l, Xobj x, CharNode nodes, int cch ) - { + // private + static CharNode updateCharNodes(Locale l, Xobj x, CharNode nodes, int cch) { assert nodes == null || nodes.locale() == l; CharNode node = nodes; int i = 0; - while ( node != null && cch > 0 ) - { + while (node != null && cch > 0) { assert node.getDom() == x; - if (node._cch > cch) + if (node._cch > cch) { node._cch = cch; + } node._off = i; i += node._cch; @@ -1591,81 +1501,66 @@ final class Cur node = node._next; } - if (cch <= 0) - { - for ( ; node != null ; node = node._next ) - { + if (cch <= 0) { + for (; node != null; node = node._next) { assert node.getDom() == x; - if (node._cch != 0) + if (node._cch != 0) { node._cch = 0; + } node._off = i; } - } - else - { + } else { node = l.createTextNode(); - node.setDom( (Dom) x ); + node.setDom((Dom) x); node._cch = cch; node._off = i; - nodes = CharNode.appendNode( nodes, node ); + nodes = CharNode.appendNode(nodes, node); } return nodes; } - final QName getXsiTypeName ( ) - { + final QName getXsiTypeName() { assert isNode(); return _xobj.getXsiTypeName(); } - final void setXsiType ( QName value ) - { + final void setXsiType(QName value) { assert isContainer(); - setAttrValueAsQName( Locale._xsiType, value ); + setAttrValueAsQName(value); } - final QName valueAsQName ( ) - { - throw new RuntimeException( "Not implemented" ); + final String namespaceForPrefix(String prefix, boolean defaultAlwaysMapped) { + return _xobj.namespaceForPrefix(prefix, defaultAlwaysMapped); } - final String namespaceForPrefix ( String prefix, boolean defaultAlwaysMapped ) - { - return _xobj.namespaceForPrefix( prefix, defaultAlwaysMapped ); - } - - final String prefixForNamespace ( String ns, String suggestion, boolean createIfMissing ) - { + final String prefixForNamespace(String ns, String suggestion, boolean createIfMissing) { return (isContainer() ? _xobj : getParent()). - prefixForNamespace( ns, suggestion, createIfMissing ); + prefixForNamespace(ns, suggestion, createIfMissing); } // Does the node at this cursor properly contain the position specified by the argument - boolean contains ( Cur that ) - { + boolean contains(Cur that) { assert isNode(); assert that != null && that.isPositioned(); - return _xobj.contains( that ); + return _xobj.contains(that); } - void insertString ( String s ) - { + void insertString(String s) { if (s != null) - insertChars( s, 0, s.length() ); + insertChars(s, 0, s.length()); } - void insertChars ( Object src, int off, int cch ) - { + void insertChars(Object src, int off, int cch) { assert isPositioned() && !isRoot(); - assert CharUtil.isValid( src, off, cch ); + assert CharUtil.isValid(src, off, cch); // Check for nothing to insert @@ -1687,7 +1582,7 @@ final class Cur // the new chars. Note that a denormalized position can never be <= 0. Xobj x = getDenormal(); - int p = _posTemp; + int p = _posTemp; assert p > 0; @@ -1695,13 +1590,13 @@ final class Cur // position after. This insertChars takes care of all the appropriate invalidations // (passing true as last arg). - x.insertCharsHelper( p, src, off, cch, true ); + x.insertCharsHelper(p, src, off, cch, true); // Reposition the cursor to be just before the newly inserted text. It's current // position could have been shifted, or it may have been just before the end tag, or // normalized on another Xobj. - moveTo( x, p ); + moveTo(x, p); _locale._versionAll++; } @@ -1709,8 +1604,7 @@ final class Cur // Move the chars just after this Cur to the "to" Cur. If no "to" Cur is specified, // then remove the chars. - Object moveChars ( Cur to, int cchMove ) - { + Object moveChars(Cur to, int cchMove) { assert isPositioned(); assert cchMove <= 0 || cchMove <= cchRight(); assert to == null || (to.isPositioned() && !to.isRoot()); @@ -1720,8 +1614,7 @@ final class Cur // If we're instructed to move 0 characters, then return the null triple. - if (cchMove == 0) - { + if (cchMove == 0) { _offSrc = 0; _cchSrc = 0; @@ -1731,40 +1624,35 @@ final class Cur // Here I record the triple of the chars to move. I will return this. No need to save // cch 'cause cchMove will be that value. - Object srcMoved = getChars( cchMove ); - int offMoved = _offSrc; + Object srcMoved = getChars(cchMove); + int offMoved = _offSrc; // Either I'm moving text from the value or the after text. If after, then the container // must be occupied. If in the value, because we're just before text, it must be occupied. assert isText() && (_pos >= _xobj.posAfter() ? _xobj._parent : _xobj).isOccupied(); - if (to == null) - { + if (to == null) { // In this case, I'm removing chars vs moving them. Normally I would like to blow // them away entirely, but if there are any references to those chars via a bookmark // I need to keep them alive. I do this by moving these chars to a new root. Note // that because Curs will stay behind, I don't have to check for them. - for ( Bookmark b = _xobj._bookmarks ; b != null ; b = b._next ) - { - if (inChars( b, cchMove, false )) - { + for (Bookmark b = _xobj._bookmarks; b != null; b = b._next) { + if (inChars(b, cchMove, false)) { Cur c = _locale.tempCur(); c.createRoot(); c.next(); - Object chars = moveChars( c, cchMove ); + Object chars = moveChars(c, cchMove); c.release(); return chars; } } - } - else - { + } else { // If the target, "to", is inside or on the edge of the text to be moved, then this // is a no-op. In this case, I still want to return the text "moved". // @@ -1773,13 +1661,12 @@ final class Cur // different location, then "to" would be at the beginning of the newly moved chars, // and "this" would be at the gap left by the newly removed chars. - if (inChars( to, cchMove, true )) - { + if (inChars(to, cchMove, true)) { // BUGBUG - may want to consider shuffling the interior cursors to the right just // like I move "this" to the right... - to.moveToCur( this ); - nextChars( cchMove ); + to.moveToCur(this); + nextChars(cchMove); _offSrc = offMoved; _cchSrc = cchMove; @@ -1789,7 +1676,7 @@ final class Cur // Copy the chars here, I'll remove the originals next - to.insertChars( srcMoved, offMoved, cchMove ); + to.insertChars(srcMoved, offMoved, cchMove); } // Notice that I can delay the general change notification to this point because any @@ -1803,9 +1690,9 @@ final class Cur //if ( _xobj != null ) { if (to == null) - _xobj.removeCharsHelper( _pos, cchMove, null, NO_POS, false, true ); + _xobj.removeCharsHelper(_pos, cchMove, null, NO_POS, false, true); else - _xobj.removeCharsHelper( _pos, cchMove, to._xobj, to._pos, false, true ); + _xobj.removeCharsHelper(_pos, cchMove, to._xobj, to._pos, false, true); } // Need to update the position of this cursor even though it did not move anywhere. This @@ -1821,11 +1708,10 @@ final class Cur return srcMoved; } - void moveNode ( Cur to ) - { + void moveNode(Cur to) { assert isNode() && !isRoot(); assert to == null || to.isPositioned(); - assert to == null || !contains( to ); + assert to == null || !contains(to); assert to == null || !to.isRoot(); // TODO - should assert that is an attr is being moved, it is ok there @@ -1843,7 +1729,7 @@ final class Cur // worry about messing with "this" here given that it not should be treated like any other // cursor after this point. - moveNode( x, to ); + moveNode(x, to); } // Moves text from one place to another in a low-level way, used as a helper for the higher @@ -1852,13 +1738,12 @@ final class Cur // arguments are denormalized. The Xobj's must be different from eachother but from the same // locale. The destination must not be not be vacant. - private static void transferChars ( Xobj xFrom, int pFrom, Xobj xTo, int pTo, int cch ) - { + private static void transferChars(Xobj xFrom, int pFrom, Xobj xTo, int pTo, int cch) { assert xFrom != xTo; assert xFrom._locale == xTo._locale; - assert pFrom > 0 && pFrom < xFrom.posMax(); - assert pTo > 0 && pTo <= xTo .posMax(); - assert cch > 0 && cch <= xFrom.cchRight( pFrom ); + assert pFrom > 0 && pFrom < xFrom.posMax(); + assert pTo > 0 && pTo <= xTo.posMax(); + assert cch > 0 && cch <= xFrom.cchRight(pFrom); assert pTo >= xTo.posAfter() || xTo.isOccupied(); // Copy the chars from -> to without performing any invalidations. This will scoot curs @@ -1867,23 +1752,21 @@ final class Cur // exactly be "correct" here. xTo.insertCharsHelper( - pTo, xFrom.getCharsHelper( pFrom, cch ), - xFrom._locale._offSrc, xFrom._locale._cchSrc, false ); + pTo, xFrom.getCharsHelper(pFrom, cch), + xFrom._locale._offSrc, xFrom._locale._cchSrc, false); - xFrom.removeCharsHelper( pFrom, cch, xTo, pTo, true, false ); + xFrom.removeCharsHelper(pFrom, cch, xTo, pTo, true, false); } // Moves the node x to "to", or removes it if to is null. - static void moveNode ( Xobj x, Cur to ) - { + static void moveNode(Xobj x, Cur to) { assert x != null && !x.isRoot(); assert to == null || to.isPositioned(); - assert to == null || !x.contains( to ); + assert to == null || !x.contains(to); assert to == null || !to.isRoot(); - if (to != null) - { + if (to != null) { // Before I go much further, I want to make sure that if "to" is in the container of // a vacant node, I get it occupied. I do not need to worry about the source being // vacant. @@ -1896,11 +1779,10 @@ final class Cur // that I make sure that to gets oved to the beginning of the node. The position of // to in all operations should leave to just before the content moved/inserted. - if ((to._pos == 0 && to._xobj == x) || to.isJustAfterEnd( x )) - { + if ((to._pos == 0 && to._xobj == x) || to.isJustAfterEnd(x)) { // TODO - should shuffle contained curs to the right??? - to.moveTo( x ); + to.moveTo(x); return; } } @@ -1912,8 +1794,7 @@ final class Cur x._locale._versionAll++; x._locale._versionSansText++; - if (to != null && to._locale != x._locale) - { + if (to != null && to._locale != x._locale) { to._locale.notifyChange(); to._locale._versionAll++; @@ -1924,9 +1805,8 @@ final class Cur // Also, this node may be an attribute -- invalidate special attrs ... if (x.isAttr()) - x.invalidateSpecialAttr( to == null ? null : to.getParentRaw() ); - else - { + x.invalidateSpecialAttr(to == null ? null : to.getParentRaw()); + else { if (x._parent != null) x._parent.invalidateUser(); @@ -1941,8 +1821,9 @@ final class Cur // I need to move this text away here so that when I walk the tree next, *all* curs // embedded in this node or deeper will be moved off this node. - if (x._cchAfter > 0) - transferChars( x, x.posAfter(), x.getDenormal( 0 ), x.posTemp(), x._cchAfter ); + if (x._cchAfter > 0) { + transferChars(x, x.posAfter(), x.getDenormal(0), x.posTemp(), x._cchAfter); + } assert x._cchAfter == 0; @@ -1952,15 +1833,16 @@ final class Cur x._locale.embedCurs(); - for ( Xobj y = x ; y != null ; y = y.walk( x, true ) ) - { - while ( y._embedded != null ) - y._embedded.moveTo( x.getNormal( x.posAfter() ) ); + for (Xobj y = x; y != null; y = y.walk(x, true)) { + while (y._embedded != null) { + y._embedded.moveTo(x.getNormal(x.posAfter())); + } y.disconnectUser(); - if (to != null) + if (to != null) { y._locale = to._locale; + } } // Now, actually remove the node @@ -1970,8 +1852,7 @@ final class Cur // Now, if there is a destination, insert the node there and shuffle the text in the // vicinity of the destination appropriately. - if (to != null) - { + if (to != null) { // To know where I should insert/append the node to move, I need to see where "to" // would be if there were no text after it. However, I need to keep "to" where it // is when I move the text after it later. @@ -1981,8 +1862,7 @@ final class Cur int cchRight = to.cchRight(); - if (cchRight > 0) - { + if (cchRight > 0) { to.push(); to.next(); here = to._xobj; @@ -1991,33 +1871,31 @@ final class Cur } if (append) - here.appendXobj( x ); + here.appendXobj(x); else - here.insertXobj( x ); + here.insertXobj(x); // The only text I need to move is that to the right of "to". Even considering all // the cases where an attribute is involed! if (cchRight > 0) - transferChars( to._xobj, to._pos, x, x.posAfter(), cchRight ); + transferChars(to._xobj, to._pos, x, x.posAfter(), cchRight); - to.moveTo( x ); + to.moveTo(x); } } - void moveNodeContents ( Cur to, boolean moveAttrs ) - { - assert _pos==0; + void moveNodeContents(Cur to, boolean moveAttrs) { + assert _pos == 0; assert to == null || !to.isRoot(); // By calling this helper, I do not have to deal with this Cur any longer. Basically, // this Cur is out of the picture, it behaves like any other cur at this point. - moveNodeContents( _xobj, to, moveAttrs ); + moveNodeContents(_xobj, to, moveAttrs); } - static void moveNodeContents ( Xobj x, Cur to, boolean moveAttrs ) - { + static void moveNodeContents(Xobj x, Cur to, boolean moveAttrs) { // TODO - should assert that is an attr is being moved, it is ok there assert to == null || !to.isRoot(); @@ -2030,25 +1908,21 @@ final class Cur // Deal with the cases where only text is involved in the move - if (noSubNodesToMove) - { + if (noSubNodesToMove) { // If we're vacant and there is no place to move a potential value, then I can avoid // acquiring the text from the TypeStoreUser. Otherwise, there may be text here I // need to move somewhere else. - if (x.isVacant() && to == null) - { - x.clearBit( Xobj.VACANT ); + if (x.isVacant() && to == null) { + x.clearBit(Xobj.VACANT); x.invalidateUser(); - x.invalidateSpecialAttr( null ); + x.invalidateSpecialAttr(null); x._locale._versionAll++; - } - else if (x.hasTextEnsureOccupancy()) - { + } else if (x.hasTextEnsureOccupancy()) { Cur c = x.tempCur(); c.next(); - c.moveChars( to, -1 ); + c.moveChars(to, -1); c.release(); } @@ -2058,17 +1932,15 @@ final class Cur // Here I check to see if "to" is just inside x. In this case this is a no-op. Note that // the value of x may still be vacant. - if (to != null) - { + if (to != null) { // Quick check of the right edge. If it is there, I need to move "to" to the left edge // so that it is positioned at the beginning of the "moved" content. - if (x == to._xobj && to._pos == END_POS) - { + if (x == to._xobj && to._pos == END_POS) { // TODO - shuffle interior curs? - to.moveTo( x ); - to.next( moveAttrs && hasAttrs ); + to.moveTo(x); + to.next(moveAttrs && hasAttrs); return; } @@ -2080,11 +1952,10 @@ final class Cur boolean isAtLeftEdge = false; - if (to._locale == x._locale) - { + if (to._locale == x._locale) { to.push(); - to.moveTo( x ); - to.next( moveAttrs && hasAttrs ); + to.moveTo(x); + to.next(moveAttrs && hasAttrs); isAtLeftEdge = to.isAtLastPush(); to.pop(); } @@ -2096,7 +1967,7 @@ final class Cur // Now, after dealing with the edge condition, I can assert that to is not inside x - assert !x.contains( to ); + assert !x.contains(to); // So, at this point, I've taken case of the no-op cases and the movement of just text. // Also, to must be occupied because I took care of the text only and nothing to move @@ -2113,15 +1984,14 @@ final class Cur int valueMovedCch = 0; - if (x.hasTextNoEnsureOccupancy()) - { + if (x.hasTextNoEnsureOccupancy()) { Cur c = x.tempCur(); c.next(); - c.moveChars( to, -1 ); + c.moveChars(to, -1); c.release(); if (to != null) - to.nextChars( valueMovedCch = c._cchSrc ); + to.nextChars(valueMovedCch = c._cchSrc); } // Now, walk all the contents, invalidating special attrs, reportioning cursors, @@ -2130,26 +2000,23 @@ final class Cur x._locale.embedCurs(); - Xobj firstToMove = x.walk( x, true ); + Xobj firstToMove = x.walk(x, true); boolean sawBookmark = false; - for ( Xobj y = firstToMove ; y != null ; y = y.walk( x, true ) ) - { - if (y._parent == x && y.isAttr()) - { + for (Xobj y = firstToMove; y != null; y = y.walk(x, true)) { + if (y._parent == x && y.isAttr()) { assert y._cchAfter == 0; - if (!moveAttrs) - { + if (!moveAttrs) { firstToMove = y._nextSibling; continue; } - y.invalidateSpecialAttr( to == null ? null : to.getParent() ); + y.invalidateSpecialAttr(to == null ? null : to.getParent()); } - for ( Cur c ; (c = y._embedded) != null ; ) - c.moveTo( x, END_POS ); + for (Cur c; (c = y._embedded) != null; ) + c.moveTo(x, END_POS); y.disconnectUser(); @@ -2169,8 +2036,7 @@ final class Cur Cur surragateTo = null; - if (sawBookmark && to == null) - { + if (sawBookmark && to == null) { surragateTo = to = x._locale.tempCur(); to.createRoot(); to.next(); @@ -2186,8 +2052,7 @@ final class Cur x._locale._versionAll++; x._locale._versionSansText++; - if (to != null && valueMovedCch == 0) - { + if (to != null && valueMovedCch == 0) { to.getParent().invalidateUser(); to._locale._versionAll++; to._locale._versionSansText++; @@ -2195,10 +2060,9 @@ final class Cur // Remove the children and, if needed, move them - x.removeXobjs( firstToMove, lastToMove ); + x.removeXobjs(firstToMove, lastToMove); - if (to != null) - { + if (to != null) { // To know where I should insert/append the contents to move, I need to see where "to" // would be if there were no text after it. @@ -2207,8 +2071,7 @@ final class Cur int cchRight = to.cchRight(); - if (cchRight > 0) - { + if (cchRight > 0) { to.push(); to.next(); here = to._xobj; @@ -2227,53 +2090,51 @@ final class Cur // as the containers value text when the last new node being inserted is an attr! // Whew! - if (firstToMove.isAttr()) - { + if (firstToMove.isAttr()) { Xobj lastNewAttr = firstToMove; - while ( lastNewAttr._nextSibling != null && lastNewAttr._nextSibling.isAttr() ) + while (lastNewAttr._nextSibling != null && lastNewAttr._nextSibling.isAttr()) lastNewAttr = lastNewAttr._nextSibling; // Get to's parnet now before I potentially move him with the next transfer Xobj y = to.getParent(); - if (cchRight > 0) - transferChars( to._xobj, to._pos, lastNewAttr, lastNewAttr.posMax(), cchRight ); + if (cchRight > 0) { + transferChars(to._xobj, to._pos, lastNewAttr, lastNewAttr.posMax(), cchRight); + } - if (y.hasTextNoEnsureOccupancy()) - { + if (y.hasTextNoEnsureOccupancy()) { int p, cch; - if (y._cchValue > 0) - { + if (y._cchValue > 0) { p = 1; cch = y._cchValue; - } - else - { + } else { y = y.lastAttr(); + assert(y != null); p = y.posAfter(); cch = y._cchAfter; } - transferChars( y, p, lastNewAttr, lastNewAttr.posAfter(), cch ); + transferChars(y, p, lastNewAttr, lastNewAttr.posAfter(), cch); } + } else if (cchRight > 0) { + transferChars(to._xobj, to._pos, lastToMove, lastToMove.posMax(), cchRight); } - else if (cchRight > 0) - transferChars( to._xobj, to._pos, lastToMove, lastToMove.posMax(), cchRight ); // After mucking with the text, splice the new tree in - if (append) - here.appendXobjs( firstToMove, lastToMove ); - else - here.insertXobjs( firstToMove, lastToMove ); + if (append) { + here.appendXobjs(firstToMove, lastToMove); + } else { + here.insertXobjs(firstToMove, lastToMove); + } // Position "to" to be at the beginning of the newly inserted contents - to.moveTo( firstToMove ); - to.prevChars( valueMovedCch ); + to.moveTo(firstToMove); + to.prevChars(valueMovedCch); } // If I consed up a to, release it here @@ -2282,28 +2143,25 @@ final class Cur surragateTo.release(); } - protected final Bookmark setBookmark ( Object key, Object value ) - { + protected final Bookmark setBookmark(Object key, Object value) { assert isNormal(); assert key != null; - return _xobj.setBookmark( _pos, key, value ); + return _xobj.setBookmark(_pos, key, value); } - Object getBookmark ( Object key ) - { + Object getBookmark(Object key) { assert isNormal(); assert key != null; - for ( Bookmark b = _xobj._bookmarks ; b != null ; b = b._next ) + for (Bookmark b = _xobj._bookmarks; b != null; b = b._next) if (b._pos == _pos && b._key == key) return b._value; return null; } - int firstBookmarkInChars ( Object key, int cch ) - { + int firstBookmarkInChars(Object key, int cch) { assert isNormal(); assert key != null; assert cch > 0; @@ -2311,18 +2169,16 @@ final class Cur int d = -1; - if (isText()) - { - for ( Bookmark b = _xobj._bookmarks ; b != null ; b = b._next ) - if (b._key == key && inChars( b, cch, false )) + if (isText()) { + for (Bookmark b = _xobj._bookmarks; b != null; b = b._next) + if (b._key == key && inChars(b, cch, false)) d = (d == -1 || b._pos - _pos < d) ? b._pos - _pos : d; } return d; } - int firstBookmarkInCharsLeft ( Object key, int cch ) - { + int firstBookmarkInCharsLeft(Object key, int cch) { assert isNormal(); assert key != null; assert cch > 0; @@ -2330,55 +2186,50 @@ final class Cur int d = -1; - if (cchLeft() > 0) - {
[... 1669 lines stripped ...] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
