|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.planetj.taste.impl.model.file.FileDataModel
public class FileDataModel
A DataModel backed by a comma-delimited file. This class assumes that each line of the
file contains a user ID, followed by item ID, followed by preferences value, separated by commas.
The preference value is assumed to be parseable as a double. The user and item IDs
are ready literally as Strings and treated as such in the API. Note that this means that whitespace
matters in the data file; they will be treated as part of the ID values.
This class is not intended for use with very large amounts of data (over, say, a million rows). For
that, MySQLJDBCDataModel and a database are more appropriate.
The file will be periodically reloaded if a change is detected.
| Constructor Summary | |
|---|---|
FileDataModel(java.io.File dataFile)
|
|
| Method Summary | |
|---|---|
protected Item |
buildItem(java.lang.String id)
Subclasses may override to return a different Item implementation. |
protected Preference |
buildPreference(User user,
Item item,
double value)
Subclasses may override to return a different Preference implementation. |
protected User |
buildUser(java.lang.String id,
java.util.List<Preference> prefs)
Subclasses may override to return a different User implementation. |
Item |
getItem(java.lang.Object id)
|
java.lang.Iterable<? extends Item> |
getItems()
|
int |
getNumItems()
|
int |
getNumUsers()
|
java.lang.Iterable<? extends Preference> |
getPreferencesForItem(java.lang.Object itemID)
|
Preference[] |
getPreferencesForItemAsArray(java.lang.Object itemID)
|
User |
getUser(java.lang.Object id)
|
java.lang.Iterable<? extends User> |
getUsers()
|
void |
refresh()
Triggers "refresh" -- whatever that means -- of the implementation. |
protected void |
reload()
|
void |
removePreference(java.lang.Object userID,
java.lang.Object itemID)
Removes a particular preference for a user. |
void |
setPreference(java.lang.Object userID,
java.lang.Object itemID,
double value)
Sets a particular preference (item plus rating) for a user. |
java.lang.String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public FileDataModel(java.io.File dataFile)
throws java.io.FileNotFoundException
dataFile - file containing preferences data
java.io.FileNotFoundException - if dataFile does not exist| Method Detail |
|---|
protected void reload()
throws java.io.IOException
java.io.IOException
@NotNull
public java.lang.Iterable<? extends User> getUsers()
throws TasteException
getUsers in interface DataModelList of all Users in the model, ordered by User
TasteException - if an error occurs while accessing the data
@NotNull
public User getUser(java.lang.Object id)
throws TasteException
getUser in interface DataModelid - user ID
User who has that ID
java.util.NoSuchElementException - if there is no such user
TasteException - if an error occurs while accessing the data
@NotNull
public java.lang.Iterable<? extends Item> getItems()
throws TasteException
getItems in interface DataModelList of all Items in the model, order by Item
TasteException - if an error occurs while accessing the data
@NotNull
public Item getItem(java.lang.Object id)
throws TasteException
getItem in interface DataModelid - item ID
Item that has that ID
TasteException - if an error occurs while accessing the data
@NotNull
public java.lang.Iterable<? extends Preference> getPreferencesForItem(java.lang.Object itemID)
throws TasteException
getPreferencesForItem in interface DataModelitemID - item ID
Preferences expressed for that item, ordered by User
TasteException - if an error occurs while accessing the data
@NotNull
public Preference[] getPreferencesForItemAsArray(java.lang.Object itemID)
throws TasteException
getPreferencesForItemAsArray in interface DataModelitemID - item ID
Preferences expressed for that item, ordered by User,
as an array
TasteException - if an error occurs while accessing the data
public int getNumItems()
throws TasteException
getNumItems in interface DataModelItems known to the model. This is generally the union
of all Items preferred by at least one User but could include more.
TasteException - if an error occurs while accessing the data
public int getNumUsers()
throws TasteException
getNumUsers in interface DataModelUsers known to the model.
TasteException - if an error occurs while accessing the data
public void setPreference(java.lang.Object userID,
java.lang.Object itemID,
double value)
DataModelSets a particular preference (item plus rating) for a user.
setPreference in interface DataModeluserID - user to set preference foritemID - item to set preference forvalue - preference value
java.lang.UnsupportedOperationException
public void removePreference(java.lang.Object userID,
java.lang.Object itemID)
DataModelRemoves a particular preference for a user.
removePreference in interface DataModeluserID - user from which to remove preferenceitemID - item to remove preference for
java.lang.UnsupportedOperationExceptionpublic void refresh()
Triggers "refresh" -- whatever that means -- of the implementation. The general contract is that
any Refreshable should always leave itself in a consistent, operational state, and that
the refresh atomically updates internal state from old to new.
refresh in interface Refreshable
@NotNull
protected User buildUser(java.lang.String id,
java.util.List<Preference> prefs)
User implementation.
id - user IDprefs - user preferences
GenericUser by default@NotNull protected Item buildItem(java.lang.String id)
Item implementation.
id - item ID
GenericItem by default
@NotNull
protected Preference buildPreference(User user,
Item item,
double value)
Preference implementation.
user - User who expresses the preferenceitem - preferred Itemvalue - preference value
GenericPreference by default@NotNull public java.lang.String toString()
toString in class java.lang.Object
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||