public abstract class AbstractLegacyAdapter<L,M> extends Object implements LegacyAdapter<L,M>
LegacyAdapter
implementations.
Uses a WeakHashMap
implementation for maintaining associations between
legacy and modern classes. "True" instances of each class map to wrappers of their
companion classes.
NB: because wrappers are the values in the map, they must be expected to delegate to their key
objects (wrapper values wrap their keys).
WeakHashMaps are used to ensure garbage collection when
there are no other references to the Legacy/modern pairings.
However, since the values in each
pairing wraps the key, there is always a strong reference to each key. Thus we map each key
to a WeakReference
of the wrapper.
Constructor and Description |
---|
AbstractLegacyAdapter() |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Resets any mappings in this adapter.
|
L |
getLegacy(M modern)
Used to retrieve the legacy instance associated with a given
modern instance.
|
M |
getModern(L legacy)
Used to retrieve the modern instance associated with a given
legacy instance.
|
protected abstract L |
wrapToLegacy(M modern)
Used Wraps the given modern object to a new instance of its legacy equivalent.
|
protected abstract M |
wrapToModern(L legacy)
Wraps the given legacy object to a new instance of its modern equivalent.
|
public M getModern(L legacy)
LegacyAdapter
This is the method that should typically be invoked to convert from
Legacy to Modern instances, as opposed to LegacyAdapter#wrapToModern(L)
which will
naively always wrap.
getModern
in interface LegacyAdapter<L,M>
legacy
- - An instance of the legacy class.public L getLegacy(M modern)
LegacyAdapter
This is the method that should typically be invoked to convert from
Modern to Legacy instances, as opposed to LegacyAdapter#wrapToLegacy(M)
which will
naively always wrap.
getLegacy
in interface LegacyAdapter<L,M>
modern
- - An instance of the modern class.public void clear()
LegacyAdapter
clear
in interface LegacyAdapter<L,M>
protected abstract L wrapToLegacy(M modern)
This is a "stupid" operation that always wraps to a new instance.
This method must be defined at the concrete implementation level as it requires knowledge of a specific class that extends L but is capable of wrapping M. Doing so reduces code/logic repetition by maintaining a single getLegacy implementation.
modern
- - An instance of the modern class.protected abstract M wrapToModern(L legacy)
This is a "stupid" operation that always wraps to a new instance.
This method must be defined at the concrete implementation level as it requires knowledge of a specific class that extends M but is capable of wrapping L. Doing so reduces code/logic repetition by maintaining a single getModern implementation.
legacy
- - An instance of the legacy class.Copyright © 2014 Open Microscopy Environment