Package com.yahoo.document.datatypes
Class WeightedSet<K extends FieldValue>
java.lang.Object
com.yahoo.vespa.objects.Selectable
com.yahoo.vespa.objects.Identifiable
com.yahoo.document.datatypes.FieldValue
com.yahoo.document.datatypes.CompositeFieldValue
com.yahoo.document.datatypes.CollectionFieldValue<K>
com.yahoo.document.datatypes.WeightedSet<K>
- All Implemented Interfaces:
Cloneable
,Comparable<FieldValue>
,Map<K,
Integer>
public final class WeightedSet<K extends FieldValue>
extends CollectionFieldValue<K>
implements Map<K,Integer>
A weighted set, a unique set of keys with an associated integer weight. This class
uses an encapsulated Map (actually a LinkedHashMap) that associates each key
with its weight (value).
- Author:
- Einar M R Rosenvinge
-
Nested Class Summary
-
Field Summary
Fields inherited from class com.yahoo.document.datatypes.FieldValue
classId
-
Constructor Summary
ConstructorDescriptionWeightedSet
(DataType type) Creates a new WeightedSet.WeightedSet
(DataType type, int initialCapacity) Creates a new weighted set with a given initial capacity. -
Method Summary
Modifier and TypeMethodDescriptionboolean
void
Assign this non-fieldvalue value to this field value.void
clear()
Remove all key-weight associations in this set.void
clearAndReserve
(int count) Reserve space for this amount of keys in order to avoid resizingclone()
int
compareTo
(FieldValue fieldValue) boolean
boolean
containsKey
(Object key) Checks whether this set contains the specified key.boolean
containsValue
(Object value) void
deserialize
(Field field, FieldReader reader) Read a field value from the specified readerentrySet()
boolean
Checks if another object is equal to this set.Returns the weight associated with the specified key.Used to retrieve wrapped type for simple types, such that you can use get methods to retrieve ints and floats directly instead of Int/Float field values.int
hashCode()
Uses hashCode() from the encapsulated Map.boolean
isEmpty()
Checks if this set is empty.iterator()
keySet()
void
Deprecated.Add a key with an associated weight to this set.void
putUnChecked
(K key, IntegerFieldValue weight) Add a key with an associated weight to this set.Remove a key-weight association from this set.boolean
void
serialize
(Field field, FieldWriter writer) Write out field value to the specified writerint
size()
Returns the number of key-weight pairs in this set.toString()
Uses toString() from the encapsulated Map.values()
Methods inherited from class com.yahoo.document.datatypes.CollectionFieldValue
createFieldValue, isEmpty, removeValue, verifyElementCompatibility
Methods inherited from class com.yahoo.document.datatypes.CompositeFieldValue
setDataType
Methods inherited from class com.yahoo.document.datatypes.FieldValue
create, deserialize, getRecursiveValue, getRecursiveValue, onDeserialize, onSerialize, serialize, toXml
Methods inherited from class com.yahoo.vespa.objects.Identifiable
create, createFromId, deserialize, deserializeOptional, deserializeWithId, equals, getClassId, getRawUtf8Bytes, getUtf8, onGetClassId, putUtf8, registerClass, serialize, serializeOptional, serializeWithId, visitMembers
Methods inherited from class com.yahoo.vespa.objects.Selectable
select, select, selectMembers
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Constructor Details
-
WeightedSet
Creates a new WeightedSet.- Parameters:
type
- the data type for the field that this weighted set is associated with
-
WeightedSet
Creates a new weighted set with a given initial capacity.- Parameters:
initialCapacity
- the initial capacity to use for the encapsulated Map
-
-
Method Details
-
getDataType
- Overrides:
getDataType
in classCollectionFieldValue<K extends FieldValue>
-
fieldValueIterator
- Specified by:
fieldValueIterator
in classCollectionFieldValue<K extends FieldValue>
-
assign
Description copied from class:FieldValue
Assign this non-fieldvalue value to this field value. This is used to be able to assign ints to Integer field values and List to Array field values and such.Override to accept the specific types that should be legal.
- Specified by:
assign
in classFieldValue
-
clone
- Overrides:
clone
in classFieldValue
-
printXml
Deprecated.- Specified by:
printXml
in classFieldValue
-
size
public int size()Returns the number of key-weight pairs in this set.- Specified by:
size
in interfaceMap<K extends FieldValue,
Integer> - Specified by:
size
in classCollectionFieldValue<K extends FieldValue>
- Returns:
- the number of key-weight pairs in this set
-
add
- Specified by:
add
in classCollectionFieldValue<K extends FieldValue>
-
getWrappedValue
Description copied from class:FieldValue
Used to retrieve wrapped type for simple types, such that you can use get methods to retrieve ints and floats directly instead of Int/Float field values. Complex types that can't be specified by simple java types just return themselves.- Overrides:
getWrappedValue
in classFieldValue
-
contains
- Specified by:
contains
in classCollectionFieldValue<K extends FieldValue>
-
isEmpty
public boolean isEmpty()Checks if this set is empty.- Specified by:
isEmpty
in interfaceMap<K extends FieldValue,
Integer> - Specified by:
isEmpty
in classCollectionFieldValue<K extends FieldValue>
- Returns:
- true if the set is empty
-
iterator
- Specified by:
iterator
in classCollectionFieldValue<K extends FieldValue>
-
removeValue
- Specified by:
removeValue
in classCollectionFieldValue<K extends FieldValue>
-
containsKey
Checks whether this set contains the specified key.- Specified by:
containsKey
in interfaceMap<K extends FieldValue,
Integer> - Parameters:
key
- the key to search for- Returns:
- true if this set contains this key
-
containsValue
- Specified by:
containsValue
in interfaceMap<K extends FieldValue,
Integer>
-
get
Returns the weight associated with the specified key.- Specified by:
get
in interfaceMap<K extends FieldValue,
Integer> - Parameters:
key
- the key to return the weight for- Returns:
- the weight associated with the specified key, or null (if not found)
-
put
Add a key with an associated weight to this set. If the key is already present in this set, the previous association is replaced. Checks to validate that all keys are of the same type.- Specified by:
put
in interfaceMap<K extends FieldValue,
Integer> - Parameters:
key
- the key to addweight
- the weight to associate with this key- Returns:
- the weight that was previously associated with this key, or null (if there was no previous key)
-
putUnChecked
Add a key with an associated weight to this set. If the key is already present in this set, the previous association is replaced.- Parameters:
key
- the key to addweight
- the weight to associate with this key- Returns:
- the weight that was previously associated with this key, or null (if there was no previous key)
-
remove
Remove a key-weight association from this set.- Specified by:
remove
in interfaceMap<K extends FieldValue,
Integer> - Parameters:
key
- the key to remove- Returns:
- the weight that was previously associated with this key, or null (if there was no previous key)
-
putAll
- Specified by:
putAll
in interfaceMap<K extends FieldValue,
Integer>
-
clear
public void clear()Remove all key-weight associations in this set.- Specified by:
clear
in interfaceMap<K extends FieldValue,
Integer> - Specified by:
clear
in classFieldValue
-
clearAndReserve
public void clearAndReserve(int count) Reserve space for this amount of keys in order to avoid resizing -
values
- Specified by:
values
in interfaceMap<K extends FieldValue,
Integer>
-
keySet
- Specified by:
keySet
in interfaceMap<K extends FieldValue,
Integer>
-
entrySet
- Specified by:
entrySet
in interfaceMap<K extends FieldValue,
Integer>
-
equals
Checks if another object is equal to this set.- Specified by:
equals
in interfaceMap<K extends FieldValue,
Integer> - Overrides:
equals
in classCompositeFieldValue
- Parameters:
o
- the object to check for equality with- Returns:
- true if o is an instance of WeightedSet and the two encapsulated Maps are equal, false otherwise
-
hashCode
public int hashCode()Uses hashCode() from the encapsulated Map.- Specified by:
hashCode
in interfaceMap<K extends FieldValue,
Integer> - Overrides:
hashCode
in classCompositeFieldValue
- Returns:
- the hash code of this set
-
toString
Uses toString() from the encapsulated Map.- Overrides:
toString
in classcom.yahoo.vespa.objects.Identifiable
- Returns:
- the toString() of this set
-
serialize
Description copied from class:FieldValue
Write out field value to the specified writer- Specified by:
serialize
in classFieldValue
-
deserialize
Description copied from class:FieldValue
Read a field value from the specified reader- Specified by:
deserialize
in classFieldValue
-
compareTo
- Specified by:
compareTo
in interfaceComparable<K extends FieldValue>
- Overrides:
compareTo
in classFieldValue
-