• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jiangxincode / ApkToolBoxGUI / #1179

07 Sep 2025 01:57AM UTC coverage: 2.896%. Remained the same
#1179

push

jiangxincode
[PMD issues]Fix PMD issues: ClassCastExceptionWithToArray

0 of 4 new or added lines in 1 file covered. (0.0%)

248 of 8563 relevant lines covered (2.9%)

0.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/java/edu/jiangxin/apktoolbox/swing/extend/autocomplete/AutoCompleter.java
1
package edu.jiangxin.apktoolbox.swing.extend.autocomplete;
2

3
import org.apache.commons.lang3.StringUtils;
4

5
import javax.swing.*;
6
import java.awt.*;
7
import java.awt.event.KeyEvent;
8
import java.awt.event.KeyListener;
9
import java.util.Vector;
10

11
class AutoCompleter<E> implements KeyListener {
12
    private JComboBox<E> comboBox;
13
    private JTextField textField;
14
    private ComboBoxModel<E> comboBoxModel;
15

16
    public AutoCompleter(JComboBox<E> comboBox) {
×
17
        if (comboBox == null) {
×
18
            throw new AutoCompleterInitException("comboBox is null");
×
19
        }
20
        this.comboBox = comboBox;
×
21
        ComboBoxEditor comboBoxEditor = comboBox.getEditor();
×
22
        if (comboBoxEditor == null) {
×
23
            throw new AutoCompleterInitException("comboBoxEditor is null");
×
24
        }
25
        Component component = comboBoxEditor.getEditorComponent();
×
26
        if (!(component instanceof JTextField)) {
×
27
            throw new AutoCompleterInitException("component is invalid");
×
28
        }
29
        this.textField = (JTextField) component;
×
30
        this.textField.addKeyListener(this);
×
31
        this.comboBoxModel = comboBox.getModel();
×
32
    }
×
33

34
    @Override
35
    public void keyTyped(KeyEvent e) {
36
        // do nothing
37
    }
×
38

39
    @Override
40
    public void keyPressed(KeyEvent e) {
41
        // do nothing
42
    }
×
43

44
    @Override
45
    public void keyReleased(KeyEvent e) {
46
        char keyChar = e.getKeyChar();
×
47
        if (Character.isAlphabetic(keyChar) || Character.isDigit(keyChar) || Character.isWhitespace(keyChar)
×
48
                || keyChar == KeyEvent.VK_BACK_SPACE) {
49
            String text = textField.getText();
×
50
            autoComplete(text);
×
51
            textField.setText(text);
×
52
        }
53
    }
×
54

55
    protected void autoComplete(String text) {
NEW
56
        Vector<E> opts = getMatchingOptions(text);
×
57
        comboBox.setModel(new DefaultComboBoxModel<>(opts));
×
58
        if (comboBox.getItemCount() > 0) {
×
59
            comboBox.showPopup();
×
60
        }
61
    }
×
62

63
    private Vector<E> getMatchingOptions(String text) {
NEW
64
        Vector<E> vector = new Vector<>();
×
65
        ComboBoxModel<E> tmp = this.comboBoxModel;
×
66
        for (int i = 0; i < tmp.getSize(); i++) {
×
67
            E itemObj = tmp.getElementAt(i);
×
68
            if (StringUtils.isEmpty(text) || StringUtils.containsIgnoreCase(itemObj.toString(), text)) {
×
NEW
69
                vector.add(itemObj);
×
70
            }
71
        }
NEW
72
        return vector;
×
73
    }
74

75
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc