Commit 757036f6 authored by Arne Styve's avatar Arne Styve
Browse files

Merge branch 'hotfix/v0.4.2'

parents 816c4288 678e94af
<?xml version="1.0" encoding="UTF-8"?>
<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">
<output url="file://$PROJECT_DIR$/out" />
</component>
......
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="jpa" name="JPA">
<configuration>
<setting name="validation-enabled" value="true" />
<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 name="CheckStyle-IDEA-Module">
<option name="configuration">
<map />
</option>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="jdk" jdkName="1.8.0_201" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="libs" level="project" />
<orderEntry type="library" name="libs" level="project" />
</component>
</module>
\ No newline at end of file
......@@ -6,24 +6,6 @@ import java.util.Iterator;
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.
*
......@@ -31,24 +13,6 @@ public interface AddressBook extends Serializable, Iterable<ContactDetails> {
*/
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.
* The phone number should be one that is currently in use.
......
......@@ -37,23 +37,12 @@ public class AddressBookDBHandler implements AddressBook {
private final transient EntityManagerFactory efact;
/**
* Creates an instance of the AddressbookDAO.
* Creates an instance of the AddressBookDBHandler.
*/
public AddressBookDBHandler() {
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
public void addContact(ContactDetails contact) {
EntityManager eman = this.efact.createEntityManager();
......@@ -63,16 +52,6 @@ public class AddressBookDBHandler implements AddressBook {
eman.close();
}
@Override
public void changeDetails(String oldKey, ContactDetails contact) {
//TODO: To be implemented later....
}
@Override
public int getNumberOfEntries() {
return this.getAllContacts().size();
}
@Override
public void removeContact(String phoneNumber) {
//TODO: To be implemented later...
......
......@@ -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
// sorted order. For more details on the difference:
// 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.
......@@ -32,53 +32,39 @@ public class AddressBookPlain implements AddressBook {
book = new TreeMap<>();
}
@Override
public ContactDetails findContactByPhoneNumber(String phoneNumber) {
return book.get(phoneNumber);
}
@Override
public boolean keyInUse(String phoneNumber) {
return book.containsKey(phoneNumber);
}
@Override
/**
* Add a new contact to the address book.
*
* @param contact The contact to be added.
*/
public void addContact(ContactDetails contact) {
if (contact != null) {
book.put(contact.getPhone(), contact);
}
}
@Override
public void changeDetails(String oldKey,
ContactDetails contact) {
if (keyInUse(oldKey) && contact != null) {
removeContact(oldKey);
addContact(contact);
}
}
@Override
public int getNumberOfEntries() {
return this.book.size();
}
@Override
/**
* Remove the contact with the given phonenumber from the address book.
* The phone number should be one that is currently in use.
*
* @param phoneNumber The phone number to the contact to remove
*/
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() {
return this.book.values();
}
@Override
public void close() {
// Nothing needed to be done. Intentionally left empty.
}
@Override
......
......@@ -32,7 +32,7 @@ import no.ntnu.idata2001.contacts.model.ContactDetails;
*/
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 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