<NME> FileHistory.java
<BEF> ADDFILE
<MSG> Extracted logic out of FileHistory

<DFF> @@ -0,0 +1,89 @@
+/*  Copyright (C) 2003-2015 JabRef contributors.
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License along
+    with this program; if not, write to the Free Software Foundation, Inc.,
+    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package net.sf.jabref.logic.util.io;
+
+import java.util.LinkedList;
+
+import net.sf.jabref.JabRefPreferences;
+
+public class FileHistory {
+
+    private final JabRefPreferences prefs;
+    private final LinkedList<String> history = new LinkedList<>();
+
+
+    public FileHistory(JabRefPreferences prefs) {
+        this.prefs = prefs;
+        String[] old = prefs.getStringArray(JabRefPreferences.RECENT_FILES);
+        if ((old != null) && (old.length > 0)) {
+            for (int i = 0; i < old.length; i++) {
+                history.addFirst(old[i]);
+            }
+        }
+    }
+
+    public int size() {
+        return history.size();
+    }
+
+    /**
+     * Adds the filename to the top of the list. If it already is in the list, it is merely moved to the top.
+     *
+     * @param filename a <code>String</code> value
+     */
+
+    public void newFile(String filename) {
+        int i = 0;
+        while (i < history.size()) {
+            if (history.get(i).equals(filename)) {
+                history.remove(i);
+                i--;
+            }
+            i++;
+        }
+        history.addFirst(filename);
+        while (history.size() > prefs.getInt(JabRefPreferences.HISTORY_SIZE)) {
+            history.removeLast();
+        }
+    }
+
+    public String getFileName(int i) {
+        return history.get(i);
+    }
+
+    public void removeItem(String filename) {
+        int i = 0;
+        while (i < history.size()) {
+            if (history.get(i).equals(filename)) {
+                history.remove(i);
+                return;
+            }
+            i++;
+        }
+    }
+
+    public void storeHistory() {
+        if (!history.isEmpty()) {
+            String[] names = new String[history.size()];
+            for (int i = 0; i < names.length; i++) {
+                names[i] = history.get(i);
+            }
+            prefs.putStringArray(JabRefPreferences.RECENT_FILES, names);
+        }
+    }
+
+}

{'commit': 'diff --git a/src/main/java/net/sf/jabref/JabRefPreferences.java b/src/main/java/net/sf/jabref/JabRefPreferences.java\nindex 9105f79a68..291689b6c1 100644\n--- a/src/main/java/net/sf/jabref/JabRefPreferences.java\n+++ b/src/main/java/net/sf/jabref/JabRefPreferences.java\n@@ -226,6 +226,7 @@ public class JabRefPreferences {\n     public static final String FONT_SIZE = "fontSize";\n     public static final String FONT_STYLE = "fontStyle";\n     public static final String HISTORY_SIZE = "historySize";\n+    public static final String RECENT_FILES = "recentFiles";\n     public static final String GENERAL_FIELDS = "generalFields";\n     public static final String RENAME_ON_MOVE_FILE_TO_FILE_DIR = "renameOnMoveFileToFileDir";\n     public static final String MEMORY_STICK_MODE = "memoryStickMode";\ndiff --git a/src/main/java/net/sf/jabref/gui/FileHistory.java b/src/main/java/net/sf/jabref/gui/FileHistoryMenu.java\nsimilarity index 65%\nrename from src/main/java/net/sf/jabref/gui/FileHistory.java\nrename to src/main/java/net/sf/jabref/gui/FileHistoryMenu.java\nindex 56642ca744..37eea8703d 100644\n--- a/src/main/java/net/sf/jabref/gui/FileHistory.java\n+++ b/src/main/java/net/sf/jabref/gui/FileHistoryMenu.java\n@@ -17,27 +17,23 @@ package net.sf.jabref.gui;\n \n import net.sf.jabref.JabRefExecutorService;\n import net.sf.jabref.JabRefPreferences;\n-import net.sf.jabref.gui.JabRefFrame;\n import net.sf.jabref.logic.l10n.Localization;\n+import net.sf.jabref.logic.util.io.FileHistory;\n \n import java.awt.event.ActionEvent;\n import java.awt.event.ActionListener;\n import java.io.File;\n-import java.util.Iterator;\n-import java.util.LinkedList;\n-\n import javax.swing.JMenu;\n import javax.swing.JMenuItem;\n import javax.swing.JOptionPane;\n \n-public class FileHistory extends JMenu implements ActionListener {\n+public class FileHistoryMenu extends JMenu implements ActionListener {\n \n-    private final JabRefPreferences prefs;\n-    private final LinkedList<String> history = new LinkedList<>();\n+    private final FileHistory history;\n     private final JabRefFrame frame;\n \n \n-    public FileHistory(JabRefPreferences prefs, JabRefFrame frame) {\n+    public FileHistoryMenu(JabRefPreferences prefs, JabRefFrame frame) {\n         String name = Localization.menuTitle("Recent files");\n         int i = name.indexOf(\'&\');\n         if (i >= 0) {\n@@ -48,13 +44,9 @@ public class FileHistory extends JMenu implements ActionListener {\n             setText(name);\n         }\n \n-        this.prefs = prefs;\n         this.frame = frame;\n-        String[] old = prefs.getStringArray("recentFiles");\n-        if ((old != null) && (old.length > 0)) {\n-            for (i = 0; i < old.length; i++) {\n-                history.addFirst(old[i]);\n-            }\n+        history = new FileHistory(prefs);\n+        if (history.size() > 0) {\n             setItems();\n         } else {\n             setEnabled(false);\n@@ -68,18 +60,7 @@ public class FileHistory extends JMenu implements ActionListener {\n      * @param filename a <code>String</code> value\n      */\n     public void newFile(String filename) {\n-        int i = 0;\n-        while (i < history.size()) {\n-            if (history.get(i).equals(filename)) {\n-                history.remove(i);\n-                i--;\n-            }\n-            i++;\n-        }\n-        history.addFirst(filename);\n-        while (history.size() > prefs.getInt(JabRefPreferences.HISTORY_SIZE)) {\n-            history.removeLast();\n-        }\n+        history.newFile(filename);\n         setItems();\n         if (!isEnabled()) {\n             setEnabled(true);\n@@ -88,16 +69,13 @@ public class FileHistory extends JMenu implements ActionListener {\n \n     private void setItems() {\n         removeAll();\n-        Iterator<String> i = history.iterator();\n-        int count = 1;\n-        while (i.hasNext()) {\n-            addItem(i.next(), count);\n-            count++;\n+        for (int count = 0; count < history.size(); count++) {\n+            addItem(history.getFileName(count), count + 1);\n         }\n     }\n \n     private void addItem(String filename, int num) {\n-        String number = num + "";\n+        String number = Integer.toString(num);\n         JMenuItem item = new JMenuItem(number + ". " + filename);\n         char mnemonic = Character.toUpperCase(number.charAt(0));\n         item.setMnemonic((int) mnemonic);\n@@ -106,26 +84,9 @@ public class FileHistory extends JMenu implements ActionListener {\n         //history.addFirst(item);\n     }\n \n-    private void removeItem(String filename) {\n-        int i = 0;\n-        while (i < history.size()) {\n-            if (history.get(i).equals(filename)) {\n-                history.remove(i);\n-                setItems();\n-                return;\n-            }\n-            i++;\n-        }\n-    }\n \n     public void storeHistory() {\n-        if (!history.isEmpty()) {\n-            String[] names = new String[history.size()];\n-            for (int i = 0; i < names.length; i++) {\n-                names[i] = history.get(i);\n-            }\n-            prefs.putStringArray("recentFiles", names);\n-        }\n+        history.storeHistory();\n     }\n \n     @Override\n@@ -139,7 +100,8 @@ public class FileHistory extends JMenu implements ActionListener {\n         if (!fileToOpen.exists()) {\n             JOptionPane.showMessageDialog(frame, Localization.lang("File not found") + ": " + fileToOpen.getName(),\n                     "Error", JOptionPane.ERROR_MESSAGE);\n-            removeItem(name);\n+            history.removeItem(name);\n+            setItems();\n             return;\n         }\n         JabRefExecutorService.INSTANCE.execute(new Runnable() {\ndiff --git a/src/main/java/net/sf/jabref/gui/JabRefFrame.java b/src/main/java/net/sf/jabref/gui/JabRefFrame.java\nindex d1f7b5b76c..40fbe8f48b 100644\n--- a/src/main/java/net/sf/jabref/gui/JabRefFrame.java\n+++ b/src/main/java/net/sf/jabref/gui/JabRefFrame.java\n@@ -221,7 +221,7 @@ public class JabRefFrame extends JFrame implements OutputPrinter {\n                     + \':\', SwingConstants.LEFT);\n     private final JProgressBar progressBar = new JProgressBar();\n \n-    private final FileHistory fileHistory = new FileHistory(prefs, this);\n+    private final FileHistoryMenu fileHistory = new FileHistoryMenu(prefs, this);\n \n     // The help window.\n     public final HelpDialog helpDiag = new HelpDialog(this);\n@@ -1837,7 +1837,7 @@ public class JabRefFrame extends JFrame implements OutputPrinter {\n         });\n     }\n \n-    public FileHistory getFileHistory() {\n+    public FileHistoryMenu getFileHistory() {\n         return fileHistory;\n     }\n \ndiff --git a/src/main/java/net/sf/jabref/logic/util/io/FileHistory.java b/src/main/java/net/sf/jabref/logic/util/io/FileHistory.java\nnew file mode 100644\nindex 0000000000..221f4904b2\n--- /dev/null\n+++ b/src/main/java/net/sf/jabref/logic/util/io/FileHistory.java\n@@ -0,0 +1,89 @@\n+/*  Copyright (C) 2003-2015 JabRef contributors.\n+    This program is free software; you can redistribute it and/or modify\n+    it under the terms of the GNU General Public License as published by\n+    the Free Software Foundation; either version 2 of the License, or\n+    (at your option) any later version.\n+\n+    This program is distributed in the hope that it will be useful,\n+    but WITHOUT ANY WARRANTY; without even the implied warranty of\n+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+    GNU General Public License for more details.\n+\n+    You should have received a copy of the GNU General Public License along\n+    with this program; if not, write to the Free Software Foundation, Inc.,\n+    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\n+ */\n+\n+package net.sf.jabref.logic.util.io;\n+\n+import java.util.LinkedList;\n+\n+import net.sf.jabref.JabRefPreferences;\n+\n+public class FileHistory {\n+\n+    private final JabRefPreferences prefs;\n+    private final LinkedList<String> history = new LinkedList<>();\n+\n+\n+    public FileHistory(JabRefPreferences prefs) {\n+        this.prefs = prefs;\n+        String[] old = prefs.getStringArray(JabRefPreferences.RECENT_FILES);\n+        if ((old != null) && (old.length > 0)) {\n+            for (int i = 0; i < old.length; i++) {\n+                history.addFirst(old[i]);\n+            }\n+        }\n+    }\n+\n+    public int size() {\n+        return history.size();\n+    }\n+\n+    /**\n+     * Adds the filename to the top of the list. If it already is in the list, it is merely moved to the top.\n+     *\n+     * @param filename a <code>String</code> value\n+     */\n+\n+    public void newFile(String filename) {\n+        int i = 0;\n+        while (i < history.size()) {\n+            if (history.get(i).equals(filename)) {\n+                history.remove(i);\n+                i--;\n+            }\n+            i++;\n+        }\n+        history.addFirst(filename);\n+        while (history.size() > prefs.getInt(JabRefPreferences.HISTORY_SIZE)) {\n+            history.removeLast();\n+        }\n+    }\n+\n+    public String getFileName(int i) {\n+        return history.get(i);\n+    }\n+\n+    public void removeItem(String filename) {\n+        int i = 0;\n+        while (i < history.size()) {\n+            if (history.get(i).equals(filename)) {\n+                history.remove(i);\n+                return;\n+            }\n+            i++;\n+        }\n+    }\n+\n+    public void storeHistory() {\n+        if (!history.isEmpty()) {\n+            String[] names = new String[history.size()];\n+            for (int i = 0; i < names.length; i++) {\n+                names[i] = history.get(i);\n+            }\n+            prefs.putStringArray(JabRefPreferences.RECENT_FILES, names);\n+        }\n+    }\n+\n+}\n', 'commit_subject': 'Extracted logic out of FileHistory', 'repo_name': 'JabRef/jabref', 'committer': {'name': 'Oscar Gustafsson', 'email': 'adcfd8d863b7826249ae5be30494f3f20433acbf@gmail.com', 'time_sec': '1448034481', 'tz_offset': '60', 'date': {'seconds': '1448034481'}}, 'commit_tree': 'c8b23877ea0af4e2f342d28a90bdcf50b8eec50c', 'commit_message': 'Extracted logic out of FileHistory\n', 'language_name': 'Java', 'license': 'mit', 'hunks': '@@ -0,0 +1,89 @@\n+/*  Copyright (C) 2003-2015 JabRef contributors.\n+    This program is free software; you can redistribute it and/or modify\n+    it under the terms of the GNU General Public License as published by\n+    the Free Software Foundation; either version 2 of the License, or\n+    (at your option) any later version.\n+\n+    This program is distributed in the hope that it will be useful,\n+    but WITHOUT ANY WARRANTY; without even the implied warranty of\n+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+    GNU General Public License for more details.\n+\n+    You should have received a copy of the GNU General Public License along\n+    with this program; if not, write to the Free Software Foundation, Inc.,\n+    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\n+ */\n+\n+package net.sf.jabref.logic.util.io;\n+\n+import java.util.LinkedList;\n+\n+import net.sf.jabref.JabRefPreferences;\n+\n+public class FileHistory {\n+\n+    private final JabRefPreferences prefs;\n+    private final LinkedList<String> history = new LinkedList<>();\n+\n+\n+    public FileHistory(JabRefPreferences prefs) {\n+        this.prefs = prefs;\n+        String[] old = prefs.getStringArray(JabRefPreferences.RECENT_FILES);\n+        if ((old != null) && (old.length > 0)) {\n+            for (int i = 0; i < old.length; i++) {\n+                history.addFirst(old[i]);\n+            }\n+        }\n+    }\n+\n+    public int size() {\n+        return history.size();\n+    }\n+\n+    /**\n+     * Adds the filename to the top of the list. If it already is in the list, it is merely moved to the top.\n+     *\n+     * @param filename a <code>String</code> value\n+     */\n+\n+    public void newFile(String filename) {\n+        int i = 0;\n+        while (i < history.size()) {\n+            if (history.get(i).equals(filename)) {\n+                history.remove(i);\n+                i--;\n+            }\n+            i++;\n+        }\n+        history.addFirst(filename);\n+        while (history.size() > prefs.getInt(JabRefPreferences.HISTORY_SIZE)) {\n+            history.removeLast();\n+        }\n+    }\n+\n+    public String getFileName(int i) {\n+        return history.get(i);\n+    }\n+\n+    public void removeItem(String filename) {\n+        int i = 0;\n+        while (i < history.size()) {\n+            if (history.get(i).equals(filename)) {\n+                history.remove(i);\n+                return;\n+            }\n+            i++;\n+        }\n+    }\n+\n+    public void storeHistory() {\n+        if (!history.isEmpty()) {\n+            String[] names = new String[history.size()];\n+            for (int i = 0; i < names.length; i++) {\n+                names[i] = history.get(i);\n+            }\n+            prefs.putStringArray(JabRefPreferences.RECENT_FILES, names);\n+        }\n+    }\n+\n+}\n', 'addition_count': 89, 'deletion_count': 0, 'src_file': '/dev/null', 'tgt_file': 'b/src/main/java/net/sf/jabref/logic/util/io/FileHistory.java', 'file_extension': '.java', 'before_file': 'ADDFILE', 'message': 'Extracted logic out of FileHistory\n', 'author_name': 'Oscar Gustafsson', 'lang': 'java'}