Class AbstractChar2ObjectFunction<V>
- java.lang.Object
-
- org.codelibs.jhighlight.fastutil.chars.AbstractChar2ObjectFunction<V>
-
- All Implemented Interfaces:
Serializable
,Char2ObjectFunction<V>
,Function<Character,V>
- Direct Known Subclasses:
AbstractChar2ObjectMap
,Char2ObjectFunctions.EmptyFunction
,Char2ObjectFunctions.Singleton
,Char2ObjectFunctions.SynchronizedFunction
,Char2ObjectFunctions.UnmodifiableFunction
public abstract class AbstractChar2ObjectFunction<V> extends Object implements Char2ObjectFunction<V>, Serializable
An abstract class providing basic methods for functions implementing a type-specific interface.Optional operations just throw an
UnsupportedOperationException
. Generic versions of accessors delegate to the corresponding type-specific counterparts following the interface rules (they take care of returningnull
on a missing key).This class handles directly a default return value (including methods to access it). Instances of classes inheriting from this class have just to return
defRetValue
to denote lack of a key in type-specific methods. The value is serialized.Implementing subclasses have just to provide type-specific
get()
, type-specificcontainsKey()
, andsize()
methods.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected V
defRetValue
The default return value forget()
,put()
andremove()
.
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractChar2ObjectFunction()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Removes all associations from this function (optional operation).boolean
containsKey(Object ok)
Returns true if this function contains a mapping for the specified key.V
defaultReturnValue()
Gets the default return value.void
defaultReturnValue(V rv)
Sets the default return value.V
get(Object ok)
Delegates to the corresponding type-specific method, taking care of returningnull
on a missing key.V
put(char key, V value)
Adds a pair to the map.V
put(Character ok, V ov)
Delegates to the corresponding type-specific method, taking care of returningnull
on a missing key.V
remove(char key)
Removes the mapping with the given key.V
remove(Object ok)
Delegates to the corresponding type-specific method, taking care of returningnull
on a missing key.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.codelibs.jhighlight.fastutil.chars.Char2ObjectFunction
containsKey, get
-
-
-
-
Field Detail
-
defRetValue
protected V defRetValue
The default return value forget()
,put()
andremove()
.
-
-
Method Detail
-
defaultReturnValue
public void defaultReturnValue(V rv)
Description copied from interface:Char2ObjectFunction
Sets the default return value. This value must be returned by type-specific versions ofget()
,put()
andremove()
to denote that the map does not contain the specified key. It must be 0/false
/null
by default.- Specified by:
defaultReturnValue
in interfaceChar2ObjectFunction<V>
- Parameters:
rv
- the new default return value.- See Also:
Char2ObjectFunction.defaultReturnValue()
-
defaultReturnValue
public V defaultReturnValue()
Description copied from interface:Char2ObjectFunction
Gets the default return value.- Specified by:
defaultReturnValue
in interfaceChar2ObjectFunction<V>
- Returns:
- the current default return value.
-
put
public V put(char key, V value)
Description copied from interface:Char2ObjectFunction
Adds a pair to the map.- Specified by:
put
in interfaceChar2ObjectFunction<V>
- Parameters:
key
- the key.value
- the value.- Returns:
- the old value, or the default return value if no value was present for the given key.
- See Also:
Function.put(Object,Object)
-
remove
public V remove(char key)
Description copied from interface:Char2ObjectFunction
Removes the mapping with the given key.- Specified by:
remove
in interfaceChar2ObjectFunction<V>
- Returns:
- the old value, or the default return value if no value was present for the given key.
- See Also:
Function.remove(Object)
-
clear
public void clear()
Description copied from interface:Function
Removes all associations from this function (optional operation).- Specified by:
clear
in interfaceFunction<Character,V>
- See Also:
Map.clear()
-
containsKey
public boolean containsKey(Object ok)
Description copied from interface:Function
Returns true if this function contains a mapping for the specified key.Note that for some kind of functions (e.g., hashes) this method will always return true.
- Specified by:
containsKey
in interfaceFunction<Character,V>
- Parameters:
ok
- the key.- Returns:
- true if this function associates a value to
key
. - See Also:
Map.containsKey(Object)
-
get
public V get(Object ok)
Delegates to the corresponding type-specific method, taking care of returningnull
on a missing key.This method must check whether the provided key is in the map using
containsKey()
. Thus, it probes the map twice. Implementors of subclasses should override it with a more efficient method.- Specified by:
get
in interfaceFunction<Character,V>
- Parameters:
ok
- the key.- Returns:
- the corresponding value, or
null
if no value was present for the given key. - See Also:
Map.get(Object)
-
put
public V put(Character ok, V ov)
Delegates to the corresponding type-specific method, taking care of returningnull
on a missing key.This method must check whether the provided key is in the map using
containsKey()
. Thus, it probes the map twice. Implementors of subclasses should override it with a more efficient method.- Specified by:
put
in interfaceFunction<Character,V>
- Parameters:
ok
- the key.ov
- the value.- Returns:
- the old value, or
null
if no value was present for the given key. - See Also:
Map.put(Object,Object)
-
remove
public V remove(Object ok)
Delegates to the corresponding type-specific method, taking care of returningnull
on a missing key.This method must check whether the provided key is in the map using
containsKey()
. Thus, it probes the map twice. Implementors of subclasses should override it with a more efficient method.- Specified by:
remove
in interfaceFunction<Character,V>
- Returns:
- the old value, or
null
if no value was present for the given key. - See Also:
Map.remove(Object)
-
-