/** * Implements grammer rule "Authors" * * @param be * @throws IOException */ private void parseAuthors(BibtexEntry be) throws IOException { // read authors and institutions String authors = ""; String institutions = ""; while (this.lastLine != null && !this.lastLine.equals("") && !startsWithKeyword(recognizedFields)) { // read single author String author = null; String institution = null; boolean institutionDone = false; if (this.lastLine.indexOf('(') >= 0) { author = this.lastLine.substring(0, this.lastLine.indexOf('(')).trim(); institutionDone = this.lastLine.indexOf(')') > 0; institution = this.lastLine.substring(this.lastLine.indexOf('(') + 1, institutionDone && this.lastLine.indexOf(')') > this.lastLine.indexOf('(') + 1 ? this.lastLine.indexOf(')') : this.lastLine.length()).trim(); } else { author = this.lastLine.substring(0, this.lastLine.length()).trim(); institutionDone = true; } readLine(); while (!institutionDone && this.lastLine!= null) { institutionDone = this.lastLine.indexOf(')') > 0; institution += this.lastLine.substring(0, institutionDone ? this.lastLine.indexOf(')') : this.lastLine.length()).trim(); readLine(); } if (author != null) { authors += !authors.equals("") ? " and " + author : "" + author; } if (institution != null) { institutions += !institutions.equals("") ? " and " + institution : "" + institution; } } if (!authors.equals("")) { be.setField("author", authors); } if (!institutions.equals("")) { be.setField("institution", institutions); } }
/** * Parse the entries in the source, and return a List of BibtexEntry * objects. */ public List<BibtexEntry> importEntries(InputStream stream, OutputPrinter status) throws IOException { ArrayList<BibtexEntry> bibitems = new ArrayList<BibtexEntry>(); StringBuffer sb = new StringBuffer(); BufferedReader in = new BufferedReader(ImportFormatReader.getReaderDefaultEncoding(stream)); String ENDOFRECORD = "__EOREOR__"; String str; boolean first = true; while ((str = in.readLine()) != null){ str = str.trim(); // if(str.equals("")) continue; if (str.indexOf("%0") == 0){ if (first){ first = false; }else{ sb.append(ENDOFRECORD); } sb.append(str); }else sb.append(str); sb.append("\n"); } String[] entries = sb.toString().split(ENDOFRECORD); HashMap<String, String> hm = new HashMap<String, String>(); String author = "", Type = "", editor = "", artnum = ""; for (int i = 0; i < entries.length; i++){ hm.clear(); author = ""; Type = ""; editor = ""; artnum = ""; boolean IsEditedBook = false; String[] fields = entries[i].trim().substring(1).split("\n%"); //String lastPrefix = ""; for (int j = 0; j < fields.length; j++){ if (fields[j].length() < 3) continue; /* * Details of Refer format for Journal Article and Book: * * Generic Ref Journal Article Book Code Author %A Author Author Year %D * Year Year Title %T Title Title Secondary Author %E Series Editor * Secondary Title %B Journal Series Title Place Published %C City * Publisher %I Publisher Volume %V Volume Volume Number of Volumes %6 * Number of Volumes Number %N Issue Pages %P Pages Number of Pages * Edition %7 Edition Subsidiary Author %? Translator Alternate Title %J * Alternate Journal Label %F Label Label Keywords %K Keywords Keywords * Abstract %X Abstract Abstract Notes %O Notes Notes */ String prefix = fields[j].substring(0, 1); String val = fields[j].substring(2); if (prefix.equals("A")){ if (author.equals("")) author = val; else author += " and " + val; }else if (prefix.equals("E")){ if (editor.equals("")) editor = val; else editor += " and " + val; }else if (prefix.equals("T")) hm.put("title", val); else if (prefix.equals("0")){ if (val.indexOf("Journal") == 0) Type = "article"; else if ((val.indexOf("Book Section") == 0)) Type = "incollection"; else if ((val.indexOf("Book") == 0)) Type = "book"; else if (val.indexOf("Edited Book") == 0) { Type = "book"; IsEditedBook = true; }else if (val.indexOf("Conference") == 0) // Proceedings Type = "inproceedings"; else if (val.indexOf("Report") == 0) // Techreport Type = "techreport"; else if (val.indexOf("Review") == 0) Type = "article"; else if (val.indexOf("Thesis") == 0) Type = "phdthesis"; else Type = "misc"; // }else if (prefix.equals("7")) hm.put("edition", val); else if (prefix.equals("C")) hm.put("address", val); else if (prefix.equals("D")) hm.put("year", val); else if (prefix.equals("8")) hm.put("date", val); else if (prefix.equals("J")){ // "Alternate journal. Let's set it only if no journal // has been set with %B. if (hm.get("journal") == null) hm.put("journal", val); }else if (prefix.equals("B")){ // This prefix stands for "journal" in a journal entry, and // "series" in a book entry. if (Type.equals("article")) hm.put("journal", val); else if (Type.equals("book") || Type.equals("inbook")) hm.put( "series", val); else /* if (Type.equals("inproceedings")) */ hm.put("booktitle", val); }else if (prefix.equals("I")) { if (Type.equals("phdthesis")) hm.put("school", val); else hm.put("publisher", val); } // replace single dash page ranges (23-45) with double dashes (23--45): else if (prefix.equals("P")) hm.put("pages", val.replaceAll("([0-9]) *- *([0-9])","$1--$2")); else if (prefix.equals("V")) hm.put("volume", val); else if (prefix.equals("N")) hm.put("number", val); else if (prefix.equals("U")) hm.put("url", val); else if (prefix.equals("R")) { String doi = val; if (doi.startsWith("doi:")) doi = doi.substring(4); hm.put("doi", doi); } else if (prefix.equals("O")) { // Notes may contain Article number if (val.startsWith("Artn")) { String[] tokens = val.split("\\s"); artnum = tokens[1]; } else { hm.put("note", val); } } else if (prefix.equals("K")) hm.put("keywords", val); else if (prefix.equals("X")) hm.put("abstract", val); else if (prefix.equals("9")){ //Util.pr(val); if (val.indexOf("Ph.D.") == 0) Type = "phdthesis"; if (val.indexOf("Masters") == 0) Type = "mastersthesis"; }else if (prefix.equals("F")) hm.put(BibtexFields.KEY_FIELD, Util .checkLegalKey(val)); } // For Edited Book, EndNote puts the editors in the author field. // We want them in the editor field so that bibtex knows it's an edited book if (IsEditedBook && editor.equals("")) { editor = author; author = ""; } //fixauthorscomma if (!author.equals("")) hm.put("author", fixAuthor(author)); if (!editor.equals("")) hm.put("editor", fixAuthor(editor)); //if pages missing and article number given, use the article number if (((hm.get("pages") == null) || hm.get("pages").equals("-")) && !artnum.equals("")) hm.put("pages", artnum); BibtexEntry b = new BibtexEntry(BibtexFields.DEFAULT_BIBTEXENTRY_ID, Globals .getEntryType(Type)); // id assumes an existing database so don't // create one here b.setField(hm); //if (hm.isEmpty()) if (b.getAllFields().size() > 0) bibitems.add(b); } return bibitems; }
Clone fragments detected by clone detection tool
File path: /jabref-2.10/src/java/net/sf/jabref/imports/RepecNepImporter.java File path: /jabref-2.10/src/java/net/sf/jabref/imports/EndnoteImporter.java
Method name: void parseAuthors(BibtexEntry) Method name: List importEntries(InputStream, OutputPrinter)
Number of AST nodes: 1 Number of AST nodes: 3
1
/**
1
/**
2
   * Implements grammer rule "Authors"
2
     * Parse the entries in the source, and return a List of BibtexEntry
3
   * 
3
     * objects.
4
   * @param be
4
     */
5
   * @throws IOException
5
    public List<BibtexEntry> importEntries(InputStream stream, OutputPrinter status) throws IOException {
6
   */
6
    ArrayList<BibtexEntry> bibitems = new ArrayList<BibtexEntry>();
7
  private void parseAuthors(BibtexEntry be) throws IOException {
7
    StringBuffer sb = new StringBuffer();
8
    // read authors and institutions
8
    BufferedReader in = new BufferedReader(ImportFormatReader.getReaderDefaultEncoding(stream));
9
    String authors = "";
9
    String ENDOFRECORD = "__EOREOR__";
10
    String institutions = "";
10
11
    while (this.lastLine != null && !this.lastLine.equals("") && !startsWithKeyword(recognizedFields)) {
11
    String str;
12
      
12
    boolean first = true;
13
      // read single author
13
    while ((str = in.readLine()) != null){
14
      String author = null;
14
        str = str.trim();
15
      String institution = null;
15
        // if(str.equals("")) continue;
16
      boolean institutionDone = false;
16
        if (str.indexOf("%0") == 0){
17
      if (this.lastLine.indexOf('(') >= 0) {
17
        if (first){
18
        author = this.lastLine.substring(0, this.lastLine.indexOf('(')).trim();
18
            first = false;
19
        institutionDone = this.lastLine.indexOf(')') > 0;
19
        }else{
20
        institution = this.lastLine.substring(this.lastLine.indexOf('(') + 1, institutionDone && this.lastLine.indexOf(')') > this.lastLine.indexOf('(') + 1 ? this.lastLine.indexOf(')') : this.lastLine.length()).trim();
20
            sb.append(ENDOFRECORD);
21
      } else {
21
        }
22
        author = this.lastLine.substring(0, this.lastLine.length()).trim();
22
        sb.append(str);
23
        institutionDone = true;
23
        }else sb.append(str);
24
      }
24
        sb.append("\n");
25
      
25
    }
26
      readLine();
26
27
      while (!institutionDone && this.lastLine!= null) {
27
    String[] entries = sb.toString().split(ENDOFRECORD);
28
        institutionDone = this.lastLine.indexOf(')') > 0;
28
    HashMap<String, String> hm = new HashMap<String, String>();
29
        institution += this.lastLine.substring(0, institutionDone ? this.lastLine.indexOf(')') : this.lastLine.length()).trim();
29
    String author = "", Type = "", editor = "", artnum = "";
30
        readLine();
30
    for (int i = 0; i < entries.length; i++){
31
      }
31
        hm.clear();
32
      
32
        author = "";
33
      if (author != null) {
33
        Type = "";
34
        authors += !authors.equals("") ? " and " + author : "" + author;
34
        editor = "";
35
      }
35
        artnum = "";
36
      if (institution != null) {
36
37
        institutions += !institutions.equals("") ? " and " + institution : "" + institution;
37
        boolean IsEditedBook = false;
38
      }            
38
        String[] fields = entries[i].trim().substring(1).split("\n%");
39
    }
39
        //String lastPrefix = "";
40
    
40
        for (int j = 0; j < fields.length; j++){
41
    if (!authors.equals("")) {
41
42
      be.setField("author", authors);
42
        if (fields[j].length() < 3) continue;
43
    }
43
44
    if (!institutions.equals("")) {
44
        /*
45
      be.setField("institution", institutions);
45
           * Details of Refer format for Journal Article and Book:
46
    }
46
           *
47
  }
47
           * Generic Ref Journal Article Book Code Author %A Author Author Year %D
48
           * Year Year Title %T Title Title Secondary Author %E Series Editor
49
           * Secondary Title %B Journal Series Title Place Published %C City
50
           * Publisher %I Publisher Volume %V Volume Volume Number of Volumes %6
51
           * Number of Volumes Number %N Issue Pages %P Pages Number of Pages
52
           * Edition %7 Edition Subsidiary Author %? Translator Alternate Title %J
53
           * Alternate Journal Label %F Label Label Keywords %K Keywords Keywords
54
           * Abstract %X Abstract Abstract Notes %O Notes Notes
55
           */
56
57
        String prefix = fields[j].substring(0, 1);
58
59
        String val = fields[j].substring(2);
60
61
        if (prefix.equals("A")){
62
            if (author.equals("")) author = val;
63
            else author += " and " + val;
64
        }else if (prefix.equals("E")){
65
            if (editor.equals("")) editor = val;
66
            else editor += " and " + val;
67
        }else if (prefix.equals("T")) hm.put("title", val);
68
        else if (prefix.equals("0")){
69
            if (val.indexOf("Journal") == 0) Type = "article";
70
            else if ((val.indexOf("Book Section") == 0)) Type = "incollection";
71
            else if ((val.indexOf("Book") == 0)) Type = "book";
72
            else if (val.indexOf("Edited Book") == 0) {
73
                Type = "book";
74
                IsEditedBook = true;
75
            }else if (val.indexOf("Conference") == 0) // Proceedings
76
            Type = "inproceedings";
77
            else if (val.indexOf("Report") == 0) // Techreport
78
            Type = "techreport";
79
            else if (val.indexOf("Review") == 0)
80
                Type = "article";
81
            else if (val.indexOf("Thesis") == 0)
82
                Type = "phdthesis";
83
            else Type = "misc"; //
84
        }else if (prefix.equals("7")) hm.put("edition", val);
85
        else if (prefix.equals("C")) hm.put("address", val);
86
        else if (prefix.equals("D")) hm.put("year", val);
87
        else if (prefix.equals("8")) hm.put("date", val);
88
        else if (prefix.equals("J")){
89
            // "Alternate journal. Let's set it only if no journal
90
            // has been set with %B.
91
            if (hm.get("journal") == null) hm.put("journal", val);
92
        }else if (prefix.equals("B")){
93
            // This prefix stands for "journal" in a journal entry, and
94
            // "series" in a book entry.
95
            if (Type.equals("article")) hm.put("journal", val);
96
            else if (Type.equals("book") || Type.equals("inbook")) hm.put(
97
                                          "series", val);
98
            else /* if (Type.equals("inproceedings")) */
99
            hm.put("booktitle", val);
100
        }else if (prefix.equals("I")) {
101
            if (Type.equals("phdthesis"))
102
                hm.put("school", val);
103
            else
104
                 hm.put("publisher", val);
105
        }
106
            // replace single dash page ranges (23-45) with double dashes (23--45):
107
        else if (prefix.equals("P")) hm.put("pages", val.replaceAll("([0-9]) *- *([0-9])","$1--$2"));
108
        else if (prefix.equals("V")) hm.put("volume", val);
109
        else if (prefix.equals("N")) hm.put("number", val);
110
        else if (prefix.equals("U")) hm.put("url", val);
111
        else if (prefix.equals("R")) {
112
            String doi = val;
113
            if (doi.startsWith("doi:"))
114
                doi = doi.substring(4);
115
            hm.put("doi", doi);
116
        }
117
        else if (prefix.equals("O")) {
118
	    // Notes may contain Article number
119
	    if (val.startsWith("Artn")) {
120
		String[] tokens = val.split("\\s");
121
		artnum = tokens[1];
122
	    }
123
	    else {
124
		hm.put("note", val);
125
	    }
126
	}
127
        else if (prefix.equals("K")) hm.put("keywords", val);
128
        else if (prefix.equals("X")) hm.put("abstract", val);
129
        else if (prefix.equals("9")){
130
            //Util.pr(val);
131
            if (val.indexOf("Ph.D.") == 0) Type = "phdthesis";
132
            if (val.indexOf("Masters") == 0) Type = "mastersthesis";
133
        }else if (prefix.equals("F")) hm.put(BibtexFields.KEY_FIELD, Util
134
                             .checkLegalKey(val));
135
        }
136
137
        // For Edited Book, EndNote puts the editors in the author field.
138
        // We want them in the editor field so that bibtex knows it's an edited book
139
        if (IsEditedBook && editor.equals("")) {
140
           editor = author;
141
           author = "";
142
        }
143
144
        //fixauthorscomma
145
        if (!author.equals("")) hm.put("author", fixAuthor(author));
146
        if (!editor.equals("")) hm.put("editor", fixAuthor(editor));
147
        //if pages missing and article number given, use the article number
148
        if (((hm.get("pages") == null) || hm.get("pages").equals("-")) && !artnum.equals(""))
149
            hm.put("pages", artnum);
150
151
        BibtexEntry b = new BibtexEntry(BibtexFields.DEFAULT_BIBTEXENTRY_ID, Globals
152
                        .getEntryType(Type)); // id assumes an existing database so don't
153
        // create one here
154
        b.setField(hm);
155
        //if (hm.isEmpty())
156
        if (b.getAllFields().size() > 0)
157
        	bibitems.add(b);
158
159
    }
160
    return bibitems;
161
162
    }
  1. {Refactorable}
    Mapping Summary
    Number of mapped statements3
    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 Score1.000
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    21
    institutions += !institutions.equals("") ? " and " + institution : "" + institution;
    21
    institutions += !institutions.equals("") ? " and " + institution : "" + institution;
    33
    if (author.equals(""))
    Differences
    Expression1Expression2Difference
    !institutions.equals("")author.equals("")TYPE_COMPATIBLE_REPLACEMENT
    institutionsauthorVARIABLE_NAME_MISMATCH
    institutionsauthorVARIABLE_NAME_MISMATCH
    " and " + institutionvalTYPE_COMPATIBLE_REPLACEMENT
    """ and "LITERAL_VALUE_MISMATCH
    institutionvalVARIABLE_NAME_MISMATCH
    33
    if (author.equals(""))
                                  
    34
    author = val;
    Differences
    Expression1Expression2Difference
    institutionsauthorVARIABLE_NAME_MISMATCH
    " and " + institutionvalTYPE_COMPATIBLE_REPLACEMENT
    34
    author = val;
            
    else
                                                        
    35
    author += " and " + val;
    Differences
    Expression1Expression2Difference
    institutionsauthorVARIABLE_NAME_MISMATCH
    """ and "LITERAL_VALUE_MISMATCH
    institutionvalVARIABLE_NAME_MISMATCH
    35
    author += " and " + val;
    Precondition Violations (0)
    Row Violation