]> git.mxchange.org Git - jbonuscard-lib.git/commitdiff
Broken commit towards generics
authorRoland Haeder <roland@mxchange.org>
Fri, 31 Jul 2015 08:47:20 +0000 (10:47 +0200)
committerRoland Haeder <roland@mxchange.org>
Fri, 31 Jul 2015 08:47:20 +0000 (10:47 +0200)
Signed-off-by:Roland Häder <roland@mxchange.org>

Addressbook/src/org/mxchange/addressbook/database/backend/DatabaseBackend.java
Addressbook/src/org/mxchange/addressbook/database/backend/csv/Base64CsvDatabaseBackend.java
Addressbook/src/org/mxchange/addressbook/database/backend/mysql/MySqlDatabaseBackend.java
Addressbook/src/org/mxchange/addressbook/database/frontend/contact/ContactDatabaseFrontend.java

index 70cfd81d856448c29631d7d4e9a3e456a16314d4..dfcf58375c6591f8f493bfa33d696997e7933161 100644 (file)
@@ -20,7 +20,6 @@ import java.io.IOException;
 import java.sql.SQLException;
 import java.util.Iterator;
 import org.mxchange.addressbook.FrameworkInterface;
-import org.mxchange.addressbook.contact.Contact;
 import org.mxchange.addressbook.database.storage.Storeable;
 import org.mxchange.addressbook.exceptions.BadTokenException;
 
@@ -86,8 +85,6 @@ public interface DatabaseBackend extends FrameworkInterface {
         *
         * @return Iterator for contacts
         * @throws org.mxchange.addressbook.exceptions.BadTokenException If the CSV token is badly formulated
-        * @deprecated The method is to much "contact" specific
         */
-       @Deprecated
-       public Iterator<Contact> contactIterator () throws BadTokenException;
+       public Iterator<? extends Storeable> iterator () throws BadTokenException;
 }
index 12377c635b08c6a8a58bf3c5b97f3d82b68f29a7..c0d84600215005c774970765d5820fa8b6e7cf39 100644 (file)
@@ -27,6 +27,7 @@ import java.util.Base64;
 import java.util.Iterator;
 import java.util.List;
 import java.util.StringTokenizer;
+import org.mxchange.addressbook.FrameworkInterface;
 import org.mxchange.addressbook.contact.Contact;
 import org.mxchange.addressbook.contact.Gender;
 import org.mxchange.addressbook.contact.book.BookContact;
@@ -88,35 +89,6 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Dat
                // Empty body
        }
 
-       /**
-        * Gets an iterator for contacts
-        *
-        * @return Iterator for contacts
-        * @throws org.mxchange.addressbook.exceptions.BadTokenException If the
-        * underlaying method has found an invalid token
-        */
-       @Override
-       @Deprecated
-       public Iterator<Contact> contactIterator () throws BadTokenException {
-               // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
-
-               /*
-                * Then read the file into RAM (yes, not perfect for >1000 entries ...)
-                * and get a List back.
-                */
-               List<Contact> list = this.readContactList();
-
-               // List must be set
-               assert (list instanceof List) : "list has not been set."; //NOI18N
-
-               // Trace message
-               this.getLogger().trace(MessageFormat.format("list.iterator()={0} - EXIT!", list.iterator())); //NOI18N
-
-               // Get iterator from list and return it
-               return list.iterator();
-       }
-
        /**
         * Shuts down this backend
         */
@@ -150,7 +122,7 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Dat
                try {
                        // Do a deprecated call
                        // @todo this needs rewrite!
-                       return this.readContactList().size();
+                       return this.readList().size();
                } catch (final BadTokenException ex) {
                        this.abortProgramWithException(ex);
                }
@@ -224,6 +196,33 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Dat
                return isFound;
        }
 
+       /**
+        * Gets an iterator for contacts
+        *
+        * @return Iterator for contacts
+        * @throws org.mxchange.addressbook.exceptions.BadTokenException If the underlaying method has found an invalid token
+        */
+       @Override
+       public Iterator<? extends Storeable> iterator () throws BadTokenException {
+               // Trace message
+               this.getLogger().trace("CALLED!"); //NOI18N
+               
+               /*
+                * Then read the file into RAM (yes, not perfect for >1000 entries ...)
+                * and get a List back.
+                */
+               List<Storeable> list = this.readList();
+               
+               // List must be set
+               assert (list instanceof List) : "list has not been set."; //NOI18N
+               
+               // Trace message
+               this.getLogger().trace(MessageFormat.format("list.iterator()={0} - EXIT!", list.iterator())); //NOI18N
+               
+               // Get iterator from list and return it
+               return list.iterator();
+       }
+
        /**
         * Get length of underlaying file
         *
@@ -309,15 +308,15 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Dat
        /**
         * Adds given contact to list
         *
-        * @param contact Contact instance to add
+        * @param instance An instance of FrameworkInterface to add
         * @param list List instance
         */
