char c = e.getKeyChar(); // as a coding convenience, create a reference to the text component // that is typecast to JTextComponent. this is not essential, as we // could typecast every reference, but this makes the code cleaner JTextComponent _theComponent = (JTextComponent)DataTypeFloat.this._textComponent; String text = _theComponent.getText(); // tabs and newlines get put into the text before this check, // so remove them // This only applies to Popup editing since these chars are // not passed to this level by the in-cell editor. if (c == KeyEvent.VK_TAB || c == KeyEvent.VK_ENTER) { // remove all instances of the offending char int index = text.indexOf(c); if (index != -1) { if (index == text.length() -1) { text = text.substring(0, text.length()-1); // truncate string } else { text = text.substring(0, index) + text.substring(index+1); } ((IRestorableTextComponent)_theComponent).updateText( text); _beepHelper.beep(_theComponent); } e.consume(); } if ( ! ( Character.isDigit(c) || (c == '-') || (c == '+') || (c == 'e') || (c == 'E') || (c == 'f') || (c == 'F') || (c == '.') || (c == ',') || // several number formats use '.' as decimal separator, others use ',' (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE) ) ) { _beepHelper.beep(_theComponent); e.consume(); } // handle cases of null // The processing is different when nulls are allowed and when they are not. // if ( DataTypeFloat.this._isNullable) { // user enters something when field is null if (text.equals("<null>")) { if ((c==KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) { // delete when null => original value DataTypeFloat.this._textComponent.restoreText(); e.consume(); } else { // non-delete when null => clear field and add text DataTypeFloat.this._textComponent.updateText(""); // fall through to normal processing of this key stroke } } else { // check for user deletes last thing in field if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) { if (text.length() <= 1 ) { // about to delete last thing in field, so replace with null DataTypeFloat.this._textComponent.updateText("<null>"); e.consume(); } } } } else { // field is not nullable // handleNotNullableField(text, c, e, _textComponent); }
char c = e.getKeyChar(); // as a coding convenience, create a reference to the text component // that is typecast to JTextComponent. this is not essential, as we // could typecast every reference, but this makes the code cleaner JTextComponent _theComponent = (JTextComponent)DataTypeBinary.this._textComponent; String text = _theComponent.getText(); // tabs and newlines get put into the text before this check, // so remove them // This only applies to Popup editing since these chars are // not passed to this level by the in-cell editor. if (c == KeyEvent.VK_TAB || c == KeyEvent.VK_ENTER) { // remove all instances of the offending char int index = text.indexOf(c); if (index != -1) { if (index == text.length() -1) { text = text.substring(0, text.length()-1); // truncate string } else { text = text.substring(0, index) + text.substring(index+1); } ((IRestorableTextComponent)_theComponent).updateText( text); _beepHelper.beep(_theComponent); } e.consume(); } // handle cases of null // The processing is different when nulls are allowed and when they are not. // if ( DataTypeBinary.this._isNullable) { // user enters something when field is null if (text.equals("<null>")) { if ((c==KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) { // delete when null => original value DataTypeBinary.this._textComponent.restoreText(); e.consume(); } else { // non-delete when null => clear field and add text DataTypeBinary.this._textComponent.updateText(""); // fall through to normal processing of this key stroke } } else { // check for user deletes last thing in field if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) { if (text.length() <= 1 ) { // about to delete last thing in field, so replace with null DataTypeBinary.this._textComponent.updateText("<null>"); e.consume(); } } } } else { // field is not nullable // handleNotNullableField(text, c, e, _textComponent); }
Clone fragments detected by clone detection tool
File path: /sql12/fw/src/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeFloat.java File path: /sql12/fw/src/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeBinary.java
Method name: void keyTyped(KeyEvent) Method name: void keyTyped(KeyEvent)
Number of AST nodes: 26 Number of AST nodes: 23
1
char c = e.getKeyChar();
1
char c = e.getKeyChar();
2
            
2
				
3
// as a coding convenience, create a reference to the text component
3
				// as a coding convenience, create a reference to the text component
4
            // that is typecast to JTextComponent.  this is not essential, as we
