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()
Create a new GameObjectContainer.
|
Modifier and Type | Method and Description |
---|---|
void |
addFirst(G gameObject)
Add the given GameObject at the end of this Container.
|
void |
addLast(G gameObject)
Add the given GameObject 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 java.lang.Object |
clone() |
G |
getFirst()
Return the first GameObject contained in this container.
|
G |
getLast()
Return the last GameObject contained in this container.
|
abstract MapSquare<G,A,R> |
getMapSquare()
Returns the
MapSquare of this container. |
G |
getNext(G gameObject)
Return the
GameObject succeeding a given game object. |
G |
getPrev(G gameObject)
Return the
GameObject preceding a given game object. |
boolean |
hasSameContents(GameObjectContainer<?,?,?> gameObjectContainer)
Compare this object to another game object container.
|
void |
insertAfter(G previousGameObject,
G gameObject)
Add a GameObject after another.
|
void |
insertBefore(G gameObject,
G nextGameObject)
Add a GameObject 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.
|
java.util.Iterator<G> |
iterator()
The Iterator returned does not recurse, it only contains
objects on the first level.
|
void |
moveBottom(G gameObject)
Move an item to bottom.
|
void |
moveDown(G gameObject)
Move an item down.
|
void |
moveTop(G gameObject)
Move an item to top.
|
void |
moveUp(G gameObject)
Move an item up.
|
protected abstract void |
notifyBeginChange()
Notify the map model that this container is about to change.
|
protected abstract void |
notifyEndChange()
Notify the map model that this container has changed.
|
java.lang.Iterable<G> |
recursive()
Return an object that is a recursive representation.
|
void |
remove(G gameObject)
Remove a GameObject from this container.
|
void |
removeAll()
Removes all GameObjects from this container.
|
void |
replace(G oldGameObject,
G newGameObject)
Replace an GameObject with another one.
|
java.lang.Iterable<G> |
reverse()
Return an object that is the reverse representation.
|
protected abstract void |
setThisContainer(G gameObject)
Sets a
GameObject 's container to this container. |
java.lang.String |
toString() |
protected GameObjectContainer()
@NotNull public java.util.Iterator<G> iterator()
iterator
in interface java.lang.Iterable<G extends GameObject<G,A,R>>
@NotNull public java.lang.Iterable<G> reverse()
@NotNull public 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@Nullable public abstract MapSquare<G,A,R> getMapSquare()
MapSquare
of this container.null
if this
GameObjectContainer is not (yet?) connected to a map (a MapSquare
would return itself)protected abstract void notifyBeginChange()
protected abstract void notifyEndChange()
@NotNull protected java.lang.Object clone()
clone
in class java.lang.Object
public boolean hasSameContents(@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 java.lang.String toString()
toString
in class java.lang.Object