/** * Look up the external file type registered with this name, if any. * @param name The file type name. * @return The ExternalFileType registered, or null if none. */ public ExternalFileType getExternalFileTypeByName(String name) { for (Iterator<ExternalFileType> iterator = externalFileTypes.iterator(); iterator.hasNext();) { ExternalFileType type = iterator.next(); if (type.getName().equals(name)) return type; } // Return an instance that signifies an unknown file type: return new UnknownExternalFileType(name); }
/** * Reset the List of external file types after user customization. * @param types The new List of external file types. This is the complete list, not * just new entries. */ public void setExternalFileTypes(List<ExternalFileType> types) { // First find a list of the default types: List<ExternalFileType> defTypes = getDefaultExternalFileTypes(); // Make a list of types that are unchanged: List<ExternalFileType> unchanged = new ArrayList<ExternalFileType>(); externalFileTypes.clear(); for (Iterator<ExternalFileType> iterator = types.iterator(); iterator.hasNext();) { ExternalFileType type = iterator.next(); externalFileTypes.add(type); // See if we can find a type with matching name in the default type list: ExternalFileType found = null; for (ExternalFileType defType : defTypes) { if (defType.getName().equals(type.getName())) { found = defType; break; } } if (found != null) { // Found it! Check if it is an exact match, or if it has been customized: if (found.equals(type)) unchanged.add(type); else { // It was modified. Remove its entry from the defaults list, since // the type hasn't been removed: defTypes.remove(found); } } } // Go through unchanged types. Remove them from the ones that should be stored, // and from the list of defaults, since we don't need to mention these in prefs: for (ExternalFileType type : unchanged) { defTypes.remove(type); types.remove(type); } // Now set up the array to write to prefs, containing all new types, all modified // types, and a flag denoting each default type that has been removed: String[][] array = new String[types.size()+defTypes.size()][]; int i=0; for (ExternalFileType type : types) { array[i] = type.getStringArrayRepresentation(); i++; } for (ExternalFileType type : defTypes) { array[i] = new String[] {type.getName(), FILE_TYPE_REMOVED_FLAG}; i++; } //System.out.println("Encoded: '"+Util.encodeStringArray(array)+"'"); put("externalFileTypes", Util.encodeStringArray(array)); }
Clone fragments detected by clone detection tool
File path: /jabref-2.10/src/java/net/sf/jabref/JabRefPreferences.java File path: /jabref-2.10/src/java/net/sf/jabref/JabRefPreferences.java
Method name: ExternalFileType getExternalFileTypeByName(String) Method name: void setExternalFileTypes(List)
Number of AST nodes: 4 Number of AST nodes: 4
1
/**
1
/**
2
     * Look up the external file type registered with this name, if any.
2
     * Reset the List of external file types after user customization.
3
     * @param name The file type name.
3
     * @param types The new List of external file types. This is the complete list, not
4
     * @return The ExternalFileType registered, or null if none.
4
     *  just new entries.
5
     */
5
     */
6
    public ExternalFileType getExternalFileTypeByName(String name) {
6
    public void setExternalFileTypes(List<ExternalFileType> types) {
7
        for (Iterator<ExternalFileType> iterator = externalFileTypes.iterator(); iterator.hasNext();) {
7
8
            ExternalFileType type = iterator.next();
8
        // First find a list of the default types:
9
            if (type.getName().equals(name))
9
        List<ExternalFileType> defTypes = getDefaultExternalFileTypes();
10
                return type;
10
        // Make a list of types that are unchanged:
11
        }
11
        List<ExternalFileType> unchanged = new ArrayList<ExternalFileType>();
12
        // Return an instance that signifies an unknown file type:
12
13
        return new UnknownExternalFileType(name);
13
        externalFileTypes.clear();
14
    }
14
        for (Iterator<ExternalFileType> iterator = types.iterator(); iterator.hasNext();) {
15
            ExternalFileType type = iterator.next();
16
            externalFileTypes.add(type);
17
18
            // See if we can find a type with matching name in the default type list:
19
            ExternalFileType found = null;
20
            for (ExternalFileType defType : defTypes) {
21
                if (defType.getName().equals(type.getName())) {
22
                    found = defType;
23
                    break;
24
                }
25
            }
26
            if (found != null) {
27
                // Found it! Check if it is an exact match, or if it has been customized:
28
                if (found.equals(type))
29
                    unchanged.add(type);
30
                else {
31
                    // It was modified. Remove its entry from the defaults list, since
32
                    // the type hasn't been removed:
33
                    defTypes.remove(found);
34
                }
35
            }
36
        }
37
38
        // Go through unchanged types. Remove them from the ones that should be stored,
39
        // and from the list of defaults, since we don't need to mention these in prefs:
40
        for (ExternalFileType type : unchanged) {
41
            defTypes.remove(type);
42
            types.remove(type);
43
        }
44
45
        // Now set up the array to write to prefs, containing all new types, all modified
46
        // types, and a flag denoting each default type that has been removed:
47
        String[][] array = new String[types.size()+defTypes.size()][];
48
        int i=0;
49
        for (ExternalFileType type : types) {
50
            array[i] = type.getStringArrayRepresentation();
51
            i++;
52
        }
53
        for (ExternalFileType type : defTypes) {
54
            array[i] = new String[] {type.getName(), FILE_TYPE_REMOVED_FLAG};
55
            i++;
56
        }
57
        //System.out.println("Encoded: '"+Util.encodeStringArray(array)+"'");
58
        put("externalFileTypes", Util.encodeStringArray(array));
59
    }
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements3
    Number of unmapped statements in the first code fragment1
    Number of unmapped statements in the second code fragment2
    Time elapsed for statement mapping (ms)0.0
    Similarity Score0.600
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
    1
    for (Iterator<ExternalFileType> iterator = externalFileTypes.iterator(); iterator.hasNext(); )
    1
    for (Iterator<ExternalFileType> iterator = externalFileTypes.iterator(); iterator.hasNext(); )
    8
    for (ExternalFileType defType : defTypes)
    Differences
    Expression1Expression2Difference
    typedefTypeVARIABLE_NAME_MISMATCH
    java.util.TreeSetjava.util.ListVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type java.util.TreeSet<net.sf.jabref.external.ExternalFileType> of variable externalFileTypes does not match with type java.util.List<net.sf.jabref.external.ExternalFileType> of variable defTypes
    • Make classes java.util.TreeSet and java.util.List extend a common superclass
    8
    for (ExternalFileType defType : defTypes)
    2
    ExternalFileType type = iterator.next();
    2
    ExternalFileType type = iterator.next();
    Differences
    Expression1Expression2Difference
    typedefTypeVARIABLE_NAME_MISMATCH
                                                                                      
    3
    if (type.getName().equals(name))
    3
    if (type.getName().equals(name))
    9
    if (defType.getName().equals(type.getName()))
    Differences
    Expression1Expression2Difference
    nametype.getName()TYPE_COMPATIBLE_REPLACEMENT
    typedefTypeVARIABLE_NAME_MISMATCH
    9
    if (defType.getName().equals(type.getName()))
    4
    return type;
    4
    return type;
    Preondition Violations
    Unmatched statement return type; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    Unmatched return type;
                                  
                                        
    10
    found = defType;
    Preondition Violations
    Unmatched statement found=defType; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    10
    found = defType;
                        
    11
    break;
    Preondition Violations
    Unmatched break;
    11
    break;
    Precondition Violations (5)
    Row Violation
    1Type java.util.TreeSet<net.sf.jabref.external.ExternalFileType> of variable externalFileTypes does not match with type java.util.List<net.sf.jabref.external.ExternalFileType> of variable defTypes
    2Unmatched statement return type; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    3Unmatched return type;
    4Unmatched statement found=defType; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    5Unmatched break;