Here is the code for it, and it will make sense to put this class into the
com.packtpub.celebrities.util package:
package com.packtpub.celebrities.util;
import java.text.Format;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Formats
{
private static SimpleDateFormat simpleDateFormat =
new SimpleDateFormat("MM/dd/yyyy");
public static Date parseDate(String strDate)
{
Date date = null;
try
{
date = simpleDateFormat.parse(strDate);
} catch (ParseException ex)
{
throw new RuntimeException(ex);
}
return date;
}
public static Format getDateFormat()
{
return simpleDateFormat;
}
}
The code for the MockDataSource is quite simple, at times even primitive. For
example, the way that a "unique" ID is generated in the addCelebrity method is
good only for the case when no celebrities are ever deleted from the collection, but
for now, it is good enough.
Another two helper classes that we are going to need for Celebrity Collector are
User, to contain information about the application's users, and Security which
demonstrates an extremely simplified approach towards user authentication. You
will see the code of these classes below, and, of course, all the code from this chapter
can be found in the code package provided with the book.
Pages:
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123