commons-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ki...@apache.org
Subject svn commit: r947984 [14/36] - in /websites/production/commons/content/sandbox/commons-text: ./ apidocs/ apidocs/org/apache/commons/text/diff/ apidocs/org/apache/commons/text/diff/class-use/ apidocs/org/apache/commons/text/names/ apidocs/org/apache/comm...
Date Fri, 17 Apr 2015 06:46:32 GMT
Modified: websites/production/commons/content/sandbox/commons-text/apidocs/src-html/org/apache/commons/text/diff/StringsComparator.html
==============================================================================
--- websites/production/commons/content/sandbox/commons-text/apidocs/src-html/org/apache/commons/text/diff/StringsComparator.html (original)
+++ websites/production/commons/content/sandbox/commons-text/apidocs/src-html/org/apache/commons/text/diff/StringsComparator.html Fri Apr 17 06:46:28 2015
@@ -1,5 +1,5 @@
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-<html lang="de">
+<html lang="en">
 <head>
 <title>Source code</title>
 <link rel="stylesheet" type="text/css" href="../../../../../../stylesheet.css" title="Style">
@@ -69,271 +69,275 @@
 <span class="sourceLineNo">061</span>     * Second character sequence.<a name="line.61"></a>
 <span class="sourceLineNo">062</span>     */<a name="line.62"></a>
 <span class="sourceLineNo">063</span>    private final String right;<a name="line.63"></a>
