public final class GenericUserPreferenceArray extends Object implements PreferenceArray
Like GenericItemPreferenceArray
but stores preferences for one user (all user IDs the same) rather
than one item.
This implementation maintains two parallel arrays, of item IDs and values. The idea is to save allocating
Preference
objects themselves. This saves the overhead of Preference
objects but also
duplicating the user ID value.
Constructor and Description |
---|
GenericUserPreferenceArray(int size) |
GenericUserPreferenceArray(List<? extends Preference> prefs) |
Modifier and Type | Method and Description |
---|---|
GenericUserPreferenceArray |
clone() |
boolean |
equals(Object other) |
Preference |
get(int i) |
long[] |
getIDs() |
long |
getItemID(int i) |
long |
getUserID(int i) |
float |
getValue(int i) |
int |
hashCode() |
boolean |
hasPrefWithItemID(long itemID) |
boolean |
hasPrefWithUserID(long userID) |
Iterator<Preference> |
iterator() |
int |
length() |
void |
set(int i,
Preference pref)
Sets preference at i from information in the given
Preference |
void |
setItemID(int i,
long itemID)
Sets item ID for preference at i.
|
void |
setUserID(int i,
long userID)
Sets user ID for preference at i.
|
void |
setValue(int i,
float value)
Sets preference value for preference at i.
|
void |
sortByItem()
Sorts underlying array by item ID, ascending.
|
void |
sortByUser()
Sorts underlying array by user ID, ascending.
|
void |
sortByValue()
Sorts underlying array by preference value, ascending.
|
void |
sortByValueReversed()
Sorts underlying array by preference value, descending.
|
String |
toString() |
finalize, getClass, notify, notifyAll, wait, wait, wait
forEach, spliterator
public GenericUserPreferenceArray(int size)
public GenericUserPreferenceArray(List<? extends Preference> prefs)
public int length()
length
in interface PreferenceArray
public Preference get(int i)
get
in interface PreferenceArray
i
- indexPreference
representation of the preference at ipublic void set(int i, Preference pref)
PreferenceArray
Preference
set
in interface PreferenceArray
public long getUserID(int i)
getUserID
in interface PreferenceArray
i
- indexpublic void setUserID(int i, long userID)
setUserID
in interface PreferenceArray
i
- indexuserID
- new user IDpublic long getItemID(int i)
getItemID
in interface PreferenceArray
i
- indexpublic void setItemID(int i, long itemID)
PreferenceArray
setItemID
in interface PreferenceArray
i
- indexitemID
- new item IDpublic long[] getIDs()
getIDs
in interface PreferenceArray
public float getValue(int i)
getValue
in interface PreferenceArray
i
- indexpublic void setValue(int i, float value)
PreferenceArray
setValue
in interface PreferenceArray
i
- indexvalue
- new preference valuepublic void sortByUser()
PreferenceArray
sortByUser
in interface PreferenceArray
public void sortByItem()
PreferenceArray
sortByItem
in interface PreferenceArray
public void sortByValue()
PreferenceArray
sortByValue
in interface PreferenceArray
public void sortByValueReversed()
PreferenceArray
sortByValueReversed
in interface PreferenceArray
public boolean hasPrefWithUserID(long userID)
hasPrefWithUserID
in interface PreferenceArray
userID
- user IDpublic boolean hasPrefWithItemID(long itemID)
hasPrefWithItemID
in interface PreferenceArray
itemID
- item IDpublic GenericUserPreferenceArray clone()
clone
in interface PreferenceArray
clone
in class Object
public Iterator<Preference> iterator()
iterator
in interface Iterable<Preference>
Copyright © 2008–2017 The Apache Software Foundation. All rights reserved.