public abstract class GameObjectContainer<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>
extends java.lang.Object
implements java.lang.Cloneable, java.lang.Iterable<G>, java.io.Serializable
GameObject
extends this class for containing other GameObjects,
like inventory contents e.g. of a bag or attached events.
MapSquare
extends this class to list the squares on a MapSquare.
Modifier | Constructor and Description |
---|---|
protected |
GameObjectContainer()
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
void |
addFirst(G gameObject)
Adds the given game object at the end of this container.
|
void |
addLast(G gameObject)
Adds the given game object at the end of this container.
|
abstract G |
asGameObject()
Returns this instance as a
GameObject or null if this
instance is not a game object. |
protected @NotNull java.lang.Object |
clone() |
G |
getFirst()
Returns the first GameObject contained in this container.
|
G |
getLast()
Returns the last GameObject contained in this container.
|
abstract @NotNull MapSquare<G,A,R> |
getMapSquare()
Returns the
MapSquare this game object is part of. |
abstract @Nullable MapSquare<G,A,R> |
getMapSquareOptional()
Returns the
MapSquare this game object is part of. |
G |
getNext(G gameObject)
Returns the
GameObject succeeding a given game object. |
G |
getPrev(G gameObject)
Returns the
GameObject preceding a given game object. |
protected boolean |
hasSameContents(@NotNull GameObjectContainer<?,?,?> gameObjectContainer)
Compares this object to another game object container.
|
void |
insertAfter(G previousGameObject,
G gameObject)
Adds a game object after another.
|
void |
insertBefore(G gameObject,
G nextGameObject)
Adds a game object before another.
|
boolean |
isBottom(G gameObject)
Returns whether this game object is the bottom-most one.
|
boolean |
isEmpty()
Check whether this square is empty.
|
boolean |
isTop(G gameObject)
Returns whether this game object is the top-most one.
|
@NotNull java.util.Iterator<G> |
iterator()
The Iterator returned does not recurse, it only contains
objects on the first level.
|
void |
moveBottom(G gameObject)
Moves a game object to bottom.
|
void |
moveDown(G gameObject)
Moves a game object down.
|
void |
moveTop(G gameObject)
Moves a game object to top.
|
void |
moveUp(G gameObject)
Moves a game object up.
|
protected abstract void |
notifyBeginChange()
Notifies the map model that this container is about to change.
|
protected abstract void |
notifyEndChange()
Notifies the map model that this container has changed.
|
@NotNull java.lang.Iterable<G> |
recursive()
Returns an object that is a recursive representation.
|
void |
remove(G gameObject)
Removes a game object from this container.
|
void |
removeAll()
Removes all game objects from this container.
|
void |
replace(G oldGameObject,
G newGameObject)
Replaces a game object with another one.
|
@NotNull java.lang.Iterable<G> |
reverse()
Returns an object that is the reverse representation.
|
protected abstract void |
setThisContainer(G gameObject)
Sets a
GameObject 's container to this container. |
@NotNull java.lang.String |
toString() |
@NotNull public @NotNull java.util.Iterator<G> iterator()
iterator
in interface java.lang.Iterable<G extends GameObject<G,A,R>>
@NotNull public @NotNull java.lang.Iterable<G> reverse()
@NotNull public @NotNull java.lang.Iterable<G> recursive()
public boolean isEmpty()
true
if this square is empty, otherwise false
@Nullable public G getFirst()
null
if isEmpty()
returns true
@Nullable public G getPrev(@NotNull G gameObject)
GameObject
preceding a given game object.gameObject
- the given game objectnull
if no preceding game
object exists.@Nullable public G getNext(@NotNull G gameObject)
GameObject
succeeding a given game object.gameObject
- the given game objectnull
if no successor game
object exists.@Nullable public G getLast()
null
if isEmpty()
returns true
public void remove(@NotNull G gameObject)
gameObject
- GameObject to removejava.lang.IllegalArgumentException
- if gameObject
isn't in this
containerpublic void removeAll()
public boolean isTop(@NotNull G gameObject)
gameObject
- item to move to topjava.lang.IllegalArgumentException
- if gameObject
isn't in this
containerpublic boolean isBottom(@NotNull G gameObject)
gameObject
- item to move to topjava.lang.IllegalArgumentException
- if gameObject
isn't in this
containerpublic void moveTop(@NotNull G gameObject)
gameObject
- item to move to topjava.lang.IllegalArgumentException
- if gameObject
isn't in this
containerpublic void moveUp(@NotNull G gameObject)
gameObject
- item to move upjava.lang.IllegalArgumentException
- if gameObject
isn't in this
containerpublic void moveDown(@NotNull G gameObject)
gameObject
- item to move downjava.lang.IllegalArgumentException
- if gameObject
isn't in this
containerpublic void moveBottom(@NotNull G gameObject)
gameObject
- item to move to bottomjava.lang.IllegalArgumentException
- if gameObject
isn't in this
containerpublic void addLast(@NotNull G gameObject)
gameObject
- the free yet unlinked GameObject
to be placed
in the inventoryjava.lang.IllegalArgumentException
- if gameObject
already is inside
another containerpublic void addFirst(@NotNull G gameObject)
gameObject
- the free yet unlinked GameObject
to be placed
in the inventoryjava.lang.IllegalArgumentException
- if gameObject
already is inside
another containerpublic void insertAfter(@Nullable G previousGameObject, @NotNull G gameObject)
previousGameObject
- previous anchor or null
to insert lastgameObject
- GameObject to insertjava.lang.IllegalArgumentException
- if gameObject
already is inside
another container or previousGameObject
isn't inside this
containerpublic void insertBefore(@NotNull G gameObject, @Nullable G nextGameObject)
gameObject
- GameObject to insertnextGameObject
- nextGameObject anchor or null
to add firstjava.lang.IllegalArgumentException
- if gameObject
already is inside
another container or prev
isn't inside this containerpublic void replace(@NotNull G oldGameObject, @NotNull G newGameObject)
oldGameObject
- old GameObject to be replacednewGameObject
- new GameObject that replaces oldGameObjectjava.lang.IllegalArgumentException
- if oldGameObject
isn't in this
container or is a multi-part object@NotNull public abstract @NotNull MapSquare<G,A,R> getMapSquare()
MapSquare
this game object is part of.java.lang.IllegalStateException
- if the game object is not part of a map@Nullable public abstract @Nullable MapSquare<G,A,R> getMapSquareOptional()
MapSquare
this game object is part of.null
if the game object is not part of
a mapprotected abstract void notifyBeginChange()
protected abstract void notifyEndChange()
@NotNull protected @NotNull java.lang.Object clone()
clone
in class java.lang.Object
protected boolean hasSameContents(@NotNull @NotNull GameObjectContainer<?,?,?> gameObjectContainer)
gameObjectContainer
- the other game object containertrue
if this object equals the other objectprotected abstract void setThisContainer(@NotNull G gameObject)
GameObject
's container to this container.gameObject
- the game object@Nullable public abstract G asGameObject()
GameObject
or null
if this
instance is not a game object.null
@NotNull public @NotNull java.lang.String toString()
toString
in class java.lang.Object