/** * To simplify implementation, we list all associations * found with any of the Classifiers * represented by the linked Instances. <p> * * TODO: Make a foolproof algorithm that only allows selecting associations * that create a correct model. Also take into account n-ary associations * and associationclasses. This algo best goes in the model subsystem, e.g. * in a method getAllPossibleAssociationsForALink(). * * @see org.argouml.uml.ui.UMLComboBoxModel#buildModelList() */ protected void buildModelList() { Collection linkEnds; Collection associations = new HashSet(); Object t = getTarget(); if (Model.getFacade().isALink(t)) { linkEnds = Model.getFacade().getConnections(t); Iterator ile = linkEnds.iterator(); while (ile.hasNext()) { Object instance = Model.getFacade().getInstance(ile.next()); Collection c = Model.getFacade().getClassifiers(instance); Iterator ic = c.iterator(); while (ic.hasNext()) { Object classifier = ic.next(); Collection ae = Model.getFacade().getAssociationEnds(classifier); Iterator iae = ae.iterator(); while (iae.hasNext()) { Object associationEnd = iae.next(); Object association = Model.getFacade().getAssociation(associationEnd); associations.add(association); } } } } setElements(associations); }
/** * Return all edges going to given port.<p> * * The only objects with ports on the use case diagram are actors * and use cases. In each case we find the attached association * ends, and build a list of them as the incoming ports.<p> * * @param port The port for which we want to know the incoming edges. * * @return A list of objects which are the incoming edges. */ public List getInEdges(Object port) { if (Model.getFacade().isAActor(port) || Model.getFacade().isAUseCase(port)) { List result = new ArrayList(); Collection ends = Model.getFacade().getAssociationEnds(port); if (ends == null) { return Collections.EMPTY_LIST; } for (Object ae : ends) { result.add(Model.getFacade().getAssociation(ae)); } return result; } return Collections.EMPTY_LIST; }
Clone fragments detected by clone detection tool
File path: /ArgoUML-0.34-src/argouml/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLLinkAssociationComboBoxModel.java File path: /ArgoUML-0.34-src/argouml/src/argouml-app/src/org/argouml/uml/diagram/use_case/UseCaseDiagramGraphModel.java
Method name: void buildModelList() Method name: List getInEdges(Object)
Number of AST nodes: 4 Number of AST nodes: 2
1
/**
1
/**
2
     * To simplify implementation, we list all associations
2
     * Return all edges going to given port.<p>
3
     * found with any of the Classifiers
3
     *
4
     * represented by the linked Instances. <p>
4
     * The only objects with ports on the use case diagram are actors
5
     *
5
     * and use cases.  In each case we find the attached association
6
     * TODO: Make a foolproof algorithm that only allows selecting associations
6
     * ends, and build a list of them as the incoming ports.<p>
7
     * that create a correct model. Also take into account n-ary associations
7
     *
8
     * and associationclasses. This algo best goes in the model subsystem, e.g.
8
     * @param port  The port for which we want to know the incoming edges.
9
     * in a method getAllPossibleAssociationsForALink().
9
     *
10
     *
10
     * @return      A list of objects which are the incoming edges.
11
     * @see org.argouml.uml.ui.UMLComboBoxModel#buildModelList()
11
     */
12
     */
12
    public List getInEdges(Object port) {
13
    protected void buildModelList() {
13
        if (Model.getFacade().isAActor(port) 
14
        Collection linkEnds;
14
                || Model.getFacade().isAUseCase(port)) {
15
        Collection associations = new HashSet();
15
            List result = new ArrayList();
16
        Object t = getTarget();
16
            Collection ends = Model.getFacade().getAssociationEnds(port);
17
        if (Model.getFacade().isALink(t)) {
17
            if (ends == null) {
18
            linkEnds = Model.getFacade().getConnections(t);
18
                return Collections.EMPTY_LIST;
19
            Iterator ile = linkEnds.iterator();
19
            }
20
            while (ile.hasNext()) {
20
            for (Object ae : ends) {
21
                Object instance = Model.getFacade().getInstance(ile.next());
21
                result.add(Model.getFacade().getAssociation(ae));
22
                Collection c = Model.getFacade().getClassifiers(instance);
22
            }
23
                Iterator ic = c.iterator();
23
            return result;
24
                while (ic.hasNext()) {
24
        }
25
                    Object classifier = ic.next();
25
        return Collections.EMPTY_LIST;
26
                    Collection ae =
26
    }
27
                        Model.getFacade().getAssociationEnds(classifier);
28
                    Iterator iae = ae.iterator();
29
                    while (iae.hasNext()) {
30
                        Object associationEnd = iae.next();
31
                        Object association =
32
                            Model.getFacade().getAssociation(associationEnd);
33
                        associations.add(association);
34
                    }
35
                }
36
            }
37
        }
38
        setElements(associations);
39
    }
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements3
    Number of unmapped statements in the first code fragment2
    Number of unmapped statements in the second code fragment1
    Time elapsed for statement mapping (ms)0.0
    Similarity Score1.000
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
    15
    while (iae.hasNext())
    15
    while (iae.hasNext())
    6
    for (Object ae : ends)
    Differences
    Expression1Expression2Difference
    associationEndaeVARIABLE_NAME_MISMATCH
    6
    for (Object ae : ends)
                                                                                                            
    7
    result.add(Model.getFacade().getAssociation(ae));
    Preondition Violations
    Unmatched statement result.add(Model.getFacade().getAssociation(ae)); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    7
    result.add(Model.getFacade().getAssociation(ae));
    16
    Object associationEnd = iae.next();
    16
    Object associationEnd = iae.next();
    Differences
    Expression1Expression2Difference
    associationEndaeVARIABLE_NAME_MISMATCH
                                                                              
    17
    Object association = Model.getFacade().getAssociation(associationEnd);
    17
    Object association = Model.getFacade().getAssociation(associationEnd);
    Preondition Violations
    Unmatched statement Object association=Model.getFacade().getAssociation(associationEnd); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                                                                    
    18
    associations.add(association);
                                                                        
    Precondition Violations (2)
    Row Violation
    1Unmatched statement result.add(Model.getFacade().getAssociation(ae)); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    2Unmatched statement Object association=Model.getFacade().getAssociation(associationEnd); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted