/** * 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); }
/** * Set up the list of external file types, either from default values, or from values * recorded in Preferences. */ public void updateExternalFileTypes() { // First get a list of the default file types as a starting point: List<ExternalFileType> types = getDefaultExternalFileTypes(); // If no changes have been stored, simply use the defaults: if (prefs.get("externalFileTypes", null) == null) { externalFileTypes.clear(); externalFileTypes.addAll(types); return; } // Read the prefs information for file types: String[][] vals = Util.decodeStringDoubleArray(prefs.get("externalFileTypes", "")); for (int i = 0; i < vals.length; i++) { if ((vals[i].length == 2) && (vals[i][1].equals(FILE_TYPE_REMOVED_FLAG))) { // This entry indicates that a default entry type should be removed: ExternalFileType toRemove = null; for (ExternalFileType type : types) { if (type.getName().equals(vals[i][0])) { toRemove = type; break; } } // If we found it, remove it from the type list: if (toRemove != null) types.remove(toRemove); } else { // A new or modified entry type. Construct it from the string array: ExternalFileType type = new ExternalFileType(vals[i]); // Check if there is a default type with the same name. If so, this is a // modification of that type, so remove the default one: ExternalFileType toRemove = null; for (ExternalFileType defType : types) { if (type.getName().equals(defType.getName())) { toRemove = defType; break; } } // If we found it, remove it from the type list: if (toRemove != null) { types.remove(toRemove); } // Then add the new one: types.add(type); } } // Finally, build the list of types based on the modified defaults list: for (ExternalFileType type : types) { externalFileTypes.add(type); } }
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 updateExternalFileTypes()
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
     * Set up the list of external file types, either from default values, or from values
3
     * @param name The file type name.
3
     * recorded in Preferences.
4
     * @return The ExternalFileType registered, or null if none.
4
     */
5
     */
5
    public void updateExternalFileTypes() {
6
    public ExternalFileType getExternalFileTypeByName(String name) {
6
        // First get a list of the default file types as a starting point:
7
        for (Iterator<ExternalFileType> iterator = externalFileTypes.iterator(); iterator.hasNext();) {
7
        List<ExternalFileType> types = getDefaultExternalFileTypes();
8
            ExternalFileType type = iterator.next();
8
        // If no changes have been stored, simply use the defaults:
9
            if (type.getName().equals(name))
9
        if (prefs.get("externalFileTypes", null) == null) {
10
                return type;
10
            externalFileTypes.clear();
11
        }
11
            externalFileTypes.addAll(types);
12
        // Return an instance that signifies an unknown file type:
12
            return;
13
        return new UnknownExternalFileType(name);
13
        }
14
    }
14
        // Read the prefs information for file types:
15
        String[][] vals = Util.decodeStringDoubleArray(prefs.get("externalFileTypes", ""));
16
        for (int i = 0; i < vals.length; i++) {
17
            if ((vals[i].length == 2) && (vals[i][1].equals(FILE_TYPE_REMOVED_FLAG))) {
18
                // This entry indicates that a default entry type should be removed:
19
                ExternalFileType toRemove = null;
20
                for (ExternalFileType type : types) {
21
                    if (type.getName().equals(vals[i][0])) {
22
                        toRemove = type;
23
                        break;
24
                    }
25
                }
26
                // If we found it, remove it from the type list:
27
                if (toRemove != null)
28
                    types.remove(toRemove);
29
            }
30
            else {
31
                // A new or modified entry type. Construct it from the string array:
32
                ExternalFileType type = new ExternalFileType(vals[i]);
33
                // Check if there is a default type with the same name. If so, this is a
34
                // modification of that type, so remove the default one:
35
                ExternalFileType toRemove = null;
36
                for (ExternalFileType defType : types) {
37
                    if (type.getName().equals(defType.getName())) {
38
                        toRemove = defType;
39
                        break;
40
                    }
41
                }
42
                // If we found it, remove it from the type list:
43
                if (toRemove != null) {
44
                    types.remove(toRemove);
45
                }
46
                
47
                // Then add the new one:
48
                types.add(type);
49
            }
50
        }
51
52
        // Finally, build the list of types based on the modified defaults list:
53
        for (ExternalFileType type : types) {
54
            externalFileTypes.add(type);
55
        }
56
    }
  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.429
    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(); )
    10
    for (ExternalFileType type : types)
    Differences
    Expression1Expression2Difference
    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 types
    • Make classes java.util.TreeSet and java.util.List extend a common superclass
    10
    for (ExternalFileType type : types)
    2
    ExternalFileType type = iterator.next();
                                                                                      
    3
    if (type.getName().equals(name))
    3
    if (type.getName().equals(name))
    11
    if (type.getName().equals(vals[i][0]))
    Differences
    Expression1Expression2Difference
    namevals[i][0]TYPE_COMPATIBLE_REPLACEMENT
    11
    if (type.getName().equals(vals[i][0]))
    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;
                                  
                                        
    12
    toRemove = type;
    Preondition Violations
    Unmatched statement toRemove=type; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    12
    toRemove = type;
                        
    13
    break;
    Preondition Violations
    Unmatched break;
    13
    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 types
    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 toRemove=type; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    5Unmatched break;