⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 contextualdiffprovider.java

📁 jspwiki source code,jspwiki source code
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        /** State Machine Mode */        private int m_mode = -1; /* -1: Unset, 0: Add, 1: Del, 2: Change mode */        /** Buffer to coalesce the changes together */        private StringBuffer m_origBuf = null;        private StringBuffer m_newBuf = null;        /** Reference to the source string array */        private String[] m_origStrings = null;        private ChangeMerger( final StringBuffer sb, final String[] origStrings, final int max )        {            m_sb = sb;            m_origStrings = origStrings;            m_max = max;            m_origBuf = new StringBuffer();            m_newBuf = new StringBuffer();        }        private void updateState( Delta delta )        {            m_index++;            Chunk orig = delta.getOriginal();            if (orig.first() > m_firstElem)            {                // We "skip" some lines in the output.                // So flush out the last Change, if one exists.                flushChanges();                // Allow us to "skip" large swaths of unchanged text, show a "limited" amound of                // unchanged context so the changes are shown in                if ((orig.first() - m_firstElem) > 2 * m_unchangedContextLimit)                {                    if (m_firstElem > 0)                    {                        int endIndex = Math.min( m_firstElem + m_unchangedContextLimit, m_origStrings.length -1 );                        for (int j = m_firstElem; j < endIndex; j++)                            m_sb.append(m_origStrings[j]);                        m_sb.append(m_elidedTailIndicatorHtml);                    }                    m_sb.append(m_elidedHeadIndicatorHtml);                    int startIndex = Math.max(orig.first() - m_unchangedContextLimit, 0);                    for (int j = startIndex; j < orig.first(); j++)                        m_sb.append(m_origStrings[j]);                }                else                {                    // No need to skip anything, just output the whole range...                    for (int j = m_firstElem; j < orig.first(); j++)                    m_sb.append( m_origStrings[j] );                }            }            m_firstElem = orig.last() + 1;        }        public void visit( Revision rev )        {            // GNDN (Goes nowhere, does nothing)        }        public void visit( AddDelta delta )        {            updateState( delta );            // We have run Deletes up to now. Flush them out.            if( m_mode == 1 )            {                flushChanges();                m_mode = -1;            }            // We are in "neutral mode". Start a new Change            if( m_mode == -1 )            {                m_mode = 0;            }            // We are in "add mode".            if( m_mode == 0 || m_mode == 2 )            {                addNew( delta.getRevised() );                m_mode = 1;            }        }        public void visit( ChangeDelta delta )        {            updateState( delta );            // We are in "neutral mode". A Change might be merged with an add or delete.            if( m_mode == -1 )            {                m_mode = 2;            }            // Add the Changes to the buffers.            addOrig( delta.getOriginal() );            addNew( delta.getRevised() );        }        public void visit( DeleteDelta delta )        {            updateState( delta );            // We have run Adds up to now. Flush them out.            if( m_mode == 0 )            {                flushChanges();                m_mode = -1;            }            // We are in "neutral mode". Start a new Change            if( m_mode == -1 )            {                m_mode = 1;            }            // We are in "delete mode".            if( m_mode == 1 || m_mode == 2 )            {                addOrig( delta.getOriginal() );                m_mode = 1;            }        }        public void shutdown()        {            m_index = m_max + 1; // Make sure that no hyperlink gets created            flushChanges();            if (m_firstElem < m_origStrings.length)            {                // If there's more than the limit of the orginal left just emit limit and elided...                if ((m_origStrings.length - m_firstElem) > m_unchangedContextLimit)                {                    int endIndex = Math.min( m_firstElem + m_unchangedContextLimit, m_origStrings.length -1 );                    for (int j = m_firstElem; j < endIndex; j++)                    m_sb.append( m_origStrings[j] );                    m_sb.append(m_elidedTailIndicatorHtml);                }                else                // emit entire tail of original...                {                    for (int j = m_firstElem; j < m_origStrings.length; j++)                        m_sb.append(m_origStrings[j]);                }            }        }        private void addOrig( Chunk chunk )        {            if( chunk != null )            {                chunk.toString( m_origBuf );            }        }        private void addNew( Chunk chunk )        {            if( chunk != null )            {                chunk.toString( m_newBuf );            }        }        private void flushChanges()        {            if( m_newBuf.length() + m_origBuf.length() > 0 )            {                // This is the span element which encapsulates anchor and the change itself                m_sb.append( m_changeStartHtml );                // Do we want to have a "back link"?                if( m_emitChangeNextPreviousHyperlinks && m_count > 1 )                {                    m_sb.append( m_backPreIndex );                    m_sb.append( m_count - 1 );                    m_sb.append( m_backPostIndex );                }                // An anchor for the change.                if (m_emitChangeNextPreviousHyperlinks)                {                    m_sb.append( m_anchorPreIndex );                    m_sb.append( m_count++ );                    m_sb.append( m_anchorPostIndex );                }                // ... has been added                if( m_newBuf.length() > 0 )                {                    m_sb.append( m_insertionStartHtml );                    m_sb.append( m_newBuf );                    m_sb.append( m_insertionEndHtml );                }                // .. has been removed                if( m_origBuf.length() > 0 )                {                    m_sb.append( m_deletionStartHtml );                    m_sb.append( m_origBuf );                    m_sb.append( m_deletionEndHtml );                }                // Do we want a "forward" link?                if( m_emitChangeNextPreviousHyperlinks && (m_index < m_max) )                {                    m_sb.append( m_forwardPreIndex );                    m_sb.append( m_count ); // Has already been incremented.                    m_sb.append( m_forwardPostIndex );                }                m_sb.append( m_changeEndHtml );                // Nuke the buffers.                m_origBuf = new StringBuffer();                m_newBuf = new StringBuffer();            }            // After a flush, everything is reset.            m_mode = -1;        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -