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
ConstructorsConstructorDescriptionWeightedSet(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 TypeMethodDescriptionbooleanvoidAssign this non-fieldvalue value to this field value.voidclear()Remove all key-weight associations in this set.voidclearAndReserve(int count) Reserve space for this amount of keys in order to avoid resizingclone()intcompareTo(FieldValue fieldValue) booleanbooleancontainsKey(Object key) Checks whether this set contains the specified key.booleancontainsValue(Object value) voiddeserialize(Field field, FieldReader reader) Read a field value from the specified readerentrySet()booleanChecks 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.inthashCode()Uses hashCode() from the encapsulated Map.booleanisEmpty()Checks if this set is empty.iterator()keySet()voidDeprecated.Add a key with an associated weight to this set.voidputUnChecked(K key, IntegerFieldValue weight) Add a key with an associated weight to this set.Remove a key-weight association from this set.booleanvoidserialize(Field field, FieldWriter writer) Write out field value to the specified writerintsize()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, verifyElementCompatibilityMethods inherited from class com.yahoo.document.datatypes.CompositeFieldValue
setDataTypeMethods inherited from class com.yahoo.document.datatypes.FieldValue
create, deserialize, getRecursiveValue, getRecursiveValue, onDeserialize, onSerialize, serialize, toXmlMethods inherited from class com.yahoo.vespa.objects.Identifiable
create, createFromId, deserialize, deserializeOptional, deserializeWithId, equals, getClassId, getRawUtf8Bytes, getUtf8, onGetClassId, putUtf8, registerClass, registerClass, serialize, serializeOptional, serializeWithId, visitMembersMethods inherited from class com.yahoo.vespa.objects.Selectable
select, select, selectMembersMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods 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:
getDataTypein classCollectionFieldValue<K extends FieldValue>
-
fieldValueIterator
- Specified by:
fieldValueIteratorin classCollectionFieldValue<K extends FieldValue>
-
assign
Description copied from class:FieldValueAssign 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:
assignin classFieldValue
-
clone
- Overrides:
clonein classFieldValue
-
printXml
Deprecated.- Specified by:
printXmlin classFieldValue
-
size
public int size()Returns the number of key-weight pairs in this set.- Specified by:
sizein interfaceMap<K extends FieldValue,Integer> - Specified by:
sizein classCollectionFieldValue<K extends FieldValue>- Returns:
- the number of key-weight pairs in this set
-
add
- Specified by:
addin classCollectionFieldValue<K extends FieldValue>
-
getWrappedValue
Description copied from class:FieldValueUsed 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:
getWrappedValuein classFieldValue
-
contains
- Specified by:
containsin classCollectionFieldValue<K extends FieldValue>
-
isEmpty
public boolean isEmpty()Checks if this set is empty.- Specified by:
isEmptyin interfaceMap<K extends FieldValue,Integer> - Specified by:
isEmptyin classCollectionFieldValue<K extends FieldValue>- Returns:
- true if the set is empty
-
iterator
- Specified by:
iteratorin classCollectionFieldValue<K extends FieldValue>
-
removeValue
- Specified by:
removeValuein classCollectionFieldValue<K extends FieldValue>
-
containsKey
Checks whether this set contains the specified key.- Specified by:
containsKeyin interfaceMap<K extends FieldValue,Integer> - Parameters:
key- the key to search for- Returns:
- true if this set contains this key
-
containsValue
- Specified by:
containsValuein interfaceMap<K extends FieldValue,Integer>
-
get
Returns the weight associated with the specified key.- Specified by:
getin 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:
putin 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:
removein 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:
putAllin interfaceMap<K extends FieldValue,Integer>
-
clear
public void clear()Remove all key-weight associations in this set.- Specified by:
clearin interfaceMap<K extends FieldValue,Integer> - Specified by:
clearin classFieldValue
-
clearAndReserve
public void clearAndReserve(int count) Reserve space for this amount of keys in order to avoid resizing -
values
- Specified by:
valuesin interfaceMap<K extends FieldValue,Integer>
-
keySet
- Specified by:
keySetin interfaceMap<K extends FieldValue,Integer>
-
entrySet
- Specified by:
entrySetin interfaceMap<K extends FieldValue,Integer>
-
equals
Checks if another object is equal to this set.- Specified by:
equalsin interfaceMap<K extends FieldValue,Integer> - Overrides:
equalsin 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:
hashCodein interfaceMap<K extends FieldValue,Integer> - Overrides:
hashCodein classCompositeFieldValue- Returns:
- the hash code of this set
-
toString
Uses toString() from the encapsulated Map.- Overrides:
toStringin classcom.yahoo.vespa.objects.Identifiable- Returns:
- the toString() of this set
-
serialize
Description copied from class:FieldValueWrite out field value to the specified writer- Specified by:
serializein classFieldValue
-
deserialize
Description copied from class:FieldValueRead a field value from the specified reader- Specified by:
deserializein classFieldValue
-
compareTo
- Specified by:
compareToin interfaceComparable<K extends FieldValue>- Overrides:
compareToin classFieldValue
-