]> git.mxchange.org Git - addressbook-lib.git/blobdiff - Addressbook/src/org/mxchange/addressbook/database/frontend/contact/ContactDatabaseFrontend.java
Global commit: Changed spaces to tabs, because all Java files have tabs for indenting
[addressbook-lib.git] / Addressbook / src / org / mxchange / addressbook / database / frontend / contact / ContactDatabaseFrontend.java
index df1854c93cb4bd3e601082b3e4d403c378df83a9..cfd7ec1a7caa959419e3907187a8af6a20375e67 100644 (file)
-/*\r
- * Copyright (C) 2015 Roland Haeder\r
- *\r
- * This program is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation, either version 3 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
- */\r
-package org.mxchange.addressbook.database.frontend.contact;\r
-\r
-import java.io.IOException;\r
-import java.util.Iterator;\r
-import java.util.List;\r
-import org.mxchange.addressbook.BadTokenException;\r
-import org.mxchange.addressbook.contact.Contact;\r
-import org.mxchange.addressbook.database.backend.csv.CsvBackend;\r
-import org.mxchange.addressbook.database.frontend.BaseDatabaseFrontend;\r
-import org.mxchange.addressbook.database.storage.Storeable;\r
-import org.mxchange.addressbook.manager.contact.ContactManager;\r
-\r
-/**\r
- * Stores and retrieves Contact instances\r
- *\r
- * @author Roland Haeder\r
- */\r
-public class ContactDatabaseFrontend extends BaseDatabaseFrontend implements ContactWrapper {\r
-    /**\r
-     * Constructor which accepts a contact manager\r
-     * @param manager\r
-     */\r
-    public ContactDatabaseFrontend (final ContactManager manager) {\r
-       // Call own constructor\r
-       this();\r
-       \r
-       // Set contact manager\r
-       this.setContactManager(manager);\r
-    }\r
-\r
-    /**\r
-     * Basic constrcutor\r
-     */\r
-    protected ContactDatabaseFrontend () {\r
-       super();\r
-\r
-       // Set "table" name\r
-       this.setTableName("contacts");\r
-\r
-       // Initalize backend\r
-       this.initBackend();\r
-    }\r
-\r
-    /**\r
-     * Shuts down the database layer\r
-     */\r
-    @Override\r
-    public void doShutdown () {\r
-       // Shutdown backend\r
-       this.getBackend().doShutdown();\r
-    }\r
-\r
-    /**\r
-     * Flushes all contact entries to database\r
-     */\r
-    @Override\r
-    public void flushAllContacts () {\r
-       // Get full list\r
-       List<Contact> contacts = this.getContactManager().getList();\r
-\r
-       // Get iterator\r
-       Iterator<Contact> iterator = contacts.iterator();\r
-\r
-       // Rewind backend\r
-       this.getBackend().rewind();\r
-\r
-       // Get all entries\r
-       while (iterator.hasNext()) {\r
-           // Get next entry\r
-           Contact contact = iterator.next();\r
-\r
-           try {\r
-               // Store this entry\r
-               this.getBackend().store((Storeable) contact);\r
-           } catch (final IOException ex) {\r
-               // Should not happen?\r
-               this.getLogger().catching(ex);\r
-               System.exit(1);\r
-           }\r
-       }\r
-    }\r
-\r
-    /**\r
-     * Reads all contacts from database backend and handles them over to the\r
-     * contact manager\r
-     */\r
-    @Override\r
-    public void readAllContacts () {\r
-       // Get iterator and case it\r
-       CsvBackend backend = (CsvBackend) this.getBackend();\r
-       \r
-       // First rewind to beginning\r
-       this.getBackend().rewind();\r
-\r
-       // Get backend iterator\r
-       Iterator<Contact> iterator = null;\r
-       try {\r
-           iterator = backend.contactIterator();\r
-       } catch (final BadTokenException ex) {\r
-           this.getLogger().catching(ex);\r
-           System.exit(1);\r
-       }\r
-\r
-       // Read all entries\r
-       while (iterator.hasNext()) {\r
-           // Get next entry\r
-           Contact contact = iterator.next();\r
-\r
-           // Add contact instance to manager\r
-           this.getContactManager().addContact(contact);\r
-       }\r
-    }\r
-}\r
+/*
+ * Copyright (C) 2015 Roland Haeder
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.database.frontend.contact;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+import org.mxchange.addressbook.exceptions.BadTokenException;
+import org.mxchange.addressbook.contact.Contact;
+import org.mxchange.addressbook.database.backend.csv.CsvBackend;
+import org.mxchange.addressbook.database.frontend.BaseDatabaseFrontend;
+import org.mxchange.addressbook.database.storage.Storeable;
+import org.mxchange.addressbook.manager.contact.ContactManager;
+
+/**
+ * Stores and retrieves Contact instances
+ *
+ * @author Roland Haeder
+ */
+public class ContactDatabaseFrontend extends BaseDatabaseFrontend implements ContactWrapper {
+
+       /**
+        * Constructor which accepts a contact manager
+        *
+        * @param manager
+        */
+       public ContactDatabaseFrontend (final ContactManager manager) {
+               // Call own constructor
+               this();
+
+               // Set contact manager
+               this.setContactManager(manager);
+       }
+
+       /**
+        * Basic constrcutor
+        */
+       protected ContactDatabaseFrontend () {
+               super();
+
+               // Set "table" name
+               this.setTableName("contacts");
+
+               // Initalize backend
+               this.initBackend();
+       }
+
+       /**
+        * Shuts down the database layer
+        */
+       @Override
+       public void doShutdown () {
+               // Shutdown backend
+               this.getBackend().doShutdown();
+       }
+
+       /**
+        * Flushes all contact entries to database
+        */
+       @Override
+       public void flushAllContacts () {
+               // Get full list
+               List<Contact> contacts = this.getContactManager().getList();
+
+               // Get iterator
+               Iterator<Contact> iterator = contacts.iterator();
+
+               // Rewind backend
+               this.getBackend().rewind();
+
+               // Get all entries
+               while (iterator.hasNext()) {
+                       // Get next entry
+                       Contact contact = iterator.next();
+
+                       try {
+                               // Store this entry
+                               this.getBackend().store((Storeable) contact);
+                       } catch (final IOException ex) {
+                               // Should not happen?
+                               this.getLogger().catching(ex);
+                               System.exit(1);
+                       }
+               }
+       }
+
+       /**
+        * Reads all contacts from database backend and handles them over to the
+        * contact manager
+        */
+       @Override
+       public void readAllContacts () {
+               // Get iterator and case it
+               CsvBackend backend = (CsvBackend) this.getBackend();
+
+               // First rewind to beginning
+               this.getBackend().rewind();
+
+               // Get backend iterator
+               Iterator<Contact> iterator = null;
+               try {
+                       iterator = backend.contactIterator();
+               } catch (final BadTokenException ex) {
+                       this.getLogger().catching(ex);
+                       System.exit(1);
+               }
+
+               // Read all entries
+               while (iterator.hasNext()) {
+                       // Get next entry
+                       Contact contact = iterator.next();
+
+                       // Add contact instance to manager
+                       this.getContactManager().addContact(contact);
+               }
+       }
+}