4
				// that is typecast to JTextComponent.  this is not essential, as we
5
            // could typecast every reference, but this makes the code cleaner
5
				// could typecast every reference, but this makes the code cleaner
6
            JTextComponent _theComponent = (JTextComponent)DataTypeFloat.this._textComponent;
6
				JTextComponent _theComponent = (JTextComponent)DataTypeBinary.this._textComponent;
7
            String text = _theComponent.getText();
7
				String text = _theComponent.getText();
8
            
8
												
9
// tabs and newlines get put into the text before this check,
9
				// tabs and newlines get put into the text before this check,
10
            // so remove them
10
				// so remove them
11
            // This only applies to Popup editing since these chars are
11
				// This only applies to Popup editing since these chars are
12
            // not passed to this level by the in-cell editor.
12
				// not passed to this level by the in-cell editor.
13
            if (c == KeyEvent.VK_TAB || c == KeyEvent.VK_ENTER) {
13
				if (c == KeyEvent.VK_TAB || c == KeyEvent.VK_ENTER) {
14
               // remove all instances of the offending char
14
					// remove all instances of the offending char
15
               int index = text.indexOf(c);
15
					int index = text.indexOf(c);
16
               if (index != -1) {
16
					if (index != -1) {
17
	               if (index == text.length() -1) {
17
						if (index == text.length() -1) {
18
	                  text = text.substring(0, text.length()-1);	// truncate string
18
							text = text.substring(0, text.length()-1);	// truncate string
19
	               }
19
	
20
	               else {
21
	                  
20
					}
21
						else {
22
text = text.substring(0, index) + text.substring(index+1);
22
							text = text.substring(0, index) + text.substring(index+1);
23
	               }
23
	
24
	               
24
					}
25
((IRestorableTextComponent)_theComponent).updateText( text);
25
						((IRestorableTextComponent)_theComponent).updateText( text);
26
	               _beepHelper.beep(_theComponent);
26
						_beepHelper.beep(_theComponent);
27
               }
28
               e.consume();
29
            }
30
            if ( ! ( Character.isDigit(c) ||
31
               (c == '-') || (c == '+') ||
32
               (c == 'e') || (c == 'E') ||
33
               (c == 'f') || (c == 'F') ||
34
               (c == '.') || (c == ',') ||  // several number formats use '.' as decimal separator, others use ','
35
               (c == KeyEvent.VK_BACK_SPACE) ||
36
               (c == KeyEvent.VK_DELETE) ) ) {
37
            	_beepHelper.beep(_theComponent);
38
               e.consume();
39
            }
40
            
27
					}
28
					e.consume();
29
				}
41
// handle cases of null
30
				// handle cases of null
42
            // The processing is different when nulls are allowed and when they are not.
31
				// The processing is different when nulls are allowed and when they are not.
43
            //
44
            
32
				//
