mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Source: Restore broken commit
This commit is contained in:
38
400_xowa/src/gplx/xowa/apps/versions/Xoa_version_.java
Normal file
38
400_xowa/src/gplx/xowa/apps/versions/Xoa_version_.java
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.apps.versions; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
public class Xoa_version_ {
|
||||
public static int Compare(String lhs_str, String rhs_str) {
|
||||
String[] lhs_ary = String_.Split(lhs_str, ".");
|
||||
String[] rhs_ary = String_.Split(rhs_str, ".");
|
||||
return Compare_as_int(lhs_ary, rhs_ary);
|
||||
}
|
||||
private static int Compare_as_int(String[] lhs_ary, String[] rhs_ary) {
|
||||
int lhs_ary_len = lhs_ary.length;
|
||||
int rhs_ary_len = rhs_ary.length;
|
||||
int len_comp = Int_.Compare(lhs_ary_len, rhs_ary_len);
|
||||
if (len_comp != CompareAble_.Same) return len_comp;
|
||||
for (int i = 0; i < lhs_ary_len; ++i) {
|
||||
String lhs_itm = lhs_ary[i];
|
||||
String rhs_itm = rhs_ary[i];
|
||||
int itm_comp = Int_.Compare(Int_.parse_or(lhs_itm, 0), Int_.parse_or(rhs_itm, 0));
|
||||
if (itm_comp != CompareAble_.Same) return itm_comp;
|
||||
}
|
||||
return CompareAble_.Same;
|
||||
}
|
||||
}
|
||||
37
400_xowa/src/gplx/xowa/apps/versions/Xoa_version_tst.java
Normal file
37
400_xowa/src/gplx/xowa/apps/versions/Xoa_version_tst.java
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.apps.versions; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import org.junit.*;
|
||||
public class Xoa_version_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoa_version_fxt fxt = new Xoa_version_fxt();
|
||||
@Test public void Compare() {
|
||||
fxt.Test_compare("1.8.1.1", "1.8.2.1" , CompareAble_.Less); // rev:less
|
||||
fxt.Test_compare("1.8.2.1", "1.8.1.1" , CompareAble_.More); // rev:more
|
||||
fxt.Test_compare("1.8.1.1", "1.8.1.1" , CompareAble_.Same); // rev:same
|
||||
fxt.Test_compare("1.7.9.1", "1.8.1.1" , CompareAble_.Less); // min:less
|
||||
fxt.Test_compare("", "1.8.1.1" , CompareAble_.Less); // empty:less
|
||||
fxt.Test_compare("1.8.1.1", "" , CompareAble_.More); // empty:more
|
||||
fxt.Test_compare("", "" , CompareAble_.Same); // empty:more
|
||||
}
|
||||
}
|
||||
class Xoa_version_fxt {
|
||||
public void Clear() {}
|
||||
public void Test_compare(String lhs, String rhs, int expd) {
|
||||
Tfds.Eq(expd, Xoa_version_.Compare(lhs, rhs), lhs + "|" + rhs);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user