views:

131

answers:

4

I have a hobby project, which is basically to maintain 'todo' tasks in the way I like. One task can be described as:

public class TodoItem {
    private String subject;
    private Date dueBy;
    private Date startBy;
    private Priority priority;
    private String category;
    private Status status;
    private String notes;
}

As you can imagine I would have 1000s of todo items at a given time.

  • What is the best strategy to store a todo item? (currently on an XML file) such that all the items are loaded quickly up on app start up(the application shows kind of a dashboard of all the items at start up)?
  • What is the best way to design its back-end so that it can be ported to Android/or a J2ME based phone?
  • Currently this is done using Java Swing. What should I concentrate on so that it works efficiently on a device where memory is limited?
  • The application throws open a form to enter new todo task. For now, I would like to save the newly added task to my-todos.xml once the user presses "save" button. What are the common ways to append such a change to an existing XML file?(note that I don't want to read the whole file again and then persist)
+1  A: 

As with any programming question there are a lot of ways to do things. However, by specifying that you are intending to go to a phone, you list of considerations changes. Firstly you need to look at your intended phones to see what they support. Especially in terms of data storage.

Xml or some other flat file format will work fine if you don't have too much data and don't want to enable searching and other functions which will access the data in random ways.

But if you want to store larger amounts of data or do random access, you need to look into data storage techniques that are more database like. This is where you intended target platforms are likely to impose limits in terms of performance or storage limits.

The other alternative is that you design the application so that it's storage os decoupled from the core program. This means that you can apply different types of data storage, depending on whether it's a PC or phone, yet not have to recode everything else.

Derek Clarkson
+3  A: 

For storing: SQLite seems like a good solution for things such as searching and cross platform support. Android and many other devices support SQLite.

Joel
Indeed, it's easy to write an Android app to work with SQL databases. I've never tried importing an external DB into an app, but I know it can be done (for example, see http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/).
Steve H
A: 

One option that comes to mind is an in-memory DB, which exists in various flavors. I've yet to use one of these, so I can't tell you about memory usage or platform constraints. Still, it's worth looking at.

Another option that comes to mind is to maintain a large collection of TodoItem objects, and write your own code to read from and persist this collection to the XML file. Essentially, build a class that contains the large Map (or whatever you decide to use) and have this class implement Externalizable.

Both of these options will allow you to read the XML file to its in-memory representation, search and alter the state, and eventually write the final state back to XML when the app goes down (or at fixed intervals, whatever you decide).

Yuval
A: 

You might be able to use java.util.prefs.Preferences.

Catalina Island