diff --git a/src/main/java/org/ntlab/citrusserver/repositories/ScheduleManager.java b/src/main/java/org/ntlab/citrusserver/repositories/ScheduleManager.java index 13a5982..cd816c4 100644 --- a/src/main/java/org/ntlab/citrusserver/repositories/ScheduleManager.java +++ b/src/main/java/org/ntlab/citrusserver/repositories/ScheduleManager.java @@ -9,7 +9,7 @@ import java.util.HashMap; @Repository -public class ScheduleManager implements IBookListener{ +public class ScheduleManager implements IBookListener { private final BookManager bookManager; @@ -19,55 +19,60 @@ public ScheduleManager(BookManager bookManager) { this.bookManager = bookManager; this.bookManager.addListener(this); + this.addSchedule("fish", 2024, 5, 28, "chinema", "10;00", "12:00", 0); + this.addSchedule("fish", 2024, 5, 28, "test", "15;00", "18:00", 1); + this.addSchedule("bird", 2024, 5, 28, "chinema", "10;00", "12:00", 0); + this.addSchedule("bird", 2024, 5, 28, "test", "15;00", "18:00", 1); + } //管理 private final HashMap>>>> schedules + HashMap>>>> schedules = new HashMap<>(); - public HashMap>>> getScheduleAll(String accountId) { + public HashMap>>> getScheduleAll(String accountId) { return schedules.get(accountId); } - public HashMap>> getScheduleYear(String accountId, int year){ + public HashMap>> getScheduleYear(String accountId, int year) { return schedules.get(accountId).get(year); } - public HashMap> getScheduleMonth(String accountId, int year, int month){ + public HashMap> getScheduleMonth(String accountId, int year, int month) { return schedules.get(accountId).get(year).get(month); } - public HashMap getScheduleDay(String accountId, int year, int month, int day){ + public HashMap getScheduleDay(String accountId, int year, int month, int day) { return schedules.get(accountId).get(year).get(month).get(day); } - public Schedule addSchedule(String accountId, int year, int month, int day, String title, String startTime, String endTime, Integer bookId){ - if(bookId == null || bookId.equals(0)){ + public Schedule addSchedule(String accountId, int year, int month, int day, String title, String startTime, String endTime, Integer bookId) { + if (bookId == null || bookId.equals(0)) { bookId = 0; - } else if (bookManager.getBooks(accountId)==null) { + } else if (bookManager.getBooks(accountId) == null) { return null; - } else if(!bookManager.getBooks(accountId).containsKey(bookId))return null; + } else if (!bookManager.getBooks(accountId).containsKey(bookId)) return null; - if(!schedules.containsKey(accountId)){ + if (!schedules.containsKey(accountId)) { schedules.put(accountId, new HashMap<>()); } - if(!schedules.get(accountId).containsKey(year)){ + if (!schedules.get(accountId).containsKey(year)) { schedules.get(accountId).put(year, new HashMap<>()); } - if(!schedules.get(accountId).get(year).containsKey(month)){ + if (!schedules.get(accountId).get(year).containsKey(month)) { schedules.get(accountId).get(year).put(month, new HashMap<>()); } - if(!schedules.get(accountId).get(year).get(month).containsKey(day)){ + if (!schedules.get(accountId).get(year).get(month).containsKey(day)) { schedules.get(accountId).get(year).get(month).put(day, new HashMap<>()); } String accountSchedule = accountId + year + month + day;// - if(!nextScheduleId.containsKey(accountSchedule)){ + if (!nextScheduleId.containsKey(accountSchedule)) { nextScheduleId.put(accountSchedule, 0); } @@ -78,48 +83,48 @@ return newSchedule; } - public Schedule getScheduleId(String accountId, int year, int month, int day, int scheduleId){ + public Schedule getScheduleId(String accountId, int year, int month, int day, int scheduleId) { return schedules.get(accountId).get(year).get(month).get(day).get(scheduleId); } - public void deleteSchedule(String accountId, int year, int month, int day, int scheduleId){ + public void deleteSchedule(String accountId, int year, int month, int day, int scheduleId) { schedules.get(accountId).get(year).get(month).get(day).remove(scheduleId); } - public void setScheduleStartTime(String accountId, int year, int month, int day, int scheduleId, String newTime){ + public void setScheduleStartTime(String accountId, int year, int month, int day, int scheduleId, String newTime) { schedules.get(accountId).get(year).get(month).get(day).get(scheduleId).setStartTime(newTime); } - public void setScheduleEndTime(String accountId, int year, int month, int day, int scheduleId, String newTime){ + public void setScheduleEndTime(String accountId, int year, int month, int day, int scheduleId, String newTime) { schedules.get(accountId).get(year).get(month).get(day).get(scheduleId).setEndTime(newTime); } - public void changeScheduleTitle(String accountId, int year, int month, int day, int scheduleId, String newTitle){ + public void changeScheduleTitle(String accountId, int year, int month, int day, int scheduleId, String newTitle) { schedules.get(accountId).get(year).get(month).get(day).get(scheduleId).setTitle(newTitle); } //voidからintに変更 1で成功 -1でエラー処理 - public int setSchedulesBookId(String accountId, int year, int month, int day, int scheduleId, Integer newBookId){ - if(newBookId == null || newBookId.equals(0)){ + public int setSchedulesBookId(String accountId, int year, int month, int day, int scheduleId, Integer newBookId) { + if (newBookId == null || newBookId.equals(0)) { newBookId = 0; - }else if (bookManager.getBooks(accountId)==null) { + } else if (bookManager.getBooks(accountId) == null) { return -1; - }else if(!bookManager.getBooks(accountId).containsKey(newBookId))return -1; + } else if (!bookManager.getBooks(accountId).containsKey(newBookId)) return -1; schedules.get(accountId).get(year).get(month).get(day).get(scheduleId).setBookId(newBookId); return 1; } - public void deleteSchedules(String accountId){ + public void deleteSchedules(String accountId) { schedules.remove(accountId); } - public void deleteScheduleBookId(String accountId, Integer bookId){ - for(int year : schedules.get(accountId).keySet()){ - for (int month : schedules.get(accountId).get(year).keySet()){ - for(int day : schedules.get(accountId).get(year).get(month).keySet()){ - for (int scheduleId : schedules.get(accountId).get(year).get(month).get(day).keySet()){ - if(schedules.get(accountId).get(year).get(month).get(day).get(scheduleId).getBookId().equals(bookId)){ + public void deleteScheduleBookId(String accountId, Integer bookId) { + for (int year : schedules.get(accountId).keySet()) { + for (int month : schedules.get(accountId).get(year).keySet()) { + for (int day : schedules.get(accountId).get(year).get(month).keySet()) { + for (int scheduleId : schedules.get(accountId).get(year).get(month).get(day).keySet()) { + if (schedules.get(accountId).get(year).get(month).get(day).get(scheduleId).getBookId().equals(bookId)) { schedules.get(accountId).get(year).get(month).get(day).get(scheduleId).setBookId(0); } } @@ -136,11 +141,11 @@ @Override public void bookDeleted(Account accountIn, Book book) { String account = accountIn.getId(); - for(int year : schedules.get(account).keySet()){ - for (int month : schedules.get(account).get(year).keySet()){ - for(int day : schedules.get(account).get(year).get(month).keySet()){ - for (int scheduleId : schedules.get(account).get(year).get(month).get(day).keySet()){ - if(schedules.get(account).get(year).get(month).get(day).get(scheduleId).getBookId().equals(book.getBookId())){ + for (int year : schedules.get(account).keySet()) { + for (int month : schedules.get(account).get(year).keySet()) { + for (int day : schedules.get(account).get(year).get(month).keySet()) { + for (int scheduleId : schedules.get(account).get(year).get(month).get(day).keySet()) { + if (schedules.get(account).get(year).get(month).get(day).get(scheduleId).getBookId().equals(book.getBookId())) { schedules.get(account).get(year).get(month).get(day).get(scheduleId).setBookId(0); } } @@ -148,82 +153,4 @@ } } } - - public void autoAddSchedule(){ - String accountId1 = "fish"; - int year = 2024; - int month = 5; - int day = 28; - String title1 = "cinema"; - String startTime1 = "13:00"; - String endTime1 = "14:00"; - Integer bookId1 = 0; - - String accountId2 = "bird"; - - String title2 = "test"; - String startTime2 = "10:00"; - String endTime2 = "12:00"; - Integer bookId2 = 1; - - //account1 - if(!schedules.containsKey(accountId1)){ - schedules.put(accountId1, new HashMap<>()); - } - if(!schedules.get(accountId1).containsKey(year)){ - schedules.get(accountId1).put(year, new HashMap<>()); - } - if(!schedules.get(accountId1).get(year).containsKey(month)){ - schedules.get(accountId1).get(year).put(month, new HashMap<>()); - } - if(!schedules.get(accountId1).get(year).get(month).containsKey(day)){ - schedules.get(accountId1).get(year).get(month).put(day, new HashMap<>()); - } - - String accountSchedule1 = accountId1 + year + month + day;// - - if(!nextScheduleId.containsKey(accountSchedule1)){ - nextScheduleId.put(accountSchedule1, 0); - } - - int newScheduleId1 = nextScheduleId.get(accountSchedule1); - Schedule newSchedule11 = new Schedule(title1, startTime1, endTime1, bookId1, newScheduleId1); - Schedule newSchedule12 = new Schedule(title2, startTime2, endTime2, bookId2, newScheduleId1); - - schedules.get(accountId1).get(year).get(month).get(day).put(newScheduleId1, newSchedule11); - nextScheduleId.put(accountSchedule1, newScheduleId1 + 1); - - schedules.get(accountId1).get(year).get(month).get(day).put(newScheduleId1, newSchedule12); - nextScheduleId.put(accountSchedule1, newScheduleId1 + 1); - - //account2 - - if(!schedules.containsKey(accountId2)){ - schedules.put(accountId2, new HashMap<>()); - } - if(!schedules.get(accountId2).containsKey(year)){ - schedules.get(accountId2).put(year, new HashMap<>()); - } - if(!schedules.get(accountId2).get(year).containsKey(month)){ - schedules.get(accountId2).get(year).put(month, new HashMap<>()); - } - if(!schedules.get(accountId2).get(year).get(month).containsKey(day)){ - schedules.get(accountId2).get(year).get(month).put(day, new HashMap<>()); - } - - String accountSchedule2 = accountId2 + year + month + day;// - if(!nextScheduleId.containsKey(accountSchedule2)){ - nextScheduleId.put(accountSchedule2, 0); - } - - int newScheduleId2 = nextScheduleId.get(accountSchedule2); - Schedule newSchedule21 = new Schedule(title1, startTime1, endTime1 , bookId1, newScheduleId2); - Schedule newSchedule22 = new Schedule(title2, startTime2, endTime2 , bookId2, newScheduleId2); - - schedules.get(accountId2).get(year).get(month).get(day).put(newScheduleId2, newSchedule21); - nextScheduleId.put(accountSchedule2, newScheduleId2 + 1); - - schedules.get(accountId2).get(year).get(month).get(day).put(newScheduleId2, newSchedule22); - nextScheduleId.put(accountSchedule2, newScheduleId2 + 1); - } }