-<span class="sourceLineNo">064</span><a name="line.64"></a>
-<span class="sourceLineNo">065</span>    /** Temporary variables. */<a name="line.65"></a>
-<span class="sourceLineNo">066</span>    private final int[] vDown;<a name="line.66"></a>
-<span class="sourceLineNo">067</span>    private final int[] vUp;<a name="line.67"></a>
-<span class="sourceLineNo">068</span><a name="line.68"></a>
-<span class="sourceLineNo">069</span>    /**<a name="line.69"></a>
-<span class="sourceLineNo">070</span>     * Simple constructor.<a name="line.70"></a>
-<span class="sourceLineNo">071</span>     * &lt;p&gt;<a name="line.71"></a>
-<span class="sourceLineNo">072</span>     * Creates a new instance of StringsComparator.<a name="line.72"></a>
-<span class="sourceLineNo">073</span>     * &lt;/p&gt;<a name="line.73"></a>
-<span class="sourceLineNo">074</span>     * &lt;p&gt;<a name="line.74"></a>
-<span class="sourceLineNo">075</span>     * It is &lt;em&gt;guaranteed&lt;/em&gt; that the comparisons will always be done as<a name="line.75"></a>
-<span class="sourceLineNo">076</span>     * &lt;code&gt;o1.equals(o2)&lt;/code&gt; where &lt;code&gt;o1&lt;/code&gt; belongs to the first<a name="line.76"></a>
-<span class="sourceLineNo">077</span>     * sequence and &lt;code&gt;o2&lt;/code&gt; belongs to the second sequence. This can be<a name="line.77"></a>
-<span class="sourceLineNo">078</span>     * important if subclassing is used for some elements in the first sequence<a name="line.78"></a>
-<span class="sourceLineNo">079</span>     * and the &lt;code&gt;equals&lt;/code&gt; method is specialized.<a name="line.79"></a>
-<span class="sourceLineNo">080</span>     * &lt;/p&gt;<a name="line.80"></a>
-<span class="sourceLineNo">081</span>     *<a name="line.81"></a>
-<span class="sourceLineNo">082</span>     * @param left first character sequence to be compared<a name="line.82"></a>
-<span class="sourceLineNo">083</span>     * @param right second character sequence to be compared<a name="line.83"></a>
-<span class="sourceLineNo">084</span>     */<a name="line.84"></a>
-<span class="sourceLineNo">085</span>    public StringsComparator(String left, String right) {<a name="line.85"></a>
-<span class="sourceLineNo">086</span>        this.left = left;<a name="line.86"></a>
-<span class="sourceLineNo">087</span>        this.right = right;<a name="line.87"></a>
-<span class="sourceLineNo">088</span><a name="line.88"></a>
-<span class="sourceLineNo">089</span>        final int size = left.length() + right.length() + 2;<a name="line.89"></a>
-<span class="sourceLineNo">090</span>        vDown = new int[size];<a name="line.90"></a>
-<span class="sourceLineNo">091</span>        vUp   = new int[size];<a name="line.91"></a>
-<span class="sourceLineNo">092</span>    }<a name="line.92"></a>
-<span class="sourceLineNo">093</span><a name="line.93"></a>
-<span class="sourceLineNo">094</span>    /**<a name="line.94"></a>
-<span class="sourceLineNo">095</span>     * Get the {@link EditScript} object.<a name="line.95"></a>
-<span class="sourceLineNo">096</span>     * &lt;p&gt;<a name="line.96"></a>
-<span class="sourceLineNo">097</span>     * It is guaranteed that the objects embedded in the {@link InsertCommand<a name="line.97"></a>
-<span class="sourceLineNo">098</span>     * insert commands} come from the second sequence and that the objects<a name="line.98"></a>
-<span class="sourceLineNo">099</span>     * embedded in either the {@link DeleteCommand delete commands} or<a name="line.99"></a>
-<span class="sourceLineNo">100</span>     * {@link KeepCommand keep commands} come from the first sequence. This can<a name="line.100"></a>
-<span class="sourceLineNo">101</span>     * be important if subclassing is used for some elements in the first<a name="line.101"></a>
-<span class="sourceLineNo">102</span>     * sequence and the &lt;code&gt;equals&lt;/code&gt; method is specialized.<a name="line.102"></a>
-<span class="sourceLineNo">103</span>     * &lt;/p&gt;<a name="line.103"></a>
-<span class="sourceLineNo">104</span>     *<a name="line.104"></a>
-<span class="sourceLineNo">105</span>     * @return the edit script resulting from the comparison of the two<a name="line.105"></a>
-<span class="sourceLineNo">106</span>     *         sequences<a name="line.106"></a>
-<span class="sourceLineNo">107</span>     */<a name="line.107"></a>
-<span class="sourceLineNo">108</span>    public EditScript&lt;Character&gt; getScript() {<a name="line.108"></a>
-<span class="sourceLineNo">109</span>        final EditScript&lt;Character&gt; script = new EditScript&lt;Character&gt;();<a name="line.109"></a>
-<span class="sourceLineNo">110</span>        buildScript(0, left.length(), 0, right.length(), script);<a name="line.110"></a>
-<span class="sourceLineNo">111</span>        return script;<a name="line.111"></a>
-<span class="sourceLineNo">112</span>    }<a name="line.112"></a>
-<span class="sourceLineNo">113</span><a name="line.113"></a>
-<span class="sourceLineNo">114</span>    /**<a name="line.114"></a>
-<span class="sourceLineNo">115</span>     * Build an edit script.<a name="line.115"></a>
-<span class="sourceLineNo">116</span>     *<a name="line.116"></a>
-<span class="sourceLineNo">117</span>     * @param start1  the begin of the first sequence to be compared<a name="line.117"></a>
-<span class="sourceLineNo">118</span>     * @param end1  the end of the first sequence to be compared<a name="line.118"></a>
-<span class="sourceLineNo">119</span>     * @param start2  the begin of the second sequence to be compared<a name="line.119"></a>
-<span class="sourceLineNo">120</span>     * @param end2  the end of the second sequence to be compared<a name="line.120"></a>
-<span class="sourceLineNo">121</span>     * @param script the edited script<a name="line.121"></a>
-<span class="sourceLineNo">122</span>     */<a name="line.122"></a>
-<span class="sourceLineNo">123</span>    private void buildScript(final int start1, final int end1, final int start2, final int end2,<a name="line.123"></a>
-<span class="sourceLineNo">124</span>            final EditScript&lt;Character&gt; script) {<a name="line.124"></a>
-<span class="sourceLineNo">125</span>        final Snake middle = getMiddleSnake(start1, end1, start2, end2);<a name="line.125"></a>
-<span class="sourceLineNo">126</span><a name="line.126"></a>
-<span class="sourceLineNo">127</span>        if (middle == null<a name="line.127"></a>
-<span class="sourceLineNo">128</span>                || middle.getStart() == end1 &amp;&amp; middle.getDiag() == end1 - end2<a name="line.128"></a>
-<span class="sourceLineNo">129</span>                || middle.getEnd() == start1 &amp;&amp; middle.getDiag() == start1 - start2) {<a name="line.129"></a>
+<span class="sourceLineNo">064</span>    /**<a name="line.64"></a>
+<span class="sourceLineNo">065</span>     * Temporary array.<a name="line.65"></a>
+<span class="sourceLineNo">066</span>     */<a name="line.66"></a>
+<span class="sourceLineNo">067</span>    private final int[] vDown;<a name="line.67"></a>
+<span class="sourceLineNo">068</span>    /**<a name="line.68"></a>
+<span class="sourceLineNo">069</span>     * Temporary array.<a name="line.69"></a>
+<span class="sourceLineNo">070</span>     */<a name="line.70"></a>
+<span class="sourceLineNo">071</span>    private final int[] vUp;<a name="line.71"></a>
+<span class="sourceLineNo">072</span><a name="line.72"></a>
+<span class="sourceLineNo">073</span>    /**<a name="line.73"></a>
+<span class="sourceLineNo">074</span>     * Simple constructor.<a name="line.74"></a>
+<span class="sourceLineNo">075</span>     * &lt;p&gt;<a name="line.75"></a>
+<span class="sourceLineNo">076</span>     * Creates a new instance of StringsComparator.<a name="line.76"></a>
+<span class="sourceLineNo">077</span>     * &lt;/p&gt;<a name="line.77"></a>
+<span class="sourceLineNo">078</span>     * &lt;p&gt;<a name="line.78"></a>
+<span class="sourceLineNo">079</span>     * It is &lt;em&gt;guaranteed&lt;/em&gt; that the comparisons will always be done as<a name="line.79"></a>
+<span class="sourceLineNo">080</span>     * &lt;code&gt;o1.equals(o2)&lt;/code&gt; where &lt;code&gt;o1&lt;/code&gt; belongs to the first<a name="line.80"></a>
+<span class="sourceLineNo">081</span>     * sequence and &lt;code&gt;o2&lt;/code&gt; belongs to the second sequence. This can be<a name="line.81"></a>
+<span class="sourceLineNo">082</span>     * important if subclassing is used for some elements in the first sequence<a name="line.82"></a>
+<span class="sourceLineNo">083</span>     * and the &lt;code&gt;equals&lt;/code&gt; method is specialized.<a name="line.83"></a>
+<span class="sourceLineNo">084</span>     * &lt;/p&gt;<a name="line.84"></a>
+<span class="sourceLineNo">085</span>     *<a name="line.85"></a>
+<span class="sourceLineNo">086</span>     * @param left first character sequence to be compared<a name="line.86"></a>
+<span class="sourceLineNo">087</span>     * @param right second character sequence to be compared<a name="line.87"></a>
+<span class="sourceLineNo">088</span>     */<a name="line.88"></a>
+<span class="sourceLineNo">089</span>    public StringsComparator(String left, String right) {<a name="line.89"></a>
+<span class="sourceLineNo">090</span>        this.left = left;<a name="line.90"></a>
+<span class="sourceLineNo">091</span>        this.right = right;<a name="line.91"></a>
+<span class="sourceLineNo">092</span><a name="line.92"></a>
+<span class="sourceLineNo">093</span>        final int size = left.length() + right.length() + 2;<a name="line.93"></a>
+<span class="sourceLineNo">094</span>        vDown = new int[size];<a name="line.94"></a>
+<span class="sourceLineNo">095</span>        vUp   = new int[size];<a name="line.95"></a>
+<span class="sourceLineNo">096</span>    }<a name="line.96"></a>
+<span class="sourceLineNo">097</span><a name="line.97"></a>
+<span class="sourceLineNo">098</span>    /**<a name="line.98"></a>
+<span class="sourceLineNo">099</span>     * Get the {@link EditScript} object.<a name="line.99"></a>
+<span class="sourceLineNo">100</span>     * &lt;p&gt;<a name="line.100"></a>
+<span class="sourceLineNo">101</span>     * It is guaranteed that the objects embedded in the {@link InsertCommand<a name="line.101"></a>
+<span class="sourceLineNo">102</span>     * insert commands} come from the second sequence and that the objects<a name="line.102"></a>
+<span class="sourceLineNo">103</span>     * embedded in either the {@link DeleteCommand delete commands} or<a name="line.103"></a>
+<span class="sourceLineNo">104</span>     * {@link KeepCommand keep commands} come from the first sequence. This can<a name="line.104"></a>
+<span class="sourceLineNo">105</span>     * be important if subclassing is used for some elements in the first<a name="line.105"></a>
+<span class="sourceLineNo">106</span>     * sequence and the &lt;code&gt;equals&lt;/code&gt; method is specialized.<a name="line.106"></a>
+<span class="sourceLineNo">107</span>     * &lt;/p&gt;<a name="line.107"></a>
+<span class="sourceLineNo">108</span>     *<a name="line.108"></a>
+<span class="sourceLineNo">109</span>     * @return the edit script resulting from the comparison of the two<a name="line.109"></a>
+<span class="sourceLineNo">110</span>     *         sequences<a name="line.110"></a>
+<span class="sourceLineNo">111</span>     */<a name="line.111"></a>
+<span class="sourceLineNo">112</span>    public EditScript&lt;Character&gt; getScript() {<a name="line.112"></a>
+<span class="sourceLineNo">113</span>        final EditScript&lt;Character&gt; script = new EditScript&lt;Character&gt;();<a name="line.113"></a>
+<span class="sourceLineNo">114</span>        buildScript(0, left.length(), 0, right.length(), script);<a name="line.114"></a>
+<span class="sourceLineNo">115</span>        return script;<a name="line.115"></a>
+<span class="sourceLineNo">116</span>    }<a name="line.116"></a>
+<span class="sourceLineNo">117</span><a name="line.117"></a>
+<span class="sourceLineNo">118</span>    /**<a name="line.118"></a>
+<span class="sourceLineNo">119</span>     * Build an edit script.<a name="line.119"></a>
+<span class="sourceLineNo">120</span>     *<a name="line.120"></a>
+<span class="sourceLineNo">121</span>     * @param start1  the begin of the first sequence to be compared<a name="line.121"></a>
+<span class="sourceLineNo">122</span>     * @param end1  the end of the first sequence to be compared<a name="line.122"></a>
+<span class="sourceLineNo">123</span>     * @param start2  the begin of the second sequence to be compared<a name="line.123"></a>
+<span class="sourceLineNo">124</span>     * @param end2  the end of the second sequence to be compared<a name="line.124"></a>
+<span class="sourceLineNo">125</span>     * @param script the edited script<a name="line.125"></a>
+<span class="sourceLineNo">126</span>     */<a name="line.126"></a>
+<span class="sourceLineNo">127</span>    private void buildScript(final int start1, final int end1, final int start2, final int end2,<a name="line.127"></a>
+<span class="sourceLineNo">128</span>            final EditScript&lt;Character&gt; script) {<a name="line.128"></a>
+<span class="sourceLineNo">129</span>        final Snake middle = getMiddleSnake(start1, end1, start2, end2);<a name="line.129"></a>
 <span class="sourceLineNo">130</span><a name="line.130"></a>
-<span class="sourceLineNo">131</span>            int i = start1;<a name="line.131"></a>
-<span class="sourceLineNo">132</span>            int j = start2;<a name="line.132"></a>
-<span class="sourceLineNo">133</span>            while (i &lt; end1 || j &lt; end2) {<a name="line.133"></a>
-<span class="sourceLineNo">134</span>                if (i &lt; end1 &amp;&amp; j &lt; end2 &amp;&amp; left.charAt(i) == right.charAt(j)) {<a name="line.134"></a>
-<span class="sourceLineNo">135</span>                    script.append(new KeepCommand&lt;Character&gt;(left.charAt(i)));<a name="line.135"></a>
-<span class="sourceLineNo">136</span>                    ++i;<a name="line.136"></a>
-<span class="sourceLineNo">137</span>                    ++j;<a name="line.137"></a>
-<span class="sourceLineNo">138</span>                } else {<a name="line.138"></a>
-<span class="sourceLineNo">139</span>                    if (end1 - start1 &gt; end2 - start2) {<a name="line.139"></a>
-<span class="sourceLineNo">140</span>                        script.append(new DeleteCommand&lt;Character&gt;(left.charAt(i)));<a name="line.140"></a>
-<span class="sourceLineNo">141</span>                        ++i;<a name="line.141"></a>
-<span class="sourceLineNo">142</span>                    } else {<a name="line.142"></a>
-<span class="sourceLineNo">143</span>                        script.append(new InsertCommand&lt;Character&gt;(right.charAt(j)));<a name="line.143"></a>
-<span class="sourceLineNo">144</span>                        ++j;<a name="line.144"></a>
-<span class="sourceLineNo">145</span>                    }<a name="line.145"></a>
-<span class="sourceLineNo">146</span>                }<a name="line.146"></a>
-<span class="sourceLineNo">147</span>            }<a name="line.147"></a>
-<span class="sourceLineNo">148</span><a name="line.148"></a>
-<span class="sourceLineNo">149</span>        } else {<a name="line.149"></a>
-<span class="sourceLineNo">150</span><a name="line.150"></a>
-<span class="sourceLineNo">151</span>            buildScript(start1, middle.getStart(),<a name="line.151"></a>
-<span class="sourceLineNo">152</span>                        start2, middle.getStart() - middle.getDiag(),<a name="line.152"></a>
-<span class="sourceLineNo">153</span>                        script);<a name="line.153"></a>
-<span class="sourceLineNo">154</span>            for (int i = middle.getStart(); i &lt; middle.getEnd(); ++i) {<a name="line.154"></a>
-<span class="sourceLineNo">155</span>                script.append(new KeepCommand&lt;Character&gt;(left.charAt(i)));<a name="line.155"></a>
-<span class="sourceLineNo">156</span>            }<a name="line.156"></a>
-<span class="sourceLineNo">157</span>            buildScript(middle.getEnd(), end1,<a name="line.157"></a>
-<span class="sourceLineNo">158</span>                        middle.getEnd() - middle.getDiag(), end2,<a name="line.158"></a>
-<span class="sourceLineNo">159</span>                        script);<a name="line.159"></a>
-<span class="sourceLineNo">160</span>        }<a name="line.160"></a>
-<span class="sourceLineNo">161</span>    }<a name="line.161"></a>
-<span class="sourceLineNo">162</span><a name="line.162"></a>
-<span class="sourceLineNo">163</span>    /**<a name="line.163"></a>
-<span class="sourceLineNo">164</span>     * Get the middle snake corresponding to two subsequences of the<a name="line.164"></a>
-<span class="sourceLineNo">165</span>     * main sequences.<a name="line.165"></a>
-<span class="sourceLineNo">166</span>     * &lt;p&gt;<a name="line.166"></a>
-<span class="sourceLineNo">167</span>     * The snake is found using the MYERS Algorithm (this algorithms has<a name="line.167"></a>
-<span class="sourceLineNo">168</span>     * also been implemented in the GNU diff program). This algorithm is<a name="line.168"></a>
-<span class="sourceLineNo">169</span>     * explained in Eugene Myers article:<a name="line.169"></a>
-<span class="sourceLineNo">170</span>     * &lt;a href="http://www.cs.arizona.edu/people/gene/PAPERS/diff.ps"&gt;<a name="line.170"></a>
-<span class="sourceLineNo">171</span>     * An O(ND) Difference Algorithm and Its Variations&lt;/a&gt;.<a name="line.171"></a>
-<span class="sourceLineNo">172</span>     * &lt;/p&gt;<a name="line.172"></a>
-<span class="sourceLineNo">173</span>     *<a name="line.173"></a>
-<span class="sourceLineNo">174</span>     * @param start1  the begin of the first sequence to be compared<a name="line.174"></a>
-<span class="sourceLineNo">175</span>     * @param end1  the end of the first sequence to be compared<a name="line.175"></a>
-<span class="sourceLineNo">176</span>     * @param start2  the begin of the second sequence to be compared<a name="line.176"></a>
-<span class="sourceLineNo">177</span>     * @param end2  the end of the second sequence to be compared<a name="line.177"></a>
-<span class="sourceLineNo">178</span>     * @return the middle snake<a name="line.178"></a>
-<span class="sourceLineNo">179</span>     */<a name="line.179"></a>
-<span class="sourceLineNo">180</span>    private Snake getMiddleSnake(int start1, int end1, int start2, int end2) {<a name="line.180"></a>
-<span class="sourceLineNo">181</span>        // Myers Algorithm<a name="line.181"></a>
-<span class="sourceLineNo">182</span>        // Initialisations<a name="line.182"></a>
-<span class="sourceLineNo">183</span>        final int m = end1 - start1;<a name="line.183"></a>
-<span class="sourceLineNo">184</span>        final int n = end2 - start2;<a name="line.184"></a>
-<span class="sourceLineNo">185</span>        if (m == 0 || n == 0) {<a name="line.185"></a>
-<span class="sourceLineNo">186</span>            return null;<a name="line.186"></a>
-<span class="sourceLineNo">187</span>        }<a name="line.187"></a>
-<span class="sourceLineNo">188</span><a name="line.188"></a>
-<span class="sourceLineNo">189</span>        final int delta  = m - n;<a name="line.189"></a>
-<span class="sourceLineNo">190</span>        final int sum    = n + m;<a name="line.190"></a>
-<span class="sourceLineNo">191</span>        final int offset = (sum % 2 == 0 ? sum : sum + 1) / 2;<a name="line.191"></a>
-<span class="sourceLineNo">192</span>        vDown[1+offset] = start1;<a name="line.192"></a>
-<span class="sourceLineNo">193</span>        vUp[1+offset]   = end1 + 1;<a name="line.193"></a>
-<span class="sourceLineNo">194</span><a name="line.194"></a>
-<span class="sourceLineNo">195</span>        for (int d = 0; d &lt;= offset ; ++d) {<a name="line.195"></a>
-<span class="sourceLineNo">196</span>            // Down<a name="line.196"></a>
-<span class="sourceLineNo">197</span>            for (int k = -d; k &lt;= d; k += 2) {<a name="line.197"></a>
-<span class="sourceLineNo">198</span>                // First step<a name="line.198"></a>
-<span class="sourceLineNo">199</span><a name="line.199"></a>
-<span class="sourceLineNo">200</span>                final int i = k + offset;<a name="line.200"></a>
-<span class="sourceLineNo">201</span>                if (k == -d || k != d &amp;&amp; vDown[i-1] &lt; vDown[i+1]) {<a name="line.201"></a>
-<span class="sourceLineNo">202</span>                    vDown[i] = vDown[i+1];<a name="line.202"></a>
-<span class="sourceLineNo">203</span>                } else {<a name="line.203"></a>
-<span class="sourceLineNo">204</span>                    vDown[i] = vDown[i-1] + 1;<a name="line.204"></a>
-<span class="sourceLineNo">205</span>                }<a name="line.205"></a>
-<span class="sourceLineNo">206</span><a name="line.206"></a>
-<span class="sourceLineNo">207</span>                int x = vDown[i];<a name="line.207"></a>
-<span class="sourceLineNo">208</span>                int y = x - start1 + start2 - k;<a name="line.208"></a>
-<span class="sourceLineNo">209</span><a name="line.209"></a>
-<span class="sourceLineNo">210</span>                while (x &lt; end1 &amp;&amp; y &lt; end2 &amp;&amp; left.charAt(x) == right.charAt(y)) {<a name="line.210"></a>
-<span class="sourceLineNo">211</span>                    vDown[i] = ++x;<a name="line.211"></a>
-<span class="sourceLineNo">212</span>                    ++y;<a name="line.212"></a>
-<span class="sourceLineNo">213</span>                }<a name="line.213"></a>
-<span class="sourceLineNo">214</span>                // Second step<a name="line.214"></a>
-<span class="sourceLineNo">215</span>                if (delta % 2 != 0 &amp;&amp; delta - d &lt;= k &amp;&amp; k &lt;= delta + d) {<a name="line.215"></a>
-<span class="sourceLineNo">216</span>                    if (vUp[i-delta] &lt;= vDown[i]) {<a name="line.216"></a>
-<span class="sourceLineNo">217</span>                        return buildSnake(vUp[i-delta], k + start1 - start2, end1, end2);<a name="line.217"></a>
-<span class="sourceLineNo">218</span>                    }<a name="line.218"></a>
-<span class="sourceLineNo">219</span>                }<a name="line.219"></a>
-<span class="sourceLineNo">220</span>            }<a name="line.220"></a>
-<span class="sourceLineNo">221</span><a name="line.221"></a>
-<span class="sourceLineNo">222</span>            // Up<a name="line.222"></a>
-<span class="sourceLineNo">223</span>            for (int k = delta - d; k &lt;= delta + d; k += 2) {<a name="line.223"></a>
-<span class="sourceLineNo">224</span>                // First step<a name="line.224"></a>
-<span class="sourceLineNo">225</span>                final int i = k + offset - delta;<a name="line.225"></a>
-<span class="sourceLineNo">226</span>                if (k == delta - d<a name="line.226"></a>
-<span class="sourceLineNo">227</span>                        || k != delta + d &amp;&amp; vUp[i+1] &lt;= vUp[i-1]) {<a name="line.227"></a>
-<span class="sourceLineNo">228</span>                    vUp[i] = vUp[i+1] - 1;<a name="line.228"></a>
-<span class="sourceLineNo">229</span>                } else {<a name="line.229"></a>
-<span class="sourceLineNo">230</span>                    vUp[i] = vUp[i-1];<a name="line.230"></a>
-<span class="sourceLineNo">231</span>                }<a name="line.231"></a>
-<span class="sourceLineNo">232</span><a name="line.232"></a>
-<span class="sourceLineNo">233</span>                int x = vUp[i] - 1;<a name="line.233"></a>
-<span class="sourceLineNo">234</span>                int y = x - start1 + start2 - k;<a name="line.234"></a>
-<span class="sourceLineNo">235</span>                while (x &gt;= start1 &amp;&amp; y &gt;= start2<a name="line.235"></a>
-<span class="sourceLineNo">236</span>                        &amp;&amp; left.charAt(x) == right.charAt(y)) {<a name="line.236"></a>
-<span class="sourceLineNo">237</span>                    vUp[i] = x--;<a name="line.237"></a>
-<span class="sourceLineNo">238</span>                    y--;<a name="line.238"></a>
-<span class="sourceLineNo">239</span>                }<a name="line.239"></a>
-<span class="sourceLineNo">240</span>                // Second step<a name="line.240"></a>
-<span class="sourceLineNo">241</span>                if (delta % 2 == 0 &amp;&amp; -d &lt;= k &amp;&amp; k &lt;= d ) {<a name="line.241"></a>
-<span class="sourceLineNo">242</span>                    if (vUp[i] &lt;= vDown[i + delta]) {<a name="line.242"></a>
-<span class="sourceLineNo">243</span>                        return buildSnake(vUp[i], k + start1 - start2, end1, end2);<a name="line.243"></a>
-<span class="sourceLineNo">244</span>                    }<a name="line.244"></a>
-<span class="sourceLineNo">245</span>                }<a name="line.245"></a>
-<span class="sourceLineNo">246</span>            }<a name="line.246"></a>
-<span class="sourceLineNo">247</span>        }<a name="line.247"></a>
-<span class="sourceLineNo">248</span><a name="line.248"></a>
-<span class="sourceLineNo">249</span>        // this should not happen<a name="line.249"></a>
-<span class="sourceLineNo">250</span>        throw new RuntimeException("Internal Error");<a name="line.250"></a>
-<span class="sourceLineNo">251</span>    }<a name="line.251"></a>
+<span class="sourceLineNo">131</span>        if (middle == null<a name="line.131"></a>
+<span class="sourceLineNo">132</span>                || middle.getStart() == end1 &amp;&amp; middle.getDiag() == end1 - end2<a name="line.132"></a>
+<span class="sourceLineNo">133</span>                || middle.getEnd() == start1 &amp;&amp; middle.getDiag() == start1 - start2) {<a name="line.133"></a>
+<span class="sourceLineNo">134</span><a name="line.134"></a>
+<span class="sourceLineNo">135</span>            int i = start1;<a name="line.135"></a>
+<span class="sourceLineNo">136</span>            int j = start2;<a name="line.136"></a>
+<span class="sourceLineNo">137</span>            while (i &lt; end1 || j &lt; end2) {<a name="line.137"></a>
+<span class="sourceLineNo">138</span>                if (i &lt; end1 &amp;&amp; j &lt; end2 &amp;&amp; left.charAt(i) == right.charAt(j)) {<a name="line.138"></a>
+<span class="sourceLineNo">139</span>                    script.append(new KeepCommand&lt;Character&gt;(left.charAt(i)));<a name="line.139"></a>
+<span class="sourceLineNo">140</span>                    ++i;<a name="line.140"></a>
+<span class="sourceLineNo">141</span>                    ++j;<a name="line.141"></a>
+<span class="sourceLineNo">142</span>                } else {<a name="line.142"></a>
+<span class="sourceLineNo">143</span>                    if (end1 - start1 &gt; end2 - start2) {<a name="line.143"></a>
+<span class="sourceLineNo">144</span>                        script.append(new DeleteCommand&lt;Character&gt;(left.charAt(i)));<a name="line.144"></a>
+<span class="sourceLineNo">145</span>                        ++i;<a name="line.145"></a>
+<span class="sourceLineNo">146</span>                    } else {<a name="line.146"></a>
+<span class="sourceLineNo">147</span>                        script.append(new InsertCommand&lt;Character&gt;(right.charAt(j)));<a name="line.147"></a>
+<span class="sourceLineNo">148</span>                        ++j;<a name="line.148"></a>
+<span class="sourceLineNo">149</span>                    }<a name="line.149"></a>
+<span class="sourceLineNo">150</span>                }<a name="line.150"></a>
+<span class="sourceLineNo">151</span>            }<a name="line.151"></a>
+<span class="sourceLineNo">152</span><a name="line.152"></a>
+<span class="sourceLineNo">153</span>        } else {<a name="line.153"></a>
+<span class="sourceLineNo">154</span><a name="line.154"></a>
+<span class="sourceLineNo">155</span>            buildScript(start1, middle.getStart(),<a name="line.155"></a>
+<span class="sourceLineNo">156</span>                        start2, middle.getStart() - middle.getDiag(),<a name="line.156"></a>
+<span class="sourceLineNo">157</span>                        script);<a name="line.157"></a>
+<span class="sourceLineNo">158</span>            for (int i = middle.getStart(); i &lt; middle.getEnd(); ++i) {<a name="line.158"></a>
+<span class="sourceLineNo">159</span>                script.append(new KeepCommand&lt;Character&gt;(left.charAt(i)));<a name="line.159"></a>
+<span class="sourceLineNo">160</span>            }<a name="line.160"></a>
+<span class="sourceLineNo">161</span>            buildScript(middle.getEnd(), end1,<a name="line.161"></a>
+<span class="sourceLineNo">162</span>                        middle.getEnd() - middle.getDiag(), end2,<a name="line.162"></a>
+<span class="sourceLineNo">163</span>                        script);<a name="line.163"></a>
+<span class="sourceLineNo">164</span>        }<a name="line.164"></a>
+<span class="sourceLineNo">165</span>    }<a name="line.165"></a>
+<span class="sourceLineNo">166</span><a name="line.166"></a>
+<span class="sourceLineNo">167</span>    /**<a name="line.167"></a>
+<span class="sourceLineNo">168</span>     * Get the middle snake corresponding to two subsequences of the<a name="line.168"></a>
+<span class="sourceLineNo">169</span>     * main sequences.<a name="line.169"></a>
+<span class="sourceLineNo">170</span>     * &lt;p&gt;<a name="line.170"></a>
+<span class="sourceLineNo">171</span>     * The snake is found using the MYERS Algorithm (this algorithms has<a name="line.171"></a>
+<span class="sourceLineNo">172</span>     * also been implemented in the GNU diff program). This algorithm is<a name="line.172"></a>
+<span class="sourceLineNo">173</span>     * explained in Eugene Myers article:<a name="line.173"></a>
+<span class="sourceLineNo">174</span>     * &lt;a href="http://www.cs.arizona.edu/people/gene/PAPERS/diff.ps"&gt;<a name="line.174"></a>
+<span class="sourceLineNo">175</span>     * An O(ND) Difference Algorithm and Its Variations&lt;/a&gt;.<a name="line.175"></a>
+<span class="sourceLineNo">176</span>     * &lt;/p&gt;<a name="line.176"></a>
+<span class="sourceLineNo">177</span>     *<a name="line.177"></a>
+<span class="sourceLineNo">178</span>     * @param start1  the begin of the first sequence to be compared<a name="line.178"></a>
+<span class="sourceLineNo">179</span>     * @param end1  the end of the first sequence to be compared<a name="line.179"></a>
+<span class="sourceLineNo">180</span>     * @param start2  the begin of the second sequence to be compared<a name="line.180"></a>
+<span class="sourceLineNo">181</span>     * @param end2  the end of the second sequence to be compared<a name="line.181"></a>
+<span class="sourceLineNo">182</span>     * @return the middle snake<a name="line.182"></a>
+<span class="sourceLineNo">183</span>     */<a name="line.183"></a>
+<span class="sourceLineNo">184</span>    private Snake getMiddleSnake(int start1, int end1, int start2, int end2) {<a name="line.184"></a>
+<span class="sourceLineNo">185</span>        // Myers Algorithm<a name="line.185"></a>
+<span class="sourceLineNo">186</span>        // Initialisations<a name="line.186"></a>
+<span class="sourceLineNo">187</span>        final int m = end1 - start1;<a name="line.187"></a>
+<span class="sourceLineNo">188</span>        final int n = end2 - start2;<a name="line.188"></a>
+<span class="sourceLineNo">189</span>        if (m == 0 || n == 0) {<a name="line.189"></a>
+<span class="sourceLineNo">190</span>            return null;<a name="line.190"></a>
+<span class="sourceLineNo">191</span>        }<a name="line.191"></a>
+<span class="sourceLineNo">192</span><a name="line.192"></a>
+<span class="sourceLineNo">193</span>        final int delta  = m - n;<a name="line.193"></a>
+<span class="sourceLineNo">194</span>        final int sum    = n + m;<a name="line.194"></a>
+<span class="sourceLineNo">195</span>        final int offset = (sum % 2 == 0 ? sum : sum + 1) / 2;<a name="line.195"></a>
+<span class="sourceLineNo">196</span>        vDown[1 + offset] = start1;<a name="line.196"></a>
+<span class="sourceLineNo">197</span>        vUp[1 + offset]   = end1 + 1;<a name="line.197"></a>
+<span class="sourceLineNo">198</span><a name="line.198"></a>
+<span class="sourceLineNo">199</span>        for (int d = 0; d &lt;= offset; ++d) {<a name="line.199"></a>
+<span class="sourceLineNo">200</span>            // Down<a name="line.200"></a>
+<span class="sourceLineNo">201</span>            for (int k = -d; k &lt;= d; k += 2) {<a name="line.201"></a>
+<span class="sourceLineNo">202</span>                // First step<a name="line.202"></a>
+<span class="sourceLineNo">203</span><a name="line.203"></a>
+<span class="sourceLineNo">204</span>                final int i = k + offset;<a name="line.204"></a>
+<span class="sourceLineNo">205</span>                if (k == -d || k != d &amp;&amp; vDown[i - 1] &lt; vDown[i + 1]) {<a name="line.205"></a>
+<span class="sourceLineNo">206</span>                    vDown[i] = vDown[i + 1];<a name="line.206"></a>
+<span class="sourceLineNo">207</span>                } else {<a name="line.207"></a>
+<span class="sourceLineNo">208</span>                    vDown[i] = vDown[i - 1] + 1;<a name="line.208"></a>
+<span class="sourceLineNo">209</span>                }<a name="line.209"></a>
+<span class="sourceLineNo">210</span><a name="line.210"></a>
+<span class="sourceLineNo">211</span>                int x = vDown[i];<a name="line.211"></a>
+<span class="sourceLineNo">212</span>                int y = x - start1 + start2 - k;<a name="line.212"></a>
+<span class="sourceLineNo">213</span><a name="line.213"></a>
+<span class="sourceLineNo">214</span>                while (x &lt; end1 &amp;&amp; y &lt; end2 &amp;&amp; left.charAt(x) == right.charAt(y)) {<a name="line.214"></a>
+<span class="sourceLineNo">215</span>                    vDown[i] = ++x;<a name="line.215"></a>
+<span class="sourceLineNo">216</span>                    ++y;<a name="line.216"></a>
+<span class="sourceLineNo">217</span>                }<a name="line.217"></a>
+<span class="sourceLineNo">218</span>                // Second step<a name="line.218"></a>
+<span class="sourceLineNo">219</span>                if (delta % 2 != 0 &amp;&amp; delta - d &lt;= k &amp;&amp; k &lt;= delta + d) {<a name="line.219"></a>
+<span class="sourceLineNo">220</span>                    if (vUp[i - delta] &lt;= vDown[i]) {<a name="line.220"></a>
+<span class="sourceLineNo">221</span>                        return buildSnake(vUp[i - delta], k + start1 - start2, end1, end2);<a name="line.221"></a>
+<span class="sourceLineNo">222</span>                    }<a name="line.222"></a>
+<span class="sourceLineNo">223</span>                }<a name="line.223"></a>
+<span class="sourceLineNo">224</span>            }<a name="line.224"></a>
+<span class="sourceLineNo">225</span><a name="line.225"></a>
+<span class="sourceLineNo">226</span>            // Up<a name="line.226"></a>
+<span class="sourceLineNo">227</span>            for (int k = delta - d; k &lt;= delta + d; k += 2) {<a name="line.227"></a>
+<span class="sourceLineNo">228</span>                // First step<a name="line.228"></a>
+<span class="sourceLineNo">229</span>                final int i = k + offset - delta;<a name="line.229"></a>
+<span class="sourceLineNo">230</span>                if (k == delta - d<a name="line.230"></a>
+<span class="sourceLineNo">231</span>                        || k != delta + d &amp;&amp; vUp[i + 1] &lt;= vUp[i - 1]) {<a name="line.231"></a>
+<span class="sourceLineNo">232</span>                    vUp[i] = vUp[i + 1] - 1;<a name="line.232"></a>
+<span class="sourceLineNo">233</span>                } else {<a name="line.233"></a>
+<span class="sourceLineNo">234</span>                    vUp[i] = vUp[i - 1];<a name="line.234"></a>
+<span class="sourceLineNo">235</span>                }<a name="line.235"></a>
+<span class="sourceLineNo">236</span><a name="line.236"></a>
+<span class="sourceLineNo">237</span>                int x = vUp[i] - 1;<a name="line.237"></a>
+<span class="sourceLineNo">238</span>                int y = x - start1 + start2 - k;<a name="line.238"></a>
+<span class="sourceLineNo">239</span>                while (x &gt;= start1 &amp;&amp; y &gt;= start2<a name="line.239"></a>
+<span class="sourceLineNo">240</span>                        &amp;&amp; left.charAt(x) == right.charAt(y)) {<a name="line.240"></a>
+<span class="sourceLineNo">241</span>                    vUp[i] = x--;<a name="line.241"></a>
+<span class="sourceLineNo">242</span>                    y--;<a name="line.242"></a>
+<span class="sourceLineNo">243</span>                }<a name="line.243"></a>
+<span class="sourceLineNo">244</span>                // Second step<a name="line.244"></a>
+<span class="sourceLineNo">245</span>                if (delta % 2 == 0 &amp;&amp; -d &lt;= k &amp;&amp; k &lt;= d) {<a name="line.245"></a>
+<span class="sourceLineNo">246</span>                    if (vUp[i] &lt;= vDown[i + delta]) {<a name="line.246"></a>
+<span class="sourceLineNo">247</span>                        return buildSnake(vUp[i], k + start1 - start2, end1, end2);<a name="line.247"></a>
+<span class="sourceLineNo">248</span>                    }<a name="line.248"></a>
+<span class="sourceLineNo">249</span>                }<a name="line.249"></a>
+<span class="sourceLineNo">250</span>            }<a name="line.250"></a>
+<span class="sourceLineNo">251</span>        }<a name="line.251"></a>
 <span class="sourceLineNo">252</span><a name="line.252"></a>
-<span class="sourceLineNo">253</span>    /**<a name="line.253"></a>
-<span class="sourceLineNo">254</span>     * Build a snake.<a name="line.254"></a>
-<span class="sourceLineNo">255</span>     *<a name="line.255"></a>
-<span class="sourceLineNo">256</span>     * @param start  the value of the start of the snake<a name="line.256"></a>
-<span class="sourceLineNo">257</span>     * @param diag  the value of the diagonal of the snake<a name="line.257"></a>
-<span class="sourceLineNo">258</span>     * @param end1  the value of the end of the first sequence to be compared<a name="line.258"></a>
-<span class="sourceLineNo">259</span>     * @param end2  the value of the end of the second sequence to be compared<a name="line.259"></a>
-<span class="sourceLineNo">260</span>     * @return the snake built<a name="line.260"></a>
-<span class="sourceLineNo">261</span>     */<a name="line.261"></a>
-<span class="sourceLineNo">262</span>    private Snake buildSnake(final int start, final int diag, final int end1, final int end2) {<a name="line.262"></a>
-<span class="sourceLineNo">263</span>        int end = start;<a name="line.263"></a>
-<span class="sourceLineNo">264</span>        while (end - diag &lt; end2<a name="line.264"></a>
-<span class="sourceLineNo">265</span>                &amp;&amp; end &lt; end1<a name="line.265"></a>
-<span class="sourceLineNo">266</span>                &amp;&amp; left.charAt(end) == right.charAt(end - diag)) {<a name="line.266"></a>
-<span class="sourceLineNo">267</span>            ++end;<a name="line.267"></a>
-<span class="sourceLineNo">268</span>        }<a name="line.268"></a>
-<span class="sourceLineNo">269</span>        return new Snake(start, end, diag);<a name="line.269"></a>
-<span class="sourceLineNo">270</span>    }<a name="line.270"></a>
-<span class="sourceLineNo">271</span><a name="line.271"></a>
-<span class="sourceLineNo">272</span>    /**<a name="line.272"></a>
-<span class="sourceLineNo">273</span>     * This class is a simple placeholder to hold the end part of a path<a name="line.273"></a>
-<span class="sourceLineNo">274</span>     * under construction in a {@link StringsComparator StringsComparator}.<a name="line.274"></a>
-<span class="sourceLineNo">275</span>     */<a name="line.275"></a>
-<span class="sourceLineNo">276</span>    private static class Snake {<a name="line.276"></a>
-<span class="sourceLineNo">277</span><a name="line.277"></a>
-<span class="sourceLineNo">278</span>        /** Start index. */<a name="line.278"></a>
-<span class="sourceLineNo">279</span>        private final int start;<a name="line.279"></a>
-<span class="sourceLineNo">280</span><a name="line.280"></a>
-<span class="sourceLineNo">281</span>        /** End index. */<a name="line.281"></a>
-<span class="sourceLineNo">282</span>        private final int end;<a name="line.282"></a>
-<span class="sourceLineNo">283</span><a name="line.283"></a>
-<span class="sourceLineNo">284</span>        /** Diagonal number. */<a name="line.284"></a>
-<span class="sourceLineNo">285</span>        private final int diag;<a name="line.285"></a>
-<span class="sourceLineNo">286</span><a name="line.286"></a>
-<span class="sourceLineNo">287</span>        /**<a name="line.287"></a>
-<span class="sourceLineNo">288</span>         * Simple constructor. Creates a new instance of Snake with specified indices.<a name="line.288"></a>
-<span class="sourceLineNo">289</span>         *<a name="line.289"></a>
-<span class="sourceLineNo">290</span>         * @param start  start index of the snake<a name="line.290"></a>
-<span class="sourceLineNo">291</span>         * @param end  end index of the snake<a name="line.291"></a>
-<span class="sourceLineNo">292</span>         * @param diag  diagonal number<a name="line.292"></a>
-<span class="sourceLineNo">293</span>         */<a name="line.293"></a>
-<span class="sourceLineNo">294</span>        public Snake(final int start, final int end, final int diag) {<a name="line.294"></a>
-<span class="sourceLineNo">295</span>            this.start = start;<a name="line.295"></a>
-<span class="sourceLineNo">296</span>            this.end   = end;<a name="line.296"></a>
-<span class="sourceLineNo">297</span>            this.diag  = diag;<a name="line.297"></a>
-<span class="sourceLineNo">298</span>        }<a name="line.298"></a>
-<span class="sourceLineNo">299</span><a name="line.299"></a>
-<span class="sourceLineNo">300</span>        /**<a name="line.300"></a>
-<span class="sourceLineNo">301</span>         * Get the start index of the snake.<a name="line.301"></a>
-<span class="sourceLineNo">302</span>         *<a name="line.302"></a>
-<span class="sourceLineNo">303</span>         * @return start index of the snake<a name="line.303"></a>
-<span class="sourceLineNo">304</span>         */<a name="line.304"></a>
-<span class="sourceLineNo">305</span>        public int getStart() {<a name="line.305"></a>
-<span class="sourceLineNo">306</span>            return start;<a name="line.306"></a>
-<span class="sourceLineNo">307</span>        }<a name="line.307"></a>
-<span class="sourceLineNo">308</span><a name="line.308"></a>
-<span class="sourceLineNo">309</span>        /**<a name="line.309"></a>
-<span class="sourceLineNo">310</span>         * Get the end index of the snake.<a name="line.310"></a>
-<span class="sourceLineNo">311</span>         *<a name="line.311"></a>
-<span class="sourceLineNo">312</span>         * @return end index of the snake<a name="line.312"></a>
-<span class="sourceLineNo">313</span>         */<a name="line.313"></a>
-<span class="sourceLineNo">314</span>        public int getEnd() {<a name="line.314"></a>
-<span class="sourceLineNo">315</span>            return end;<a name="line.315"></a>
-<span class="sourceLineNo">316</span>        }<a name="line.316"></a>
-<span class="sourceLineNo">317</span><a name="line.317"></a>
-<span class="sourceLineNo">318</span>        /**<a name="line.318"></a>
-<span class="sourceLineNo">319</span>         * Get the diagonal number of the snake.<a name="line.319"></a>
-<span class="sourceLineNo">320</span>         *<a name="line.320"></a>
-<span class="sourceLineNo">321</span>         * @return diagonal number of the snake<a name="line.321"></a>
-<span class="sourceLineNo">322</span>         */<a name="line.322"></a>
-<span class="sourceLineNo">323</span>        public int getDiag() {<a name="line.323"></a>
-<span class="sourceLineNo">324</span>            return diag;<a name="line.324"></a>
-<span class="sourceLineNo">325</span>        }<a name="line.325"></a>
-<span class="sourceLineNo">326</span>    }<a name="line.326"></a>
-<span class="sourceLineNo">327</span><a name="line.327"></a>
-<span class="sourceLineNo">328</span>}<a name="line.328"></a>
+<span class="sourceLineNo">253</span>        // this should not happen<a name="line.253"></a>
+<span class="sourceLineNo">254</span>        throw new RuntimeException("Internal Error");<a name="line.254"></a>
+<span class="sourceLineNo">255</span>    }<a name="line.255"></a>
+<span class="sourceLineNo">256</span><a name="line.256"></a>
+<span class="sourceLineNo">257</span>    /**<a name="line.257"></a>
+<span class="sourceLineNo">258</span>     * Build a snake.<a name="line.258"></a>
+<span class="sourceLineNo">259</span>     *<a name="line.259"></a>
+<span class="sourceLineNo">260</span>     * @param start  the value of the start of the snake<a name="line.260"></a>
+<span class="sourceLineNo">261</span>     * @param diag  the value of the diagonal of the snake<a name="line.261"></a>
+<span class="sourceLineNo">262</span>     * @param end1  the value of the end of the first sequence to be compared<a name="line.262"></a>
+<span class="sourceLineNo">263</span>     * @param end2  the value of the end of the second sequence to be compared<a name="line.263"></a>
+<span class="sourceLineNo">264</span>     * @return the snake built<a name="line.264"></a>
+<span class="sourceLineNo">265</span>     */<a name="line.265"></a>
+<span class="sourceLineNo">266</span>    private Snake buildSnake(final int start, final int diag, final int end1, final int end2) {<a name="line.266"></a>
+<span class="sourceLineNo">267</span>        int end = start;<a name="line.267"></a>
+<span class="sourceLineNo">268</span>        while (end - diag &lt; end2<a name="line.268"></a>
+<span class="sourceLineNo">269</span>                &amp;&amp; end &lt; end1<a name="line.269"></a>
+<span class="sourceLineNo">270</span>                &amp;&amp; left.charAt(end) == right.charAt(end - diag)) {<a name="line.270"></a>
+<span class="sourceLineNo">271</span>            ++end;<a name="line.271"></a>
+<span class="sourceLineNo">272</span>        }<a name="line.272"></a>
+<span class="sourceLineNo">273</span>        return new Snake(start, end, diag);<a name="line.273"></a>
+<span class="sourceLineNo">274</span>    }<a name="line.274"></a>
+<span class="sourceLineNo">275</span><a name="line.275"></a>
+<span class="sourceLineNo">276</span>    /**<a name="line.276"></a>
+<span class="sourceLineNo">277</span>     * This class is a simple placeholder to hold the end part of a path<a name="line.277"></a>
+<span class="sourceLineNo">278</span>     * under construction in a {@link StringsComparator StringsComparator}.<a name="line.278"></a>
+<span class="sourceLineNo">279</span>     */<a name="line.279"></a>
+<span class="sourceLineNo">280</span>    private static class Snake {<a name="line.280"></a>
+<span class="sourceLineNo">281</span><a name="line.281"></a>
+<span class="sourceLineNo">282</span>        /** Start index. */<a name="line.282"></a>
+<span class="sourceLineNo">283</span>        private final int start;<a name="line.283"></a>
+<span class="sourceLineNo">284</span><a name="line.284"></a>
+<span class="sourceLineNo">285</span>        /** End index. */<a name="line.285"></a>
+<span class="sourceLineNo">286</span>        private final int end;<a name="line.286"></a>
+<span class="sourceLineNo">287</span><a name="line.287"></a>
+<span class="sourceLineNo">288</span>        /** Diagonal number. */<a name="line.288"></a>
+<span class="sourceLineNo">289</span>        private final int diag;<a name="line.289"></a>
+<span class="sourceLineNo">290</span><a name="line.290"></a>
+<span class="sourceLineNo">291</span>        /**<a name="line.291"></a>
+<span class="sourceLineNo">292</span>         * Simple constructor. Creates a new instance of Snake with specified indices.<a name="line.292"></a>
+<span class="sourceLineNo">293</span>         *<a name="line.293"></a>
+<span class="sourceLineNo">294</span>         * @param start  start index of the snake<a name="line.294"></a>
+<span class="sourceLineNo">295</span>         * @param end  end index of the snake<a name="line.295"></a>
+<span class="sourceLineNo">296</span>         * @param diag  diagonal number<a name="line.296"></a>
+<span class="sourceLineNo">297</span>         */<a name="line.297"></a>
+<span class="sourceLineNo">298</span>        public Snake(final int start, final int end, final int diag) {<a name="line.298"></a>
+<span class="sourceLineNo">299</span>            this.start = start;<a name="line.299"></a>
+<span class="sourceLineNo">300</span>            this.end   = end;<a name="line.300"></a>
+<span class="sourceLineNo">301</span>            this.diag  = diag;<a name="line.301"></a>
+<span class="sourceLineNo">302</span>        }<a name="line.302"></a>
+<span class="sourceLineNo">303</span><a name="line.303"></a>
+<span class="sourceLineNo">304</span>        /**<a name="line.304"></a>
+<span class="sourceLineNo">305</span>         * Get the start index of the snake.<a name="line.305"></a>
+<span class="sourceLineNo">306</span>         *<a name="line.306"></a>
+<span class="sourceLineNo">307</span>         * @return start index of the snake<a name="line.307"></a>
+<span class="sourceLineNo">308</span>         */<a name="line.308"></a>
+<span class="sourceLineNo">309</span>        public int getStart() {<a name="line.309"></a>
+<span class="sourceLineNo">310</span>            return start;<a name="line.310"></a>
+<span class="sourceLineNo">311</span>        }<a name="line.311"></a>
+<span class="sourceLineNo">312</span><a name="line.312"></a>
+<span class="sourceLineNo">313</span>        /**<a name="line.313"></a>
+<span class="sourceLineNo">314</span>         * Get the end index of the snake.<a name="line.314"></a>
+<span class="sourceLineNo">315</span>         *<a name="line.315"></a>
+<span class="sourceLineNo">316</span>         * @return end index of the snake<a name="line.316"></a>
+<span class="sourceLineNo">317</span>         */<a name="line.317"></a>
+<span class="sourceLineNo">318</span>        public int getEnd() {<a name="line.318"></a>
+<span class="sourceLineNo">319</span>            return end;<a name="line.319"></a>
+<span class="sourceLineNo">320</span>        }<a name="line.320"></a>
+<span class="sourceLineNo">321</span><a name="line.321"></a>
+<span class="sourceLineNo">322</span>        /**<a name="line.322"></a>
+<span class="sourceLineNo">323</span>         * Get the diagonal number of the snake.<a name="line.323"></a>
+<span class="sourceLineNo">324</span>         *<a name="line.324"></a>
+<span class="sourceLineNo">325</span>         * @return diagonal number of the snake<a name="line.325"></a>
+<span class="sourceLineNo">326</span>         */<a name="line.326"></a>
+<span class="sourceLineNo">327</span>        public int getDiag() {<a name="line.327"></a>
+<span class="sourceLineNo">328</span>            return diag;<a name="line.328"></a>
+<span class="sourceLineNo">329</span>        }<a name="line.329"></a>
+<span class="sourceLineNo">330</span>    }<a name="line.330"></a>
+<span class="sourceLineNo">331</span><a name="line.331"></a>
+<span class="sourceLineNo">332</span>}<a name="line.332"></a>
 
 
 
