001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package com.sun.kvem.midp.pim;
028:
029: import java.util.Enumeration;
030: import java.util.Vector;
031: import javax.microedition.pim.PIM;
032: import javax.microedition.pim.PIMException;
033: import javax.microedition.pim.PIMItem;
034: import javax.microedition.pim.ToDo;
035: import javax.microedition.pim.ToDoList;
036:
037: /**
038: * Class ToDoListImpl implements methods of PIM interface ToDoList.
039: *
040: */
041: class ToDoListImpl extends AbstractPIMList implements ToDoList {
042: /**
043: * Construct a ToDo handler.
044: * @param name descriptive name for list
045: * @param mode access mode
046: * @param handle handle of the list
047: */
048: ToDoListImpl(String name, int mode, Object handle) {
049: super (PIM.TODO_LIST, name, mode, handle);
050: }
051:
052: /**
053: * Creates a ToDo entry.
054: * @return ToDo entry
055: */
056: public ToDo createToDo() {
057: return new ToDoImpl(this );
058: }
059:
060: /**
061: * Initializes a ToDo entry from a previous item.
062: * @param item template containing input data
063: * @return initialized ToDo entry
064: */
065: public ToDo importToDo(ToDo item) {
066: return new ToDoImpl(this , item);
067: }
068:
069: /**
070: * Gets an Enumeration of the items in the list.
071: * @param field identifier of field
072: * @param startDate beginning of range
073: * @param endDate end of range
074: * @return Enumeration of matching events
075: */
076: public Enumeration items(int field, long startDate, long endDate)
077: throws PIMException {
078: if (getFieldDataType(field) != PIMItem.DATE) {
079: throw new IllegalArgumentException("Not a DATE field");
080: }
081: if (endDate < startDate) {
082: throw new IllegalArgumentException("Start date"
083: + " must precede end date");
084: }
085: Vector results = new Vector();
086: Vector keys = new Vector();
087: for (Enumeration e = items(); e.hasMoreElements();) {
088: ToDo item = (ToDo) e.nextElement();
089: int indices = item.countValues(field);
090: for (int i = 0; i < indices; i++) {
091: long date = item.getDate(field, i);
092: if (date >= startDate && date <= endDate) {
093: // include result
094: KeySortUtility.store(keys, results, date, item);
095: break;
096: }
097: }
098: }
099: return results.elements();
100: }
101:
102: /**
103: * Removes an entry from a ToDo list.
104: * @param item the entry to be removed
105: * @throws PIMException if the item is not int the list
106: */
107: public void removeToDo(ToDo item) throws PIMException {
108: removeItem(item);
109: }
110:
111: }
|