/** * @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 choices a user can make. * @return List of choices */ private List getChoices() { List result = new ArrayList(); for (int index : choicesList.getSelectedIndices()) { result.add(choicesList.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 getChoices()
Number of AST nodes: 2 Number of AST nodes: 2
1
/**
1
/**
2
     * @param list the JList to be sorted
2
     * Returns the choices a user can make.
3
     */
3
     * @return List of choices
4
    private void sortJListModel(JList list) {
4
     */
5
        DefaultListModel model = (DefaultListModel) list.getModel();
5
    private List getChoices() {
6
        List all = new ArrayList();
6
        List result = new ArrayList();
7
        for (int i = 0; i < model.getSize(); i++) {
7
        for (int index : choicesList.getSelectedIndices()) {
8
            all.add(model.getElementAt(i));
8
            result.add(choicesList.getModel().getElementAt(index));
9
        }
9
        }
10
        model.clear();
10
        return result;
11
        Collections.sort(all, new Comparator() {
11
    }
12
            public int compare(Object o1, Object o2) {
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 : choicesList.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 choicesList.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 choicesList.getSelectedIndices()
    • Make classes javax.swing.DefaultListModel and int[] extend a common superclass
    2
    for (int index : choicesList.getSelectedIndices())
    4
    all.add(model.getElementAt(i));
    4
    all.add(model.getElementAt(i));
    3
    result.add(choicesList.getModel().getElementAt(index));
    Differences
    Expression1Expression2Difference
    iindexVARIABLE_NAME_MISMATCH
    modelchoicesList.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(choicesList.getModel().getElementAt(index));
    Precondition Violations (4)
    Row Violation
    1Type javax.swing.DefaultListModel of variable model does not match with type int[] of variable choicesList.getSelectedIndices()
    2Type javax.swing.DefaultListModel of variable model does not match with type int[] of variable choicesList.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