写玩我自己都看不懂了,求大神看哈,能不能优化,或者说逻辑根本就有问题?
下面是代码
- TreeSet<String> ts = new TreeSet<String>(new Comparator<String>() {
- @Override
- public int compare(String str1, String str2) {
- String[] arr1 = str1.split("\\.");
- String[] arr2 = str2.split("\\.");
- int arr1Len = 0;
- int arr2Len = 0;
- int num = 0;
- if (arr1Len < arr1.length && arr2Len < arr2.length) {
- num = new Integer(arr1[arr1Len]).compareTo(new Integer(
- arr2[arr2Len]));
- arr1Len++;
- arr2Len++;
- if (num == 0) {
- if (arr1Len < arr1.length && arr2Len < arr2.length) {
- num = new Integer(arr1[arr1Len])
- .compareTo(new Integer(arr2[arr2Len]));
- arr1Len++;
- arr2Len++;
- if (num == 0) {
- if (arr1Len < arr1.length
- && arr2Len < arr2.length) {
- num = new Integer(arr1[arr1Len])
- .compareTo(new Integer(
- arr2[arr2Len]));
- arr1Len++;
- arr2Len++;
- if (num == 0) {
- if (arr1Len < arr1.length
- && arr2Len < arr2.length) {
- num = new Integer(arr1[3])
- .compareTo(new Integer(
- arr2[3]));
- arr1Len++;
- arr2Len++;
- if (num == 0) {
- if (arr1Len < arr1.length
- && arr2Len < arr2.length) {
- throw new RuntimeException("IP地址格式不对");
- }
- else
- return num;
- }
- }
- }
- }
- }
- }
- }
- }
- return num;
- }
- });
复制代码
|