@@ -397,4 +401,4 @@
 </pre>
 </div>
 </body>
-</html>
\ No newline at end of file
+</html>

Added: websites/production/commons/content/sandbox/commons-text/apidocs/src-html/org/apache/commons/text/names/HumanNameParser.html
==============================================================================
--- websites/production/commons/content/sandbox/commons-text/apidocs/src-html/org/apache/commons/text/names/HumanNameParser.html (added)
+++ websites/production/commons/content/sandbox/commons-text/apidocs/src-html/org/apache/commons/text/names/HumanNameParser.html Fri Apr 17 06:46:28 2015
@@ -0,0 +1,341 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html lang="en">
+<head>
+<title>Source code</title>
+<link rel="stylesheet" type="text/css" href="../../../../../../stylesheet.css" title="Style">
+</head>
+<body>
+<div class="sourceContainer">
+<pre><span class="sourceLineNo">001</span>/*<a name="line.1"></a>
+<span class="sourceLineNo">002</span>/*<a name="line.2"></a>
+<span class="sourceLineNo">003</span> * Licensed to the Apache Software Foundation (ASF) under one or more<a name="line.3"></a>
+<span class="sourceLineNo">004</span> * contributor license agreements.  See the NOTICE file distributed with<a name="line.4"></a>
+<span class="sourceLineNo">005</span> * this work for additional information regarding copyright ownership.<a name="line.5"></a>
+<span class="sourceLineNo">006</span> * The ASF licenses this file to You under the Apache License, Version 2.0<a name="line.6"></a>
+<span class="sourceLineNo">007</span> * (the "License"); you may not use this file except in compliance with<a name="line.7"></a>
+<span class="sourceLineNo">008</span> * the License.  You may obtain a copy of the License at<a name="line.8"></a>
+<span class="sourceLineNo">009</span> *<a name="line.9"></a>
+<span class="sourceLineNo">010</span> *      http://www.apache.org/licenses/LICENSE-2.0<a name="line.10"></a>
+<span class="sourceLineNo">011</span> *<a name="line.11"></a>
+<span class="sourceLineNo">012</span> * Unless required by applicable law or agreed to in writing, software<a name="line.12"></a>
+<span class="sourceLineNo">013</span> * distributed under the License is distributed on an "AS IS" BASIS,<a name="line.13"></a>
+<span class="sourceLineNo">014</span> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.<a name="line.14"></a>
+<span class="sourceLineNo">015</span> * See the License for the specific language governing permissions and<a name="line.15"></a>
+<span class="sourceLineNo">016</span> * limitations under the License.<a name="line.16"></a>
+<span class="sourceLineNo">017</span> */<a name="line.17"></a>
+<span class="sourceLineNo">018</span>package org.apache.commons.text.names;<a name="line.18"></a>
+<span class="sourceLineNo">019</span><a name="line.19"></a>
+<span class="sourceLineNo">020</span>import java.util.Arrays;<a name="line.20"></a>
+<span class="sourceLineNo">021</span>import java.util.List;<a name="line.21"></a>
+<span class="sourceLineNo">022</span><a name="line.22"></a>
+<span class="sourceLineNo">023</span>import org.apache.commons.lang3.StringUtils;<a name="line.23"></a>
+<span class="sourceLineNo">024</span><a name="line.24"></a>
+<span class="sourceLineNo">025</span>/**<a name="line.25"></a>
+<span class="sourceLineNo">026</span> * &lt;p&gt;A parser capable of parsing name parts out of a single string.&lt;/p&gt;<a name="line.26"></a>
+<span class="sourceLineNo">027</span> *<a name="line.27"></a>
+<span class="sourceLineNo">028</span> * &lt;p&gt;The code works by basically applying several Regexes in a certain order<a name="line.28"></a>
+<span class="sourceLineNo">029</span> * and removing (chopping) tokens off the original string. The parser consumes<a name="line.29"></a>
+<span class="sourceLineNo">030</span> * the tokens during its creation.&lt;/p&gt;<a name="line.30"></a>
+<span class="sourceLineNo">031</span> *<a name="line.31"></a>
+<span class="sourceLineNo">032</span> * &lt;ul&gt;<a name="line.32"></a>
+<span class="sourceLineNo">033</span> * &lt;li&gt;J. Walter Weatherman &lt;/li&gt;<a name="line.33"></a>
+<span class="sourceLineNo">034</span> * &lt;li&gt;de la Cruz, Ana M.&lt;/li&gt;<a name="line.34"></a>
+<span class="sourceLineNo">035</span> * &lt;li&gt;James C. ('Jimmy') O'Dell, Jr.&lt;/li&gt;<a name="line.35"></a>
+<span class="sourceLineNo">036</span> * &lt;/ul&gt;<a name="line.36"></a>
+<span class="sourceLineNo">037</span> *<a name="line.37"></a>
+<span class="sourceLineNo">038</span> * &lt;p&gt;and parses out the:&lt;/p&gt;<a name="line.38"></a>
+<span class="sourceLineNo">039</span> *<a name="line.39"></a>
+<span class="sourceLineNo">040</span> * &lt;ul&gt;<a name="line.40"></a>
+<span class="sourceLineNo">041</span> * &lt;li&gt;leading initial (Like "J." in "J. Walter Weatherman")&lt;/li&gt;<a name="line.41"></a>
+<span class="sourceLineNo">042</span> * &lt;li&gt;first name (or first initial in a name like 'R. Crumb')&lt;/li&gt;<a name="line.42"></a>
+<span class="sourceLineNo">043</span> * &lt;li&gt;nicknames (like "Jimmy" in "James C. ('Jimmy') O'Dell, Jr.")&lt;/li&gt;<a name="line.43"></a>
+<span class="sourceLineNo">044</span> * &lt;li&gt;middle names&lt;/li&gt;<a name="line.44"></a>
+<span class="sourceLineNo">045</span> * &lt;li&gt;last name (including compound ones like "van der Sar' and "Ortega y Gasset"), and&lt;/li&gt;<a name="line.45"></a>
+<span class="sourceLineNo">046</span> * &lt;li&gt;suffix (like 'Jr.', 'III')&lt;/li&gt;<a name="line.46"></a>
+<span class="sourceLineNo">047</span> * &lt;/ul&gt;<a name="line.47"></a>
+<span class="sourceLineNo">048</span> *<a name="line.48"></a>
+<span class="sourceLineNo">049</span> * &lt;pre&gt;<a name="line.49"></a>
+<span class="sourceLineNo">050</span> * Name name = new Name("Sérgio Vieira de Mello");<a name="line.50"></a>
+<span class="sourceLineNo">051</span> * HumanNameParser parser = new HumanNameParser(name);<a name="line.51"></a>
+<span class="sourceLineNo">052</span> * String firstName = parser.getFirst();<a name="line.52"></a>
+<span class="sourceLineNo">053</span> * String nickname = parser.getNickname();<a name="line.53"></a>
+<span class="sourceLineNo">054</span> * // ...<a name="line.54"></a>
+<span class="sourceLineNo">055</span> * &lt;/pre&gt;<a name="line.55"></a>
+<span class="sourceLineNo">056</span> *<a name="line.56"></a>
+<span class="sourceLineNo">057</span> * &lt;p&gt;The original code was written in &lt;a href="http://jasonpriem.com/human-name-parse"&gt;PHP&lt;/a&gt;<a name="line.57"></a>
+<span class="sourceLineNo">058</span> * and ported to &lt;a href="http://tupilabs.github.io/HumanNameParser.java/"&gt;Java&lt;/a&gt;.&lt;/p&gt;<a name="line.58"></a>
+<span class="sourceLineNo">059</span> *<a name="line.59"></a>
+<span class="sourceLineNo">060</span> * &lt;p&gt;This implementation is based on the Java implementation, with additions<a name="line.60"></a>
+<span class="sourceLineNo">061</span> * suggested in &lt;a href="https://issues.apache.org/jira/browse/SANDBOX-487"&gt;SANDBOX-487&lt;/a&gt;.&lt;/p&gt;<a name="line.61"></a>
+<span class="sourceLineNo">062</span> *<a name="line.62"></a>
+<span class="sourceLineNo">063</span> * &lt;p&gt;This class is not thread-safe.&lt;/p&gt;<a name="line.63"></a>
+<span class="sourceLineNo">064</span> *<a name="line.64"></a>
+<span class="sourceLineNo">065</span> * @since 1.0<a name="line.65"></a>
+<span class="sourceLineNo">066</span> */<a name="line.66"></a>
+<span class="sourceLineNo">067</span>public class HumanNameParser {<a name="line.67"></a>
+<span class="sourceLineNo">068</span><a name="line.68"></a>
+<span class="sourceLineNo">069</span>    /**<a name="line.69"></a>
+<span class="sourceLineNo">070</span>     * Name parsed.<a name="line.70"></a>
+<span class="sourceLineNo">071</span>     */<a name="line.71"></a>
+<span class="sourceLineNo">072</span>    private Name name;<a name="line.72"></a>
+<span class="sourceLineNo">073</span>    /**<a name="line.73"></a>
+<span class="sourceLineNo">074</span>     * Leading init part.<a name="line.74"></a>
+<span class="sourceLineNo">075</span>     */<a name="line.75"></a>
+<span class="sourceLineNo">076</span>    private String leadingInit;<a name="line.76"></a>
+<span class="sourceLineNo">077</span>    /**<a name="line.77"></a>
+<span class="sourceLineNo">078</span>     * First name.<a name="line.78"></a>
+<span class="sourceLineNo">079</span>     */<a name="line.79"></a>
+<span class="sourceLineNo">080</span>    private String first;<a name="line.80"></a>
+<span class="sourceLineNo">081</span>    /**<a name="line.81"></a>
+<span class="sourceLineNo">082</span>     * Single nickname found in the name input.<a name="line.82"></a>
+<span class="sourceLineNo">083</span>     */<a name="line.83"></a>
+<span class="sourceLineNo">084</span>    private String nickname;<a name="line.84"></a>
+<span class="sourceLineNo">085</span>    /**<a name="line.85"></a>
+<span class="sourceLineNo">086</span>     * Middle name.<a name="line.86"></a>
+<span class="sourceLineNo">087</span>     */<a name="line.87"></a>
+<span class="sourceLineNo">088</span>    private String middle;<a name="line.88"></a>
+<span class="sourceLineNo">089</span>    /**<a name="line.89"></a>
+<span class="sourceLineNo">090</span>     * Last name.<a name="line.90"></a>
+<span class="sourceLineNo">091</span>     */<a name="line.91"></a>
+<span class="sourceLineNo">092</span>    private String last;<a name="line.92"></a>
+<span class="sourceLineNo">093</span>    /**<a name="line.93"></a>
+<span class="sourceLineNo">094</span>     * Name suffix.<a name="line.94"></a>
+<span class="sourceLineNo">095</span>     */<a name="line.95"></a>
+<span class="sourceLineNo">096</span>    private String suffix;<a name="line.96"></a>
+<span class="sourceLineNo">097</span>    /**<a name="line.97"></a>
+<span class="sourceLineNo">098</span>     * Suffixes found.<a name="line.98"></a>
+<span class="sourceLineNo">099</span>     */<a name="line.99"></a>
+<span class="sourceLineNo">100</span>    private List&lt;String&gt; suffixes;<a name="line.100"></a>
+<span class="sourceLineNo">101</span>    /**<a name="line.101"></a>
+<span class="sourceLineNo">102</span>     * Prefixes found.<a name="line.102"></a>
+<span class="sourceLineNo">103</span>     */<a name="line.103"></a>
+<span class="sourceLineNo">104</span>    private List&lt;String&gt; prefixes;<a name="line.104"></a>
+<span class="sourceLineNo">105</span><a name="line.105"></a>
+<span class="sourceLineNo">106</span>    /**<a name="line.106"></a>
+<span class="sourceLineNo">107</span>     * Creates a parser given a string name.<a name="line.107"></a>
+<span class="sourceLineNo">108</span>     *<a name="line.108"></a>
+<span class="sourceLineNo">109</span>     * @param name string name<a name="line.109"></a>
+<span class="sourceLineNo">110</span>     */<a name="line.110"></a>
+<span class="sourceLineNo">111</span>    public HumanNameParser(String name) {<a name="line.111"></a>
+<span class="sourceLineNo">112</span>        this(new Name(name));<a name="line.112"></a>
+<span class="sourceLineNo">113</span>    }<a name="line.113"></a>
+<span class="sourceLineNo">114</span><a name="line.114"></a>
+<span class="sourceLineNo">115</span>    /**<a name="line.115"></a>
+<span class="sourceLineNo">116</span>     * Creates a parser given a {@code Name} object.<a name="line.116"></a>
+<span class="sourceLineNo">117</span>     *<a name="line.117"></a>
+<span class="sourceLineNo">118</span>     * @param name {@code Name}<a name="line.118"></a>
+<span class="sourceLineNo">119</span>     */<a name="line.119"></a>
+<span class="sourceLineNo">120</span>    public HumanNameParser(Name name) {<a name="line.120"></a>
+<span class="sourceLineNo">121</span>        this.name = name;<a name="line.121"></a>
+<span class="sourceLineNo">122</span><a name="line.122"></a>
+<span class="sourceLineNo">123</span>        this.leadingInit = "";<a name="line.123"></a>
+<span class="sourceLineNo">124</span>        this.first = "";<a name="line.124"></a>
+<span class="sourceLineNo">125</span>        this.nickname = "";<a name="line.125"></a>
+<span class="sourceLineNo">126</span>        this.middle = "";<a name="line.126"></a>
+<span class="sourceLineNo">127</span>        this.last = "";<a name="line.127"></a>
+<span class="sourceLineNo">128</span>        this.suffix = "";<a name="line.128"></a>
+<span class="sourceLineNo">129</span><a name="line.129"></a>
+<span class="sourceLineNo">130</span>        this.suffixes = Arrays.asList(new String[] {<a name="line.130"></a>
+<span class="sourceLineNo">131</span>                "esq", "esquire", "jr",<a name="line.131"></a>
+<span class="sourceLineNo">132</span>                "sr", "2", "ii", "iii", "iv" });<a name="line.132"></a>
+<span class="sourceLineNo">133</span>        this.prefixes = Arrays<a name="line.133"></a>
+<span class="sourceLineNo">134</span>            .asList(new String[] {<a name="line.134"></a>
+<span class="sourceLineNo">135</span>                    "bar", "ben", "bin", "da", "dal",<a name="line.135"></a>
+<span class="sourceLineNo">136</span>                    "de la", "de", "del", "der", "di", "ibn", "la", "le",<a name="line.136"></a>
+<span class="sourceLineNo">137</span>                    "san", "st", "ste", "van", "van der", "van den", "vel",<a name="line.137"></a>
+<span class="sourceLineNo">138</span>                    "von" });<a name="line.138"></a>
+<span class="sourceLineNo">139</span><a name="line.139"></a>
+<span class="sourceLineNo">140</span>        this.parse();<a name="line.140"></a>
+<span class="sourceLineNo">141</span>    }<a name="line.141"></a>
+<span class="sourceLineNo">142</span><a name="line.142"></a>
+<span class="sourceLineNo">143</span>    /**<a name="line.143"></a>
+<span class="sourceLineNo">144</span>     * Gets the {@code Name} object.<a name="line.144"></a>
+<span class="sourceLineNo">145</span>     *<a name="line.145"></a>
+<span class="sourceLineNo">146</span>     * @return the {@code Name} object<a name="line.146"></a>
+<span class="sourceLineNo">147</span>     */<a name="line.147"></a>
+<span class="sourceLineNo">148</span>    public Name getName() {<a name="line.148"></a>
+<span class="sourceLineNo">149</span>        return name;<a name="line.149"></a>
+<span class="sourceLineNo">150</span>    }<a name="line.150"></a>
+<span class="sourceLineNo">151</span><a name="line.151"></a>
+<span class="sourceLineNo">152</span>    /**<a name="line.152"></a>
+<span class="sourceLineNo">153</span>     * Gets the leading init part of the name.<a name="line.153"></a>
+<span class="sourceLineNo">154</span>     *<a name="line.154"></a>
+<span class="sourceLineNo">155</span>     * @return the leading init part of the name<a name="line.155"></a>
+<span class="sourceLineNo">156</span>     */<a name="line.156"></a>
+<span class="sourceLineNo">157</span>    public String getLeadingInit() {<a name="line.157"></a>
+<span class="sourceLineNo">158</span>        return leadingInit;<a name="line.158"></a>
+<span class="sourceLineNo">159</span>    }<a name="line.159"></a>
+<span class="sourceLineNo">160</span><a name="line.160"></a>
+<span class="sourceLineNo">161</span>    /**<a name="line.161"></a>
+<span class="sourceLineNo">162</span>     * Gets the first name.<a name="line.162"></a>
+<span class="sourceLineNo">163</span>     *<a name="line.163"></a>
+<span class="sourceLineNo">164</span>     * @return first name<a name="line.164"></a>
+<span class="sourceLineNo">165</span>     */<a name="line.165"></a>
+<span class="sourceLineNo">166</span>    public String getFirst() {<a name="line.166"></a>
+<span class="sourceLineNo">167</span>        return first;<a name="line.167"></a>
+<span class="sourceLineNo">168</span>    }<a name="line.168"></a>
+<span class="sourceLineNo">169</span><a name="line.169"></a>
+<span class="sourceLineNo">170</span>    /**<a name="line.170"></a>
+<span class="sourceLineNo">171</span>     * Gets the nickname.<a name="line.171"></a>
+<span class="sourceLineNo">172</span>     *<a name="line.172"></a>
+<span class="sourceLineNo">173</span>     * @return the nickname<a name="line.173"></a>
+<span class="sourceLineNo">174</span>     */<a name="line.174"></a>
+<span class="sourceLineNo">175</span>    public String getNickname() {<a name="line.175"></a>
+<span class="sourceLineNo">176</span>        return nickname;<a name="line.176"></a>
+<span class="sourceLineNo">177</span>    }<a name="line.177"></a>
+<span class="sourceLineNo">178</span><a name="line.178"></a>
+<span class="sourceLineNo">179</span>    /**<a name="line.179"></a>
+<span class="sourceLineNo">180</span>     * Gets the middle name.<a name="line.180"></a>
+<span class="sourceLineNo">181</span>     *<a name="line.181"></a>
+<span class="sourceLineNo">182</span>     * @return the middle name<a name="line.182"></a>
+<span class="sourceLineNo">183</span>     */<a name="line.183"></a>
+<span class="sourceLineNo">184</span>    public String getMiddle() {<a name="line.184"></a>
+<span class="sourceLineNo">185</span>        return middle;<a name="line.185"></a>
+<span class="sourceLineNo">186</span>    }<a name="line.186"></a>
+<span class="sourceLineNo">187</span><a name="line.187"></a>
+<span class="sourceLineNo">188</span>    /**<a name="line.188"></a>
+<span class="sourceLineNo">189</span>     * Gets the last name.<a name="line.189"></a>
+<span class="sourceLineNo">190</span>     *<a name="line.190"></a>
+<span class="sourceLineNo">191</span>     * @return the last name<a name="line.191"></a>
+<span class="sourceLineNo">192</span>     */<a name="line.192"></a>
+<span class="sourceLineNo">193</span>    public String getLast() {<a name="line.193"></a>
+<span class="sourceLineNo">194</span>        return last;<a name="line.194"></a>
+<span class="sourceLineNo">195</span>    }<a name="line.195"></a>
+<span class="sourceLineNo">196</span><a name="line.196"></a>
+<span class="sourceLineNo">197</span>    /**<a name="line.197"></a>
+<span class="sourceLineNo">198</span>     * Gets the suffix part of the name.<a name="line.198"></a>
+<span class="sourceLineNo">199</span>     *<a name="line.199"></a>
+<span class="sourceLineNo">200</span>     * @return the name suffix<a name="line.200"></a>
+<span class="sourceLineNo">201</span>     */<a name="line.201"></a>
+<span class="sourceLineNo">202</span>    public String getSuffix() {<a name="line.202"></a>
+<span class="sourceLineNo">203</span>        return suffix;<a name="line.203"></a>
+<span class="sourceLineNo">204</span>    }<a name="line.204"></a>
+<span class="sourceLineNo">205</span><a name="line.205"></a>
+<span class="sourceLineNo">206</span>    /**<a name="line.206"></a>
+<span class="sourceLineNo">207</span>     * Gets the name suffixes.<a name="line.207"></a>
+<span class="sourceLineNo">208</span>     *<a name="line.208"></a>
+<span class="sourceLineNo">209</span>     * @return the name suffixes<a name="line.209"></a>
+<span class="sourceLineNo">210</span>     */<a name="line.210"></a>
+<span class="sourceLineNo">211</span>    public List&lt;String&gt; getSuffixes() {<a name="line.211"></a>
+<span class="sourceLineNo">212</span>        return suffixes;<a name="line.212"></a>
+<span class="sourceLineNo">213</span>    }<a name="line.213"></a>
+<span class="sourceLineNo">214</span><a name="line.214"></a>
+<span class="sourceLineNo">215</span>    /**<a name="line.215"></a>
+<span class="sourceLineNo">216</span>     * Gets the name prefixes.<a name="line.216"></a>
+<span class="sourceLineNo">217</span>     *<a name="line.217"></a>
+<span class="sourceLineNo">218</span>     * @return the name prefixes<a name="line.218"></a>
+<span class="sourceLineNo">219</span>     */<a name="line.219"></a>
+<span class="sourceLineNo">220</span>    public List&lt;String&gt; getPrefixes() {<a name="line.220"></a>
+<span class="sourceLineNo">221</span>        return prefixes;<a name="line.221"></a>
+<span class="sourceLineNo">222</span>    }<a name="line.222"></a>
+<span class="sourceLineNo">223</span><a name="line.223"></a>
+<span class="sourceLineNo">224</span>    /**<a name="line.224"></a>
+<span class="sourceLineNo">225</span>     * Consumes the string and creates the name parts.<a name="line.225"></a>
+<span class="sourceLineNo">226</span>     *<a name="line.226"></a>
+<span class="sourceLineNo">227</span>     * @throws NameParseException if the parser fails to retrieve the name parts<a name="line.227"></a>
+<span class="sourceLineNo">228</span>     */<a name="line.228"></a>
+<span class="sourceLineNo">229</span>    private void parse() {<a name="line.229"></a>
+<span class="sourceLineNo">230</span>        String suffixes = StringUtils.join(this.suffixes, "\\.*|") + "\\.*";<a name="line.230"></a>
+<span class="sourceLineNo">231</span>        String prefixes = StringUtils.join(this.prefixes, " |") + " ";<a name="line.231"></a>
+<span class="sourceLineNo">232</span><a name="line.232"></a>
+<span class="sourceLineNo">233</span>        // The regex use is a bit tricky.  *Everything* matched by the regex will be replaced,<a name="line.233"></a>
+<span class="sourceLineNo">234</span>        // but you can select a particular parenthesized submatch to be returned.<a name="line.234"></a>
+<span class="sourceLineNo">235</span>        // Also, note that each regex requres that the preceding ones have been run, and matches chopped out.<a name="line.235"></a>
+<span class="sourceLineNo">236</span>        // names that starts or end w/ an apostrophe break this<a name="line.236"></a>
+<span class="sourceLineNo">237</span>        String nicknamesRegex = "(?i) ('|\\\"|\\(\\\"*'*)(.+?)('|\\\"|\\\"*'*\\)) ";<a name="line.237"></a>
+<span class="sourceLineNo">238</span>        String suffixRegex = "(?i),* *((" + suffixes + ")$)";<a name="line.238"></a>
+<span class="sourceLineNo">239</span>        String lastRegex = "(?i)(?!^)\\b([^ ]+ y |" + prefixes + ")*[^ ]+$";<a name="line.239"></a>
+<span class="sourceLineNo">240</span>        // note the lookahead, which isn't returned or replaced<a name="line.240"></a>
+<span class="sourceLineNo">241</span>        String leadingInitRegex = "(?i)(^(.\\.*)(?= \\p{L}{2}))";<a name="line.241"></a>
+<span class="sourceLineNo">242</span>        String firstRegex = "(?i)^([^ ]+)";<a name="line.242"></a>
+<span class="sourceLineNo">243</span><a name="line.243"></a>
+<span class="sourceLineNo">244</span>        // get nickname, if there is one<a name="line.244"></a>
+<span class="sourceLineNo">245</span>        this.nickname = this.name.chopWithRegex(nicknamesRegex, 2);<a name="line.245"></a>
+<span class="sourceLineNo">246</span><a name="line.246"></a>
+<span class="sourceLineNo">247</span>        // get suffix, if there is one<a name="line.247"></a>
+<span class="sourceLineNo">248</span>        this.suffix = this.name.chopWithRegex(suffixRegex, 1);<a name="line.248"></a>
+<span class="sourceLineNo">249</span><a name="line.249"></a>
+<span class="sourceLineNo">250</span>        // flip the before-comma and after-comma parts of the name<a name="line.250"></a>
+<span class="sourceLineNo">251</span>        this.name.flip(",");<a name="line.251"></a>
+<span class="sourceLineNo">252</span><a name="line.252"></a>
+<span class="sourceLineNo">253</span>        // get the last name<a name="line.253"></a>
+<span class="sourceLineNo">254</span>        this.last = this.name.chopWithRegex(lastRegex, 0);<a name="line.254"></a>
+<span class="sourceLineNo">255</span><a name="line.255"></a>
+<span class="sourceLineNo">256</span>        // get the first initial, if there is one<a name="line.256"></a>
+<span class="sourceLineNo">257</span>        this.leadingInit = this.name.chopWithRegex(leadingInitRegex, 1);<a name="line.257"></a>
+<span class="sourceLineNo">258</span><a name="line.258"></a>
+<span class="sourceLineNo">259</span>        // get the first name<a name="line.259"></a>
+<span class="sourceLineNo">260</span>        this.first = this.name.chopWithRegex(firstRegex, 0);<a name="line.260"></a>
+<span class="sourceLineNo">261</span>        if (StringUtils.isBlank(this.first)) {<a name="line.261"></a>
+<span class="sourceLineNo">262</span>            throw new NameParseException("Couldn't find a first name in '{" + this.name.getStr() + "}'");<a name="line.262"></a>
+<span class="sourceLineNo">263</span>        }<a name="line.263"></a>
+<span class="sourceLineNo">264</span><a name="line.264"></a>
+<span class="sourceLineNo">265</span>        // if anything's left, that's the middle name<a name="line.265"></a>
+<span class="sourceLineNo">266</span>        this.middle = this.name.getStr();<a name="line.266"></a>
+<span class="sourceLineNo">267</span>    }<a name="line.267"></a>
+<span class="sourceLineNo">268</span><a name="line.268"></a>
+<span class="sourceLineNo">269</span>}<a name="line.269"></a>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+</pre>
+</div>
+</body>
+</html>



Mime
View raw message