カレンダーの例外を追加および削除します
カレンダーの例外を扱う CalendarExceptionクラスは、カレンダーの例外オブジェクトを表すために使用されます。 ExceptionCollectionクラスは、既存の例外を取得し、追加された新しい例外を管理し、既存の例外を削除するために使用できるプロジェクトクラスのgetCalendars()メソッドを使用して取得できます。
プログラミングサンプル
次の例は、Javaを使用して例外を追加、削除、表示する方法を示しています。
1// The path to the documents directory.
2String dataDir = Utils.getDataDir(AddRemoveCalendarExceptions.class);
3
4Project project = new Project(dataDir + "input.mpp");
5
6//Remove an exception
7Calendar cal = project.getCalendars().toList().get(0);
8if (cal.getExceptions().size() > 1)
9{
10 CalendarException exc = cal.getExceptions().toList().get(0);
11 cal.getExceptions().remove(exc);
12}
13
14//Add an exception
15CalendarException calExc = new CalendarException();
16
17java.util.Calendar calObject = java.util.Calendar.getInstance();
18calObject.set(2009, 1, 1, 0, 0, 0);
19calExc.setFromDate(calObject.getTime());
20
21calObject.set(2009, 1, 3, 0, 0, 0);
22calExc.setToDate(calObject.getTime());
23
24cal.getExceptions().add(calExc);
25
26//Display exceptions
27for(CalendarException calExc1:cal.getExceptions())
28{
29 System.out.println("From" + calExc1.getFromDate().toString());
30 System.out.println("To" + calExc1.getToDate().toString());
31}