-       private void addContactToList (final Contact contact, final List<Contact> list) {
+       private void addToList (final Storeable instance, final List<Storeable> list) {
                // Trace message
-               this.getLogger().trace(MessageFormat.format("contact={0} - CALLED!", contact)); //NOI18N
+               this.getLogger().trace(MessageFormat.format("contact={0} - CALLED!", instance)); //NOI18N
 
                // No null here
-               if (contact == null) {
+               if (instance == null) {
                        // Throw exception
                        throw new NullPointerException("contact is null"); //NOI18N
                } else if (list == null) {
@@ -326,15 +325,15 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Dat
                }
 
                // Debug message
-               this.getLogger().debug(MessageFormat.format("contact={0}", contact)); //NOI18N
+               this.getLogger().debug(MessageFormat.format("contact={0}", instance)); //NOI18N
 
                // Is the contact read?
-               if (contact instanceof Contact) {
+               if (instance instanceof FrameworkInterface) {
                        // Then add it
-                       boolean added = list.add(contact);
+                       boolean added = list.add(instance);
 
                        // Debug message
-                       this.getLogger().debug(MessageFormat.format("contact={0} added={1}", contact, added)); //NOI18N
+                       this.getLogger().debug(MessageFormat.format("contact={0} added={1}", instance, added)); //NOI18N
 
                        // Has it been added?
                        if (!added) {
@@ -624,15 +623,45 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Dat
                return contact;
        }
 
+       /**
+        * Reads a line from file base
+        *
+        * @return Read line from file
+        */
+       private String readLine () {
+               // Trace message
+               this.getLogger().trace("CALLED!"); //NOI18N
+               
+               // Init input
+               String input = null;
+               
+               try {
+                       // Read single line
+                       String base64 = this.getStorageFile().readLine();
+                       
+                       // Decode BASE-64
+                       byte[] decoded = Base64.getDecoder().decode(base64);
+                       
+                       // Convert to string
+                       input = new String(decoded);
+               } catch (final IOException ex) {
+                       this.getLogger().catching(ex);
+               }
+               
+               // Trace message
+               this.getLogger().trace(MessageFormat.format("input={0} - EXIT!", input)); //NOI18N
+               
+               // Return read string or null
+               return input;
+       }
+
        /**
         * Reads the database file, if available, and adds all read lines into the
         * list.
         *
         * @return A list with Contact instances
-        * @deprecated Is to much "contacts" specific
         */
-       @Deprecated
-       private List<Contact> readContactList () throws BadTokenException {
+       private List<? extends Storeable> readList () throws BadTokenException {
                this.getLogger().trace("CALLED!"); //NOI18N
 
                // First rewind
@@ -646,11 +675,11 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Dat
 
                // Instance list
                // @TODO The maximum length could be guessed from file size?
-               List<Contact> list = new ArrayList<>(lines);
+               List<Storeable> list = new ArrayList<>(lines);
 
                // Init variables
                String line;
-               Contact contact = null;
+               Storeable instance = null;
 
                // Read all lines
                while (!this.isEndOfFile()) {
@@ -658,49 +687,17 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Dat
                        line = this.readLine();
 
                        // Parse line
-                       contact = this.parseLineToContact(line);
+                       instance = (Storeable) this.parseLineToContact(line);
 
                        // The contact instance should be there now
-                       assert (contact instanceof Contact) : MessageFormat.format("contact is not set: {0}", contact); //NOI18N
+                       assert (instance instanceof FrameworkInterface) : MessageFormat.format("instance is not set: {0}", instance); //NOI18N
 
                        // Add contact
-                       this.addContactToList(contact, list);
+                       this.addToList(instance, list);
                }
 
                // Return finished list
                this.getLogger().trace(MessageFormat.format("list.size()={0} : EXIT!", list.size())); //NOI18N
                return list;
        }
-
-       /**
-        * Reads a line from file base
-        *
-        * @return Read line from file
-        */
-       private String readLine () {
-               // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
-
-               // Init input
-               String input = null;
-
-               try {
-                       // Read single line
-                       String base64 = this.getStorageFile().readLine();
-
-                       // Decode BASE-64
-                       byte[] decoded = Base64.getDecoder().decode(base64);
-
-                       // Convert to string
-                       input = new String(decoded);
-               } catch (final IOException ex) {
-                       this.getLogger().catching(ex);
-               }
-
-               // Trace message
-               this.getLogger().trace(MessageFormat.format("input={0} - EXIT!", input)); //NOI18N
-
-               // Return read string or null
-               return input;
-       }
 }
index d95afb3e68c007ff837d791d2f2c5c8a643290c5..abc3e9b2a29b5b77b03fc39ab7d4bf7764741969 100644 (file)
@@ -24,7 +24,6 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.text.MessageFormat;
 import java.util.Iterator;
-import org.mxchange.addressbook.contact.Contact;
 import org.mxchange.addressbook.database.backend.BaseDatabaseBackend;
 import org.mxchange.addressbook.database.backend.DatabaseBackend;
 import org.mxchange.addressbook.database.storage.Storeable;
@@ -107,12 +106,6 @@ public class MySqlDatabaseBackend extends BaseDatabaseBackend implements Databas
                this.getLogger().trace("EXIT!"); //NOI18N
        }
 
-       @Override
-       @Deprecated
-       public Iterator<Contact> contactIterator () throws BadTokenException {
-               throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
-       }
-
        @Override
        public void doShutdown () {
                // This should not happen:
@@ -179,6 +172,11 @@ public class MySqlDatabaseBackend extends BaseDatabaseBackend implements Databas
                }
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
+       
+       @Override
+       public Iterator<?> iterator () throws BadTokenException {
+               throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+       }
 
        @Override
        public long length () {
index dc5cdb07c3fbfb3c818b0449799088f016ad18d2..9731d49d3d1b0ba442983a062c60223fa66e0f44 100644 (file)
@@ -178,7 +178,7 @@ public class ContactDatabaseFrontend extends BaseDatabaseFrontend implements Con
                boolean isFound = false;
 
                // Start iteration
-               Iterator<Contact> iterator = this.getBackend().contactIterator();
+               Iterator<Contact> iterator = this.getBackend().iterator();
 
                // Check all entries
                while (iterator.hasNext()) {