0

Currently I am trying to read and write the futureMeetingArray and pastMeetingArray and then later call on them in the getMeetingListOn method. This method should find any meetings with the same date and add them to an array and return that array. However, at the moment it is not finding these (so far I am only testing it on the futureMeetingsArray). I have also included the addFutureMeeting method to illustrate how I have set about adding to and then serializing the futureArrayList. Each FutureMeeting object has a global Calendar variable, which I am calling on through getters and setters. I can provide the code for this if it makes it clearer.

If anyone could suggest a reason why it is not finding the dates, I would be grateful.

public class ContactManagerImpl implements ContactManager {
    Calendar date;
    List<Meeting> futureMeetingArray = new ArrayList<Meeting>(); 
    List<PastMeetingImpl> pastMeetingArray =  new ArrayList<PastMeetingImpl>();
    List<Contact> allContacts = new ArrayList<Contact>();

    @Override
    public int addFutureMeeting(Set<Contact> contacts, Calendar date) {
        readSerializedData();
        int ID = (int)(Math.random()*500 + 1000); 
        FutureMeetingImpl fm = new FutureMeetingImpl(contacts, ID, date);
        futureMeetingArray.add(fm);
        makeNewFolder();
        try {
             FileOutputStream fileOut = new FileOutputStream("./serialized/newfuturemeeting1.out");
             ObjectOutputStream out = new ObjectOutputStream(fileOut);
             out.writeObject(futureMeetingArray); //This is so I can use later methods down where you need to get specific meetings in list form
             out.close();
             fileOut.close();
        }catch(IOException i) {
             i.printStackTrace();
        }
          contactAdder(contacts);
        return  ID;
    }

    @Override
    public List<Meeting> getMeetingListOn(Calendar date) {
        readSerializedData();
        SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
        String formatted = format1.format(date.getTime());
        List<Meeting> meetings = new ArrayList<Meeting>();
        Meeting currentMeeting = futureMeetingArray.get(0);
        if(futureMeetingArray.size() > 0){
            for(int x = 0; x < futureMeetingArray.size(); x++){
                currentMeeting = futureMeetingArray.get(x);
                Calendar currentMeetingsDate = currentMeeting.getDate();
                System.out.println("s");
                if(currentMeetingsDate == date){
                    System.out.println("Adding future");
                    meetings.add(currentMeeting);
                }
            }
        }

            for (int p = 0; p < pastMeetingArray.size(); p++){
                Meeting currentMeetingPast = new PastMeetingImpl();
                SimpleDateFormat format3 = new SimpleDateFormat("yyyy-MM-dd");
                String formatted3 = format3.format(currentMeetingPast.getDate());
                System.out.println(formatted3);
                if(formatted3 == formatted){
                    System.out.println("Adding future");
                    meetings.add(currentMeetingPast);
                }
            }
        for(int y = 0; y < meetings.size(); y++){
            Meeting meetingPrint = meetings.get(y);
            System.out.println("Your list of meetings include meeting IDs: " + meetingPrint.getId());
        }
        return meetings;
    }
}

Archeofuturist
  • 215
  • 5
  • 18
  • It may not be an issue with serialization - I may be failing to use the Calendar class correctly. If anyone has any information on using this, I'd appreciate it – Archeofuturist Feb 26 '17 at 22:28

1 Answers1

0

I am not sure what "serialization" issue you are having here. But I see you are using "==" to compare objects. You should be using .equals or try using a comparator.

Refer this post for why you should not be using "==". Compare two objects with .equals() and == operator

Community
  • 1
  • 1
BadeMan
  • 1
  • 1
  • Thanks, I will amend this. However I still get the same result, with just the loop doing around the futureMeetingArray and not adding anything. The test I am using is this: `@Test public void testgetMeetingListOn(){ System.out.println("PRINTING THE DATE " + this.date); cm.getMeetingListOn(this.date); }` – Archeofuturist Feb 26 '17 at 22:18
  • Are you using the same date format, TimeZone and Locale when adding Date (Does the calendar instance you pass to addFutureMeeting() is in the same format, TimeZone and Locale as the date you are comparing against?) If you use ".equals" to compare then both dates you are comparing should be same including milliseconds. If you don't want to include time stamp in comparison, then compare year, month and date separately. – BadeMan Feb 26 '17 at 22:34