src/main/java/seedu/planner/model/ModelManager.java
private void updateMapping(Activity oldAct, Activity newAct) throws EndOfTimeException {
        if (oldAct.getContact().isPresent()) { //checks for existing mapping
            Contact oldContact = oldAct.getContact().get();

            if (contactAccommodationMap.containsKey(oldContact) && contactActivityMap.containsKey(oldContact)) {
                //if it is linked to both
                contactActivityMap.remove(oldContact);
            } else if (contactActivityMap.containsKey(oldContact) && !contactAccommodationMap.containsKey(oldContact)) {
                //if linked to just activity
                removeContact(oldContact);
            }

            if (newAct.getContact().isPresent()) {
                Contact newContact = newAct.getContact().get();
                if (!hasContact(newContact)) {
                    addContact(newContact);
                }
                contactActivityMap.put(newContact, newAct);
            }
        } else if (newAct.getContact().isPresent()) { //activity gets new contact previously not there
            Contact newContact = newAct.getContact().get();
            if (!hasContact(newContact)) {
                addContact(newContact);
            }
            addActivityMapping(newAct);
        }
        if (activityDayMap.containsKey(oldAct)) { //updates the activities in a day
            updateDay(oldAct, newAct);
        }
    }
/**
     * Updates the mapping when there is a change to an {@code Activity}. When the {@code Contact} of the
     * {@code Activity} is changed, the {@code Contact} is also updated.
     */
Updates the mapping when there is a change to an  Activity. When the  Contact of the
Activity is changed, the  Contact is also updated.
Updates the mapping when there is a change to an Activity . When the Contact of the Activity is changed the Contact is also updated .
private void updateMapping(Activity oldAct, Activity newAct) throws EndOfTimeException {
        if (oldAct.getContact().isPresent()) { 
            Contact oldContact = oldAct.getContact().get();
            if (contactAccommodationMap.containsKey(oldContact) && contactActivityMap.containsKey(oldContact)) {
                contactActivityMap.remove(oldContact);
            } else if (contactActivityMap.containsKey(oldContact) && !contactAccommodationMap.containsKey(oldContact)) {
                removeContact(oldContact);
            }
            if (newAct.getContact().isPresent()) {
                Contact newContact = newAct.getContact().get();
                if (!hasContact(newContact)) {
                    addContact(newContact);
                }
                contactActivityMap.put(newContact, newAct);
            }
        } else if (newAct.getContact().isPresent()) { 
            Contact newContact = newAct.getContact().get();
            if (!hasContact(newContact)) {
                addContact(newContact);
            }
            addActivityMapping(newAct);
        }
        if (activityDayMap.containsKey(oldAct)) { 
            updateDay(oldAct, newAct);
        }
    }
private void updateMapping ( Activity oldAct , Activity newAct ) throws EndOfTimeException { if ( oldAct . getContact ( ) . isPresent ( ) ) { Contact oldContact = oldAct . getContact ( ) . get ( ) ; if ( contactAccommodationMap . containsKey ( oldContact ) && contactActivityMap . containsKey ( oldContact ) ) { contactActivityMap . remove ( oldContact ) ; } else if ( contactActivityMap . containsKey ( oldContact ) && ! contactAccommodationMap . containsKey ( oldContact ) ) { removeContact ( oldContact ) ; } if ( newAct . getContact ( ) . isPresent ( ) ) { Contact newContact = newAct . getContact ( ) . get ( ) ; if ( ! hasContact ( newContact ) ) { addContact ( newContact ) ; } contactActivityMap . put ( newContact , newAct ) ; } } else if ( newAct . getContact ( ) . isPresent ( ) ) { Contact newContact = newAct . getContact ( ) . get ( ) ; if ( ! hasContact ( newContact ) ) { addContact ( newContact ) ; } addActivityMapping ( newAct ) ; } if ( activityDayMap . containsKey ( oldAct ) ) { updateDay ( oldAct , newAct ) ; } }
Updates the mapping when there is a change to an {@code Activity}.
Updates the mapping when there is a change to an { @code Activity } .
//checks for existing mapping //if it is linked to both //if linked to just activity //activity gets new contact previously not there //updates the activities in a day