Java Application Design Issue
I have a hobby project that basically supports todo tasks the way I like it. 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 1000 todo items at a given time.
- What's the best storage strategy for todo item? (currently in an XML file) so all items are loaded quickly to start working with the application (the application shows a bar view of all items on startup)?
- What is the best way to develop so that it can be ported to an Android / or J2ME phone?
- This is currently being done using Java Swing. What should I focus on so that it works efficiently on a device with limited memory?
- The app opens a form to enter a new todo task. For now, I would like to save the newly added task my-todos.xml after the user clicks the Save button. What are the general ways to add such a change to an existing XML file? (note that I don't want to read the whole file again and then save)
a source to share
As with any programming question, there are many ways to do something. However, by indicating that you intend to switch to the phone, you are listing the change considerations. First, you need to look at your phones to see what they support. Especially in terms of data storage.
Xml or some other flat file format will work fine if you have too much data and don't want to include search and other functions that will randomly access the data.
But if you want to store large amounts of data or do random access, you need to learn data storage techniques that are more like a database. Here you are assuming that the target platforms may impose constraints in terms of performance or storage.
Another alternative is that you design your application so that the repository is separate from the main program. This means that you can apply different types of storage depending on whether it is a PC or a phone, but you don't need to recode everything else.
a source to share
One option that comes to mind is an in-memory database that comes in various flavors. I haven't used one of them yet, so I can't tell you about memory usage or platform limitations. Still worth a look.
Another option that comes to mind is to maintain a large collection of objects TodoItem
and write your own code to read and save that collection to an XML file. Essentially, create a class containing a large map (or whatever you decide to use) and implement that class Externalizable
.
Both of these options will allow you to read the XML file in its memory representation, search and change state, and eventually write the final state back to XML when the application goes down (or at fixed intervals, whatever you decide).
a source to share