Browse Source

Pull request #2011: REPORT-36070 公式面板搜索:date,没有显示在第一行

Merge in DESIGN/design from ~YVAN/design:release/10.0 to release/10.0

* commit 'af69f42bd7fd29bce997f9b609a6e7b3d1091d2b':
  主要修改: 补充了一个test
  主要修改: 修改了对搜索结果排序的比较器,分为以关键词开头和不以关键词开头两部分,各自以字母表顺序排列,其中在以关键词开头的部分,最为匹配关键词的放在第一行
feature/big-screen
Yvan 4 years ago
parent
commit
734b021a4a
  1. 20
      designer-base/src/main/java/com/fr/design/formula/FormulaPane.java
  2. 10
      designer-base/src/test/java/com/fr/design/formula/FormulaPaneTest.java

20
designer-base/src/main/java/com/fr/design/formula/FormulaPane.java

@ -1008,15 +1008,23 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula {
this.searchKey = searchKey.toLowerCase();
}
/**
* 把以关键词开头的和不以关键词开头的分别按照字母表顺序排序
* @param o1 待比较对象1
* @param o2 待比较对象2
* @return 比较结果1表示 o1 > o2, -1表示 o1 < o2, 0表示 o1 = o2
*/
@Override
public int compare(String o1, String o2) {
if (o1.toLowerCase().startsWith(searchKey)) {
return -1;
}
if (o2.toLowerCase().startsWith(searchKey)) {
return 1;
int result;
boolean o1StartWith = o1.toLowerCase().startsWith(searchKey);
boolean o2StartWith = o2.toLowerCase().startsWith(searchKey);
if (o1StartWith) {
result = o2StartWith ? o1.compareTo(o2) : -1;
} else {
result = o2StartWith ? 1 : o1.compareTo(o2);
}
return o2.compareTo(o1);
return result;
}
}

10
designer-base/src/test/java/com/fr/design/formula/FormulaPaneTest.java

@ -22,4 +22,12 @@ public class FormulaPaneTest extends TestCase {
Assert.assertArrayEquals(result, strs);
}
}
@Test
public void test4SimilarComparator() {
String[] strs = new String[]{"TESTB", "TESTACD", "Ftest", "Gtest", "TEST"};
String[] result = new String[]{"TEST", "TESTACD", "TESTB", "Ftest", "Gtest"};
Arrays.sort(strs, new FormulaPane.SimilarComparator("test"));
Assert.assertArrayEquals(result, strs);
}
}

Loading…
Cancel
Save