45
if ( DataTypeFloat.this._isNullable) {
33
				if ( DataTypeBinary.this._isNullable) {
46
               // user enters something when field is null
34
					// user enters something when field is null
47
               if (text.equals("<null>")) {
35
					if (text.equals("<null>")) {
48
                  if ((c==KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {
36
						if ((c==KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {
49
                     // delete when null => original value
37
							// delete when null => original value
50
                     DataTypeFloat.this._textComponent.restoreText();
38
							DataTypeBinary.this._textComponent.restoreText();
51
                     e.consume();
52
                  }
53
                  else {
54
                     
39
							e.consume();
40
						}
41
						else {
55
// non-delete when null => clear field and add text
42
							// non-delete when null => clear field and add text
56
                     DataTypeFloat.this._textComponent.updateText("");
43
							DataTypeBinary.this._textComponent.updateText("");
57
                     // fall through to normal processing of this key stroke
44
							// fall through to normal processing of this key stroke
58
                  }
59
               }
60
               else {
61
                  
45
						}
46
					}
47
					else {
62
// check for user deletes last thing in field
48
						// check for user deletes last thing in field
63
                  if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {
49
						if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {
64
                     if (text.length() <= 1 ) {
50
							if (text.length() <= 1 ) {
65
                        // about to delete last thing in field, so replace with null
51
								// about to delete last thing in field, so replace with null
66
                        DataTypeFloat.this._textComponent.updateText("<null>");
52
								DataTypeBinary.this._textComponent.updateText("<null>");
67
                        e.consume();
68
                     }
69
                  }
70
               }
71
            }
72
            
53
								e.consume();
54
							}
55
						}
56
					}
57
				}
73
else {
58
				else {
74
                    // field is not nullable
59
                    // field is not nullable
75
                    //
60
                    //
76
                    handleNotNullableField(text, c, e, _textComponent);
61
                    handleNotNullableField(text, c, e, _textComponent);
77
            }
62
				}
Summary
Number of common nesting structure subtrees1
Number of refactorable cases0
Number of non-refactorable cases1
Time elapsed for finding largest common nesting structure subtrees (ms)2.7
Clones locationClones are in different classes having the same super class
Number of node comparisons86
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements23
    Number of unmapped statements in the first code fragment3
    Number of unmapped statements in the second code fragment0
    Time elapsed for statement mapping (ms)17.3
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
    1
    char c = e.getKeyChar();
    1
    char c = e.getKeyChar();
    2
    JTextComponent _theComponent = (JTextComponent)DataTypeFloat.this._textComponent;
    2
    JTextComponent _theComponent = (JTextComponent)DataTypeFloat.this._textComponent;
    2
    JTextComponent _theComponent = (JTextComponent)DataTypeBinary.this._textComponent;
    Differences
    Expression1Expression2Difference
    net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeFloatnet.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeBinarySUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression DataTypeFloat cannot be unified with expression DataTypeBinary , because common superclass net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.BaseDataTypeComponent does not declare member(s) private net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.IRestorableTextComponent _textComponent
    2
    JTextComponent _theComponent = (JTextComponent)DataTypeBinary.this._textComponent;
    3
    String text = _theComponent.getText();
    3
    String text = _theComponent.getText();
    4
    if (c == KeyEvent.VK_TAB || c == KeyEvent.VK_ENTER)
    4
    if (c == KeyEvent.VK_TAB || c == KeyEvent.VK_ENTER)
    5
    int index = text.indexOf(c);
    5
    int index = text.indexOf(c);
    6
    if (index != -1)
    6
    if (index != -1)
    7
    if (index == text.length() - 1)
    7
    if (index == text.length() - 1)
    8
    text = text.substring(0, text.length() - 1);
    8
    text = text.substring(0, text.length() - 1);
    else
    else
    9
    text = text.substring(0, index) + text.substring(index + 1);
    9
    text = text.substring(0, index) + text.substring(index + 1);
    10
    ((IRestorableTextComponent)_theComponent).updateText(text);
    10
    ((IRestorableTextComponent)_theComponent).updateText(text);
    11
    _beepHelper.beep(_theComponent);
    11
    _beepHelper.beep(_theComponent);
    12
    e.consume();
    12
    e.consume();
    13
    if (!(Character.isDigit(c) || (c == '-') || (c == '+') || (c == 'e') || (c == 'E') || (c == 'f') || (c == 'F') || (c == '.') || (c == ',') || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)))
    13
    if (!(Character.isDigit(c) || (c == '-') || (c == '+') || (c == 'e') || (c == 'E') || (c == 'f') || (c == 'F') || (c == '.') || (c == ',') || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)))
    Preondition Violations
    Unmatched statement if(!(Character.isDigit(c) || (c == '-') || (c == '+')|| (c == 'e')|| (c == 'E')|| (c == 'f')|| (c == 'F')|| (c == '.')|| (c == ',')|| (c == KeyEvent.VK_BACK_SPACE)|| (c == KeyEvent.VK_DELETE))) cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                                                                                                                                                                                                                                                                                                                              
    14
    _beepHelper.beep(_theComponent);
    14
    _beepHelper.beep(_theComponent);
    Preondition Violations
    Unmatched statement _beepHelper.beep(_theComponent); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                            
    15
    e.consume();
                                    
    16
    if (DataTypeFloat.this._isNullable)
    16
    if (DataTypeFloat.this._isNullable)
    13
    if (DataTypeBinary.this._isNullable)
    Differences
    Expression1Expression2Difference
    net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeFloatnet.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeBinarySUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression DataTypeFloat cannot be unified with expression DataTypeBinary , because common superclass net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.BaseDataTypeComponent does not declare member(s) private boolean _isNullable
    13
    if (DataTypeBinary.this._isNullable)
    17
    if (text.equals("<null>"))
    14
    if (text.equals("<null>"))
    18
    if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE))
    15
    if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE))
    19
    DataTypeFloat.this._textComponent.restoreText();
    19
    DataTypeFloat.this._textComponent.restoreText();
    16
    DataTypeBinary.this._textComponent.restoreText();
    Differences
    Expression1Expression2Difference
    net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeFloatnet.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeBinarySUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression DataTypeFloat cannot be unified with expression DataTypeBinary , because common superclass net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.BaseDataTypeComponent does not declare member(s) private net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.IRestorableTextComponent _textComponent
    16
    DataTypeBinary.this._textComponent.restoreText();
    20
    e.consume();
    17
    e.consume();
    else
    else
    21
    DataTypeFloat.this._textComponent.updateText("");
    21
    DataTypeFloat.this._textComponent.updateText("");
    18
    DataTypeBinary.this._textComponent.updateText("");
    Differences
    Expression1Expression2Difference
    net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeFloatnet.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeBinarySUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression DataTypeFloat cannot be unified with expression DataTypeBinary , because common superclass net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.BaseDataTypeComponent does not declare member(s) private net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.IRestorableTextComponent _textComponent
    18
    DataTypeBinary.this._textComponent.updateText("");
    else
    else
    22
    if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE))
    19
    if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE))
    23
    if (text.length() <= 1)
    20
    if (text.length() <= 1)
    24
    DataTypeFloat.this._textComponent.updateText("<null>");
    24
    DataTypeFloat.this._textComponent.updateText("<null>");
    21
    DataTypeBinary.this._textComponent.updateText("<null>");
    Differences
    Expression1Expression2Difference
    net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeFloatnet.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeBinarySUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression DataTypeFloat cannot be unified with expression DataTypeBinary , because common superclass net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.BaseDataTypeComponent does not declare member(s) private net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.IRestorableTextComponent _textComponent
    21
    DataTypeBinary.this._textComponent.updateText("<null>");
    25
    e.consume();
    22
    e.consume();
    else
    else
    26
    handleNotNullableField(text, c, e, _textComponent);
    23
    handleNotNullableField(text, c, e, _textComponent);
    Precondition Violations (7)
    Row Violation
    1Expression DataTypeFloat cannot be unified with expression DataTypeBinary , because common superclass net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.BaseDataTypeComponent does not declare member(s) private net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.IRestorableTextComponent _textComponent
    2Unmatched statement if(!(Character.isDigit(c) || (c == '-') || (c == '+')|| (c == 'e')|| (c == 'E')|| (c == 'f')|| (c == 'F')|| (c == '.')|| (c == ',')|| (c == KeyEvent.VK_BACK_SPACE)|| (c == KeyEvent.VK_DELETE))) cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    3Unmatched statement _beepHelper.beep(_theComponent); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    4Expression DataTypeFloat cannot be unified with expression DataTypeBinary , because common superclass net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.BaseDataTypeComponent does not declare member(s) private boolean _isNullable
    5Expression DataTypeFloat cannot be unified with expression DataTypeBinary , because common superclass net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.BaseDataTypeComponent does not declare member(s) private net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.IRestorableTextComponent _textComponent
    6Expression DataTypeFloat cannot be unified with expression DataTypeBinary , because common superclass net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.BaseDataTypeComponent does not declare member(s) private net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.IRestorableTextComponent _textComponent
    7Expression DataTypeFloat cannot be unified with expression DataTypeBinary , because common superclass net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.BaseDataTypeComponent does not declare member(s) private net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.IRestorableTextComponent _textComponent