public final class GenericBooleanPrefDataModel extends AbstractDataModel
A simple DataModel
which uses given user data as its data source. This implementation
is mostly useful for small experiments and is not recommended for contexts where performance is important.
Constructor and Description |
---|
GenericBooleanPrefDataModel(DataModel dataModel)
Deprecated.
without direct replacement.
Consider
toDataMap(DataModel) with GenericBooleanPrefDataModel(FastByIDMap) |
GenericBooleanPrefDataModel(FastByIDMap<FastIDSet> userData)
Creates a new
GenericDataModel from the given users (and their preferences). |
GenericBooleanPrefDataModel(FastByIDMap<FastIDSet> userData,
FastByIDMap<FastByIDMap<Long>> timestamps)
Creates a new
GenericDataModel from the given users (and their preferences). |
Modifier and Type | Method and Description |
---|---|
LongPrimitiveArrayIterator |
getItemIDs() |
FastIDSet |
getItemIDsFromUser(long userID) |
int |
getNumItems() |
int |
getNumUsers() |
int |
getNumUsersWithPreferenceFor(long itemID) |
int |
getNumUsersWithPreferenceFor(long itemID1,
long itemID2) |
PreferenceArray |
getPreferencesForItem(long itemID) |
PreferenceArray |
getPreferencesFromUser(long userID) |
Long |
getPreferenceTime(long userID,
long itemID)
Retrieves the time at which a preference value from a user and item was set, if known.
|
Float |
getPreferenceValue(long userID,
long itemID)
Retrieves the preference value for a single user and item.
|
FastByIDMap<FastIDSet> |
getRawItemData()
This is used mostly internally to the framework, and shouldn't be relied upon otherwise.
|
FastByIDMap<FastIDSet> |
getRawUserData()
This is used mostly internally to the framework, and shouldn't be relied upon otherwise.
|
LongPrimitiveArrayIterator |
getUserIDs() |
boolean |
hasPreferenceValues() |
void |
refresh(Collection<Refreshable> alreadyRefreshed)
Triggers "refresh" -- whatever that means -- of the implementation.
|
void |
removePreference(long userID,
long itemID)
Removes a particular preference for a user.
|
void |
setPreference(long userID,
long itemID,
float value)
Sets a particular preference (item plus rating) for a user.
|
static FastByIDMap<FastIDSet> |
toDataMap(DataModel dataModel)
Exports the simple user IDs and associated item IDs in the data model.
|
static FastByIDMap<FastIDSet> |
toDataMap(FastByIDMap<PreferenceArray> data) |
String |
toString() |
getMaxPreference, getMinPreference, setMaxPreference, setMinPreference
public GenericBooleanPrefDataModel(FastByIDMap<FastIDSet> userData)
Creates a new GenericDataModel
from the given users (and their preferences). This
DataModel
retains all this information in memory and is effectively immutable.
userData
- users to includepublic GenericBooleanPrefDataModel(FastByIDMap<FastIDSet> userData, FastByIDMap<FastByIDMap<Long>> timestamps)
Creates a new GenericDataModel
from the given users (and their preferences). This
DataModel
retains all this information in memory and is effectively immutable.
userData
- users to includetimestamps
- optionally, provided timestamps of preferences as milliseconds since the epoch.
User IDs are mapped to maps of item IDs to Long timestamps.@Deprecated public GenericBooleanPrefDataModel(DataModel dataModel) throws TasteException
toDataMap(DataModel)
with GenericBooleanPrefDataModel(FastByIDMap)
Creates a new GenericDataModel
containing an immutable copy of the data from another given
DataModel
.
dataModel
- DataModel
to copyTasteException
- if an error occurs while retrieving the other DataModel
's userspublic static FastByIDMap<FastIDSet> toDataMap(DataModel dataModel) throws TasteException
FastByIDMap
mapping user IDs to FastIDSet
s representing
that user's associated itemsTasteException
public static FastByIDMap<FastIDSet> toDataMap(FastByIDMap<PreferenceArray> data)
public FastByIDMap<FastIDSet> getRawUserData()
public FastByIDMap<FastIDSet> getRawItemData()
public LongPrimitiveArrayIterator getUserIDs()
public PreferenceArray getPreferencesFromUser(long userID) throws NoSuchUserException
userID
- ID of user to get prefs forNoSuchUserException
- if there is no such userpublic FastIDSet getItemIDsFromUser(long userID) throws TasteException
userID
- ID of user to get prefs forNoSuchUserException
- if the user does not existTasteException
- if an error occurs while accessing the datapublic LongPrimitiveArrayIterator getItemIDs()
LongPrimitiveIterator
of all item IDs in the model, in orderpublic PreferenceArray getPreferencesForItem(long itemID) throws NoSuchItemException
itemID
- item IDPreference
s expressed for that item, ordered by user ID, as an arrayNoSuchItemException
- if the item does not existpublic Float getPreferenceValue(long userID, long itemID) throws NoSuchUserException
DataModel
userID
- user ID to get pref value fromitemID
- item ID to get pref value forNoSuchUserException
- if the user does not existpublic Long getPreferenceTime(long userID, long itemID) throws TasteException
DataModel
userID
- user ID for preference in questionitemID
- item ID for preference in questionNoSuchUserException
- if the user does not existTasteException
- if an error occurs while accessing the datapublic int getNumItems()
public int getNumUsers()
public int getNumUsersWithPreferenceFor(long itemID)
itemID
- item ID to check forpublic int getNumUsersWithPreferenceFor(long itemID1, long itemID2)
itemID1
- first item ID to check foritemID2
- second item ID to check forpublic void removePreference(long userID, long itemID)
DataModel
Removes a particular preference for a user.
userID
- user from which to remove preferenceitemID
- item to remove preference forpublic void setPreference(long userID, long itemID, float value)
DataModel
Sets a particular preference (item plus rating) for a user.
userID
- user to set preference foritemID
- item to set preference forvalue
- preference valuepublic void refresh(Collection<Refreshable> alreadyRefreshed)
Refreshable
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.
alreadyRefreshed
- Refreshable
s that are known to have already been
refreshed as a result of an initial call to a {#refresh(Collection)} method on some
object. This ensure that objects in a refresh dependency graph aren't refreshed twice
needlessly.public boolean hasPreferenceValues()
Copyright © 2008–2015 The Apache Software Foundation. All rights reserved.