/** * @param list the JList to be sorted */ private void sortJListModel(JList list) { DefaultListModel model = (DefaultListModel) list.getModel(); List all = new ArrayList(); for (int i = 0; i < model.getSize(); i++) { all.add(model.getElementAt(i)); } model.clear(); Collections.sort(all, new Comparator() { public int compare(Object o1, Object o2) { return o1.toString().compareTo(o2.toString()); } }); for (Object obj : all) { model.addElement(obj); } }
/** * Returns the selected elements in the selected list * * @return List */ private List getSelectedChoices() { List result = new ArrayList(); for (int index : selectedList.getSelectedIndices()) { result.add(selectedList.getModel().getElementAt(index)); } return result; }
Clone fragments detected by clone detection tool
File path: /ArgoUML-0.34-src/argouml/src/argouml-app/src/org/argouml/ui/explorer/PerspectiveConfigurator.java File path: /ArgoUML-0.34-src/argouml/src/argouml-app/src/org/argouml/uml/ui/UMLAddDialog.java
Method name: void sortJListModel(JList) Method name: List getSelectedChoices()
Number of AST nodes: 2 Number of AST nodes: 2
1
/**
1
/**
2
     * @param list the JList to be sorted
2
     * Returns the selected elements in the selected list
3
     */
3
     *
4
    private void sortJListModel(JList list) {
4
     * @return List
5
        DefaultListModel model = (DefaultListModel) list.getModel();
5
     */
6
        List all = new ArrayList();
6
    private List getSelectedChoices() {
7
        for (int i = 0; i < model.getSize(); i++) {
7
        List result = new ArrayList();
8
            all.add(model.getElementAt(i));
8
        for (int index : selectedList.getSelectedIndices()) {
9
        }
9
            result.add(selectedList.getModel().getElementAt(index));
10
        model.clear();
10
        }
11
        Collections.sort(all, new Comparator() {
11
        return result;
12
            public int compare(Object o1, Object o2) {
12
    }
13
                return o1.toString().compareTo(o2.toString());
14
            }
15
        });
16
        for (Object obj : all) {
17
            model.addElement(obj);
18
        }
19
    }
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements2
    Number of unmapped statements in the first code fragment0
    Number of unmapped statements in the second code fragment0
    Time elapsed for statement mapping (ms)0.0
    Similarity Score0.375
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    3
    for (int i = 0; i < model.getSize(); i++)
    3
    for (int i = 0; i < model.getSize(); i++)
    2
    for (int index : selectedList.getSelectedIndices())
    Differences
    Expression1Expression2Difference
    javax.swing.DefaultListModelint[]VARIABLE_TYPE_MISMATCH
    javax.swing.DefaultListModelint[]VARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type javax.swing.DefaultListModel of variable model does not match with type int[] of variable selectedList.getSelectedIndices()
    • Make classes javax.swing.DefaultListModel and int[] extend a common superclass
    Type javax.swing.DefaultListModel of variable model does not match with type int[] of variable selectedList.getSelectedIndices()
    • Make classes javax.swing.DefaultListModel and int[] extend a common superclass
    2
    for (int index : selectedList.getSelectedIndices())
    4
    all.add(model.getElementAt(i));
    4
    all.add(model.getElementAt(i));
    3
    result.add(selectedList.getModel().getElementAt(index));
    Differences
    Expression1Expression2Difference
    iindexVARIABLE_NAME_MISMATCH
    modelselectedList.getModel()TYPE_COMPATIBLE_REPLACEMENT
    allresultVARIABLE_NAME_MISMATCH
    Preondition Violations
    Expression i cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression index cannot be parameterized, because it has dependencies to/from statements that will be extracted
    3
    result.add(selectedList.getModel().getElementAt(index));
    Precondition Violations (4)
    Row Violation
    1Type javax.swing.DefaultListModel of variable model does not match with type int[] of variable selectedList.getSelectedIndices()
    2Type javax.swing.DefaultListModel of variable model does not match with type int[] of variable selectedList.getSelectedIndices()
    3Expression i cannot be parameterized, because it has dependencies to/from statements that will be extracted
    4Expression index cannot be parameterized, because it has dependencies to/from statements that will be extracted