D
- the kind of object that should be treated as Dockable
S
- the kind of object that should be treated as DockStation
P
- the type of item which represents a Dockable
public abstract class PlaceholderList<D,S,P extends PlaceholderListItem<D>> extends Object
Dockable
s and sets of Path
s as placeholder.
Uses a PlaceholderStrategy
to automatically create and dispose
of placeholders.bind()
and unbind()
to manage the
lifecycle of this list.PlaceholderList
is not thread-safe.Modifier and Type | Class and Description |
---|---|
static interface |
PlaceholderList.Filter<M>
A sublist of a
PlaceholderList , the elements in this
list are filtered by a strategy that is defined by the
PlaceholderList . |
class |
PlaceholderList.Item
A single item in a
PlaceholderList |
static class |
PlaceholderList.Level
identifiers for the various sublists this list consists of
|
Modifier and Type | Field and Description |
---|---|
static Path |
PLACEHOLDER_MAP_FORMAT
The
format of the PlaceholderMap s that are created by this class. |
Constructor and Description |
---|
PlaceholderList()
Creates a new and empty list.
|
PlaceholderList(PlaceholderMap map,
PlaceholderListItemConverter<D,P> converter)
Creates a new list reading all the data that is stored in
map . |
Modifier and Type | Method and Description |
---|---|
void |
addPlaceholder(D dockable,
Path placeholder)
Adds
placeholder at the location of dockable . |
int |
baseToLevel(int index,
PlaceholderList.Level level)
Searches the base entry at
index and returns
its location in sublist level . |
void |
bind()
Connects this list with its strategy.
|
void |
clear()
Clears this list, all entries are removed
|
PlaceholderList.Filter<P> |
dockables()
Gets a mutable view of all
Dockable s of this list. |
protected abstract D[] |
getChildren(S station)
Gets all the children of
station . |
P |
getDockableAt(Path placeholder)
Searches the first occurrence of
placeholder and returns the Dockable
that is stored at that location. |
int |
getDockableIndex(Path placeholder)
Emulates the insertion of a
Dockable at location placeholder and
returns the index that the inserted dockable would have in the dockable-list. |
PlaceholderList.Item |
getItem(D dockable)
|
PlaceholderList.Item |
getItem(Path placeholder)
|
int |
getListIndex(int index,
Path placeholder)
Searches for an index in
list() described by
placeholder or index .This method calls insertAllPlaceholders() if placeholder cannot
be found. |
int |
getListIndex(Path placeholder)
Searches the first occurance of
placeholder in a placeholder-set and returns
the index of that entry on the BASE level . |
PlaceholderMap |
getMap(Path placeholder)
Gets the
PlaceholderMap that was used for a station at location placeholder . |
PlaceholderMetaMap |
getMetaMap(Path placeholder)
Gets the meta-map that is associated with the set of placeholders that include
placeholder . |
int |
getNextListIndex(int index,
Path placeholder)
Searches for an index in
list() that follows the item described by
placeholder or index .This method calls insertAllPlaceholders() if placeholder cannot
be found. |
protected abstract Path |
getPlaceholder(D dockable)
Gets the placeholder which matches
dockable . |
protected abstract PlaceholderMap |
getPlaceholders(S station)
Gets all the placeholders that are used by
station . |
PlaceholderStrategy |
getStrategy()
Gets the current strategy of this list.
|
boolean |
hasPlaceholder(Path placeholder)
Tells whether this list contains a reference to
placeholder . |
void |
insertAllPlaceholders()
Inserts a placeholder for all
Dockable s that are stored in this list. |
int |
levelToBase(int index,
PlaceholderList.Level level)
Searches the base entry at
index in the sublist level and returns
its location in the base list. |
PlaceholderList.Filter<PlaceholderList.Item> |
list()
Gets a mutable view of all elements of this list.
|
PlaceholderList.Filter<Set<Path>> |
listPlaceholders()
Gets a mutable view of all elements of this list.
|
PlaceholderList.Filter<Set<Path>> |
purePlaceholders()
Gets a mutable view of all pure placeholders of this list.
|
int |
put(Path placeholder,
P dockable)
Searches for the first occurrence of
placeholder and replaces
it with dockable . |
boolean |
put(P dockable,
Path placeholder)
Searches for the entry containing
dockable and adds placeholder to the
placeholder set. |
void |
read(PlaceholderMap map,
PlaceholderListItemConverter<D,P> converter)
Reads the contents of
map and adds them at the end of this list. |
protected void |
read(PlaceholderMap map,
PlaceholderListItemConverter<D,P> converter,
boolean simulate)
Reads the contenst of
map . |
Path |
remove(int index)
|
Path |
remove(P dockable)
Searches for
dockable and replaces it by a placeholder. |
void |
removeAll(Path placeholder)
Checks all entries of this list and removes all occurrences of all
placeholder . |
void |
removeAll(Set<Path> placeholders)
Checks all entries of this list and removes all occurrences of all
paths stored in
placeholders . |
protected abstract void |
setPlaceholders(S station,
PlaceholderMap map)
Sets all the placeholders that should be used by
station . |
void |
setStrategy(PlaceholderStrategy strategy)
Sets the new strategy of this list.
|
int |
size(PlaceholderList.Level level)
Gets the number of entries in the level
level . |
PlaceholderMap |
toMap(PlaceholderListItemConverter<?,? super P> converter)
Converts this list into a
PlaceholderMap , any remaining Dockable or
DockStation will be converted using converter . |
protected abstract S |
toStation(D dockable)
Converts
dockable to the representation of a DockStation . |
String |
toString() |
protected abstract String |
toString(D dockable)
Gets a representation of
dockable as string. |
void |
unbind()
Disconnects this list from its strategy.
|
public static final Path PLACEHOLDER_MAP_FORMAT
format
of the PlaceholderMap
s that are created by this class.public PlaceholderList()
public PlaceholderList(PlaceholderMap map, PlaceholderListItemConverter<D,P> converter)
map
. This
constructor stores all placeholders that are described in map
, obsolete
placeholders may be deleted as soon as a PlaceholderStrategy
is set.map
- the map to read, not null
converter
- used to convert items back to dockables, not null
IllegalArgumentException
- if map
was not written by a PlaceholderList
protected abstract Path getPlaceholder(D dockable)
dockable
.dockable
- some random dockabledockable
, can be null
protected abstract String toString(D dockable)
dockable
as string.dockable
- some random dockable, not null
protected abstract S toStation(D dockable)
dockable
to the representation of a DockStation
.dockable
- some random dockabledockable
as station, can be null
protected abstract PlaceholderMap getPlaceholders(S station)
station
.station
- some random representation of a DockStation
null
protected abstract void setPlaceholders(S station, PlaceholderMap map)
station
.station
- a representation of a DockStation
map
- the map of placeholders, not null
protected abstract D[] getChildren(S station)
station
.station
- some station whose children are searchedpublic void read(PlaceholderMap map, PlaceholderListItemConverter<D,P> converter)
map
and adds them at the end of this list.map
- the map to readconverter
- used to convert items back to dockables, not null
IllegalArgumentException
- if the map is in the wrong formatprotected void read(PlaceholderMap map, PlaceholderListItemConverter<D,P> converter, boolean simulate)
map
. This method can either add the contents at
the end of this list, or just simulate a read. If a read is simulated, then the methods
of converter
are called just as if this would be an actual read, but
in reality no data is changed in this list.map
- the data to readconverter
- used to convert items back to dockables, not null
simulate
- whether this list should actually be changed or notIllegalArgumentException
- if the map is in the wrong formatpublic PlaceholderMap toMap(PlaceholderListItemConverter<?,? super P> converter)
PlaceholderMap
, any remaining Dockable
or
DockStation
will be converted using converter
.converter
- converter to translate dockables into persistent data, not null
null
public void bind()
public void unbind()
public PlaceholderStrategy getStrategy()
public void setStrategy(PlaceholderStrategy strategy)
null
,
then all current placeholders are checked and the invalid placeholders
are removed.strategy
- the new strategypublic void insertAllPlaceholders()
Dockable
s that are stored in this list.public PlaceholderList.Filter<P> dockables()
Dockable
s of this list.public PlaceholderList.Filter<Set<Path>> purePlaceholders()
null
.public PlaceholderList.Filter<PlaceholderList.Item> list()
public PlaceholderList.Filter<Set<Path>> listPlaceholders()
public void removeAll(Set<Path> placeholders)
placeholders
. If an entry remains with
0 placeholders and no Dockable
it is removed.placeholders
- the placeholders to removepublic void removeAll(Path placeholder)
placeholder
. If an entry remains with 0 placeholders
and no Dockable
it is removed.placeholder
- the placeholder to removepublic Path remove(int index)
index
- the index of the element to removenull
public Path remove(P dockable)
dockable
and replaces it by a placeholder. If dockable
is a DockStation
, then its PlaceholderMap
is stored.dockable
- the element to removenull
if the current strategy does
not assign a placeholder to dockable
or if dockable
was not found in this listpublic int put(Path placeholder, P dockable)
placeholder
and replaces
it with dockable
. If there is already another dockable stored at that
location, then the other dockable is replaced silently. If dockable
is a
DockStation
and a PlaceholderMap
is set, then this map is transfered to
dockable
and removed from this list, but only if the DockStation
does not
already have children.placeholder
and the placeholder that is assigned
by the current PlaceholderStrategy
from this list.placeholder
- the placeholder to search, not null
dockable
- the element which will replace placeholder
, not null
dockables()
where dockable
was inserted or -1 if
placeholder
was not foundpublic int getDockableIndex(Path placeholder)
Dockable
at location placeholder
and
returns the index that the inserted dockable would have in the dockable-list.placeholder
- the placeholder of the element to insertplaceholder
was not foundpublic int getListIndex(Path placeholder)
placeholder
in a placeholder-set and returns
the index of that entry on the BASE level
.placeholder
- the placeholder to searchpublic int getListIndex(int index, Path placeholder)
list()
described by
placeholder
or index
.insertAllPlaceholders()
if placeholder
cannot
be found.index
- the backup index, used if placeholder
cannot be foundplaceholder
- a placeholder to search, can be null
placeholder
or index
public int getNextListIndex(int index, Path placeholder)
list()
that follows the item described by
placeholder
or index
.insertAllPlaceholders()
if placeholder
cannot
be found.index
- the backup index, used if placeholder
cannot be foundplaceholder
- a placeholder to search, can be null
placeholder
or index
public boolean hasPlaceholder(Path placeholder)
placeholder
.placeholder
- the placeholder to searchpublic boolean put(P dockable, Path placeholder)
dockable
and adds placeholder
to the
placeholder set. This method removes placeholder
from all the other entries.dockable
- the keyplaceholder
- the placeholder to inserttrue
if dockable
was found, false
otherwisepublic P getDockableAt(Path placeholder)
placeholder
and returns the Dockable
that is stored at that location.placeholder
- the placeholder to searchnull
if there is no dockable stored or
placeholder
is not foundpublic PlaceholderMetaMap getMetaMap(Path placeholder)
placeholder
.placeholder
- some placeholder to searchplaceholder
, can be null
public PlaceholderMap getMap(Path placeholder)
PlaceholderMap
that was used for a station at location placeholder
.placeholder
- some placeholder to searchPlaceholderMap
that was stored at the place where placeholder
was found,
can be null
public PlaceholderList.Item getItem(Path placeholder)
placeholder
- the placeholder used for searchingplaceholder
or null
public PlaceholderList.Item getItem(D dockable)
dockable
- the dockable used for searchingdockable
or null
public void addPlaceholder(D dockable, Path placeholder)
placeholder
at the location of dockable
. This method will remove placeholder
from all
other locations.dockable
- some dockable that is known to this listplaceholder
- a placeholder that should be added to the PlaceholderList.Item
that represents dockable
IllegalArgumentException
- if either argument is null
, or if the location of dockable
cannot be foundpublic int size(PlaceholderList.Level level)
level
.level
- some level to countpublic int baseToLevel(int index, PlaceholderList.Level level)
index
and returns
its location in sublist level
.index
- the index of some entrylevel
- the sublistlevel
IndexOutOfBoundsException
- if index
is illegalpublic int levelToBase(int index, PlaceholderList.Level level)
index
in the sublist level
and returns
its location in the base list.index
- the index of some entrylevel
- the sublistIndexOutOfBoundsException
- if index
is illegalpublic void clear()