rendered paste body
+
+public class AINumericdocument extends PlainDocument {
Chiamalo AINumericDocument.
+ private String formatRegex = null;
+ private Pattern pattern = null;
Da togliere.
+
+ private boolean onlyDigits(String str) {
+ if (str == null) {
+ return true;
+ }
+ int sz = str.length();
+ for (int i = 0; i < sz; i++) {
+ if (!Character.isDigit(str.charAt(i))) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
+ if (str == null) {
+ return;
+ }
+
+ if (!onlyDigits(str)) {
+ return;
+ }
Viene controllato due volte se str è null. Forse uno dei due check si può togliere.
Ad esempio onlyDigits potrebbe tornare false se str è null.
+
+ super.insertString(offs, str, a);
+ }
+}