Skip to content

Commit 2e2c6e4

Browse files
suppressing common prefix to make shown test id more compact
1 parent 4512f80 commit 2e2c6e4

File tree

2 files changed

+88
-4
lines changed

2 files changed

+88
-4
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright 2019 Philipp Salvisberg <philipp.salvisberg@trivadis.com>
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.utplsql.sqldev.model
17+
18+
// converted to Xtend based on Java code on https://www.geeksforgeeks.org/longest-common-prefix-using-binary-search/
19+
class GFG {
20+
def static int findMinLength(String[] arr, int n) {
21+
var int min = Integer.MAX_VALUE
22+
for (var int i = 0; i <= (n - 1); i++) {
23+
if ({
24+
val _rdIndx_arr = i
25+
arr.get(_rdIndx_arr)
26+
}.length() < min) {
27+
min = {
28+
val _rdIndx_arr = i
29+
arr.get(_rdIndx_arr)
30+
}.length()
31+
}
32+
}
33+
return min
34+
}
35+
36+
def static boolean allContainsPrefix(String[] arr, int n, String str, int start, int end) {
37+
for (var int i = 0; i <= (n - 1); i++) {
38+
var String arr_i = {
39+
val _rdIndx_arr = i
40+
arr.get(_rdIndx_arr)
41+
}
42+
for (var int j = start; j <= end; j++)
43+
if(arr_i.charAt(j) !== str.charAt(j)) return false
44+
}
45+
return true
46+
}
47+
48+
def static String commonPrefix(String[] arr, int n) {
49+
var int index = findMinLength(arr, n)
50+
var String prefix = ""
51+
var int low = 0
52+
var int high = index
53+
while (low <= high) {
54+
var int mid = low + (high - low) / 2
55+
if (allContainsPrefix(arr, n, arr.get(0), low, mid)) {
56+
prefix = prefix + arr.get(0).substring(low, mid + 1)
57+
low = mid + 1
58+
} else {
59+
high = mid - 1
60+
}
61+
}
62+
return prefix
63+
}
64+
}

sqldev/src/main/java/org/utplsql/sqldev/ui/runner/TestOverviewTableModel.xtend

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,38 @@
1-
package org.utplsql.sqldev.ui.runner
1+
/*
2+
* Copyright 2019 Philipp Salvisberg <philipp.salvisberg@trivadis.com>
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.utplsql.sqldev.ui.runner
217

318
import java.util.LinkedHashMap
419
import javax.swing.Icon
520
import javax.swing.table.DefaultTableModel
21+
import org.utplsql.sqldev.model.GFG
622
import org.utplsql.sqldev.model.runner.Test
723
import org.utplsql.sqldev.resources.UtplsqlResources
824

925
class TestOverviewTableModel extends DefaultTableModel {
1026
LinkedHashMap<String, Test> tests
27+
String commonPrefix
1128

1229
new() {
1330
super()
1431
}
1532

1633
def setModel(LinkedHashMap<String, Test> tests) {
1734
this.tests = tests
35+
this.commonPrefix = null
1836
fireTableDataChanged()
1937
}
2038

@@ -31,17 +49,19 @@ class TestOverviewTableModel extends DefaultTableModel {
3149

3250
override getValueAt(int row, int col) {
3351
val test = tests.entrySet.get(row).value
34-
3552
if (test === null) {
3653
return null
3754
}
38-
55+
if (commonPrefix === null) {
56+
var String[] testArray = newArrayOfSize(tests.keySet.size)
57+
commonPrefix = GFG.commonPrefix(tests.keySet.toArray(testArray), tests.keySet.size)
58+
}
3959
switch (col) {
4060
case 0: {
4161
return test.statusIcon
4262
}
4363
case 1: {
44-
return test.id
64+
return test.id.substring(if(commonPrefix === null) {0} else {commonPrefix.length})
4565
}
4666
case 2: {
4767
return test.executionTime

0 commit comments

Comments
 (0)