Commit 678e94af authored by Arne Styve's avatar Arne Styve
Browse files

Removed unused methods from intrface AddressBook, and hence also from...

Removed unused methods from intrface AddressBook, and hence also from AddressBookPlain and AddressBookDBHandler. Ready for release v0.4.2
parent 816c4288
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="FrameworkDetectionExcludesConfiguration" detection-enabled="false" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8.0_201" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8.0_201" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4"> <module type="JAVA_MODULE" version="4">
<component name="FacetManager"> <component name="CheckStyle-IDEA-Module">
<facet type="jpa" name="JPA"> <option name="configuration">
<configuration> <map />
<setting name="validation-enabled" value="true" /> </option>
<datasource-mapping>
<factory-entry name="contacts-pu" />
</datasource-mapping>
<naming-strategy-map />
<deploymentDescriptor name="persistence.xml" url="file://$MODULE_DIR$/src/META-INF/persistence.xml" />
</configuration>
</facet>
</component> </component>
<component name="NewModuleRootManager" inherit-compiler-output="true"> <component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output /> <exclude-output />
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="jdk" jdkName="1.8.0_201" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="libs" level="project" /> <orderEntry type="library" name="libs" level="project" />
</component> </component>
</module> </module>
\ No newline at end of file
...@@ -6,24 +6,6 @@ import java.util.Iterator; ...@@ -6,24 +6,6 @@ import java.util.Iterator;
public interface AddressBook extends Serializable, Iterable<ContactDetails> { public interface AddressBook extends Serializable, Iterable<ContactDetails> {
/**
* Searches for a contact matching the phone number given by the parameter.
* The found contact is returned. If no contact found, <code>null</code>
* is returned.
*
* @param phoneNumber The number to be looked up.
* @return The details corresponding to the phone number.
*/
ContactDetails findContactByPhoneNumber(String phoneNumber);
/**
* Return whether or not the current phone number is in use.
*
* @param phoneNumber The name or phone number to be looked up.
* @return true if the phoneNumber is in use, false otherwise.
*/
boolean keyInUse(String phoneNumber);
/** /**
* Add a new contact to the address book. * Add a new contact to the address book.
* *
...@@ -31,24 +13,6 @@ public interface AddressBook extends Serializable, Iterable<ContactDetails> { ...@@ -31,24 +13,6 @@ public interface AddressBook extends Serializable, Iterable<ContactDetails> {
*/ */
void addContact(ContactDetails contact); void addContact(ContactDetails contact);
/**
* Change the contact previously stored under the given key.
*
* @param oldKey One of the keys used to store the contact.
* This should be a key that is currently in use.
* @param contact The replacement contact.
*/
void changeDetails(String oldKey,
ContactDetails contact);
/**
* Return the number of entries currently in the
* address book.
*
* @return The number of entries.
*/
int getNumberOfEntries();
/** /**
* Remove the contact with the given phone number from the address book. * Remove the contact with the given phone number from the address book.
* The phone number should be one that is currently in use. * The phone number should be one that is currently in use.
......
...@@ -37,23 +37,12 @@ public class AddressBookDBHandler implements AddressBook { ...@@ -37,23 +37,12 @@ public class AddressBookDBHandler implements AddressBook {
private final transient EntityManagerFactory efact; private final transient EntityManagerFactory efact;
/** /**
* Creates an instance of the AddressbookDAO. * Creates an instance of the AddressBookDBHandler.
*/ */
public AddressBookDBHandler() { public AddressBookDBHandler() {
this.efact = Persistence.createEntityManagerFactory("contacts-pu"); this.efact = Persistence.createEntityManagerFactory("contacts-pu");
} }
@Override
public ContactDetails findContactByPhoneNumber(String phoneNumber) {
//TODO: To be implemented later....
return null;
}
@Override
public boolean keyInUse(String phoneNumber) {
return false;
}
@Override @Override
public void addContact(ContactDetails contact) { public void addContact(ContactDetails contact) {
EntityManager eman = this.efact.createEntityManager(); EntityManager eman = this.efact.createEntityManager();
...@@ -63,16 +52,6 @@ public class AddressBookDBHandler implements AddressBook { ...@@ -63,16 +52,6 @@ public class AddressBookDBHandler implements AddressBook {
eman.close(); eman.close();
} }
@Override
public void changeDetails(String oldKey, ContactDetails contact) {
//TODO: To be implemented later....
}
@Override
public int getNumberOfEntries() {
return this.getAllContacts().size();
}
@Override @Override
public void removeContact(String phoneNumber) { public void removeContact(String phoneNumber) {
//TODO: To be implemented later... //TODO: To be implemented later...
......
...@@ -23,7 +23,7 @@ public class AddressBookPlain implements AddressBook { ...@@ -23,7 +23,7 @@ public class AddressBookPlain implements AddressBook {
// TreeMap is a bit less efficient than a HashMap in terms of searching, du to the // TreeMap is a bit less efficient than a HashMap in terms of searching, du to the
// sorted order. For more details on the difference: // sorted order. For more details on the difference:
// https://javatutorial.net/difference-between-hashmap-and-treemap-in-java // https://javatutorial.net/difference-between-hashmap-and-treemap-in-java
private final TreeMap<String, ContactDetails> book; private TreeMap<String, ContactDetails> book;
/** /**
* Creates an instance of the AddressBook, initialising the instance. * Creates an instance of the AddressBook, initialising the instance.
...@@ -32,53 +32,39 @@ public class AddressBookPlain implements AddressBook { ...@@ -32,53 +32,39 @@ public class AddressBookPlain implements AddressBook {
book = new TreeMap<>(); book = new TreeMap<>();
} }
/**
@Override * Add a new contact to the address book.
public ContactDetails findContactByPhoneNumber(String phoneNumber) { *
return book.get(phoneNumber); * @param contact The contact to be added.
} */
@Override
public boolean keyInUse(String phoneNumber) {
return book.containsKey(phoneNumber);
}
@Override
public void addContact(ContactDetails contact) { public void addContact(ContactDetails contact) {
if (contact != null) { if (contact != null) {
book.put(contact.getPhone(), contact); book.put(contact.getPhone(), contact);
} }
} }
@Override /**
public void changeDetails(String oldKey, * Remove the contact with the given phonenumber from the address book.
ContactDetails contact) { * The phone number should be one that is currently in use.
if (keyInUse(oldKey) && contact != null) { *
removeContact(oldKey); * @param phoneNumber The phone number to the contact to remove
addContact(contact); */
}
}
@Override
public int getNumberOfEntries() {
return this.book.size();
}
@Override
public void removeContact(String phoneNumber) { public void removeContact(String phoneNumber) {
if (keyInUse(phoneNumber)) { this.book.remove(phoneNumber);
this.book.remove(phoneNumber);
}
} }
@Override /**
* Returns all the contacts as a collection.
*
* @return all the contacts as a collection.
*/
public Collection<ContactDetails> getAllContacts() { public Collection<ContactDetails> getAllContacts() {
return this.book.values(); return this.book.values();
} }
@Override @Override
public void close() { public void close() {
// Nothing needed to be done. Intentionally left empty.
} }
@Override @Override
......
...@@ -32,7 +32,7 @@ import no.ntnu.idata2001.contacts.model.ContactDetails; ...@@ -32,7 +32,7 @@ import no.ntnu.idata2001.contacts.model.ContactDetails;
*/ */
public class ContactsApp extends Application { public class ContactsApp extends Application {
private static final String VERSION = "0.4.1"; private static final String VERSION = "0.4.2";
private MainController mainController; private MainController mainController;
private AddressBook addressBook; private AddressBook addressBook;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment