Package marauroa.common.game
Class RPSlot
java.lang.Object
marauroa.common.game.RPSlot
- All Implemented Interfaces:
Cloneable
,Iterable<RPObject>
,Serializable
- Direct Known Subclasses:
EntitySlot
This class represent a slot in an object
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
Add an object to the slot.protected int
adds an object to a slot preserving its it.int
addPreservingId(RPObject object)
adds an object to a slot preserving its it.void
clear()
This method empty the slot by removing all the objects inside.void
clearVisible(boolean sync)
Removes the visible objects from this slot.clone()
This method create a copy of the slotboolean
Returns true if both objects are equalget(RPObject.ID id)
Gets the object from the slotint
Returns the maximum amount of objects that can be stored at the slot.getFirst()
Gets the first object from the slot.getName()
Get the name of the slotprotected SlotOwner
getOwner()
This method returns the owner of the objectboolean
has(RPObject.ID id)
This method returns true if the slot has the object whose id is idboolean
hasAsAncestor(RPObject object)
Traverses up the container tree to see if the slot is owned by object or by one of its parentsboolean
hasAsAncestor(SlotOwner object)
Traverses up the container tree to see if the slot is owned by object or by one of its parentsint
hashCode()
boolean
isEmpty()
Is this slot empty?boolean
isFull()
Returns true if the slot is full.iterator()
Iterate over the objects of the slot.void
Fills this object with the data that has been serialized.remove(RPObject.ID id)
This method removes the object from the slot.void
Clear stored delta^2 information.boolean
setAddedRPObject(RPSlot slot)
Copy to given slot the objects added.void
setCapacity(int capacity)
Set the capacity of the slot.boolean
setDeletedRPObject(RPSlot slot)
Copy to given slot the objects deleted.void
Sets the name of the slotint
size()
Return the number of elements in the slottoString()
void
writeObject(OutputSerializer out)
This method serialize the object with the default level of detail, that removes private and hidden attributesvoid
writeObject(OutputSerializer out, DetailLevel level)
This method serialize the object with the given level of detail.void
writeToJson(StringBuilder out, DetailLevel level)
This method serialize the object with the given level of detail.Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
RPSlot
public RPSlot()Constructor for deserialization. Please useRPSlot(String)
. -
RPSlot
Constructor- Parameters:
name
- name of the slot
-
-
Method Details
-
getOwner
This method returns the owner of the object- Returns:
- the owner of the slot
-
setName
Sets the name of the slot- Parameters:
name
- the name of the slot.
-
getName
Get the name of the slot- Returns:
- the name of the object.
-
add
Add an object to the slot. It calls assignSlotID for the object to assign it a valid unique id for the object inside the container.- Parameters:
object
- the object to add to this slot.- Returns:
- the id assigned to the object
- Throws:
SlotIsFullException
- if there is no more room at the slot.NullPointerException
- if Owner is null
-
addPreservingId
adds an object to a slot preserving its it. Note: In most cases you want to assign a new id.- Parameters:
object
- RPObject to add- Returns:
- the id of the object
-
add
adds an object to a slot preserving its it. Note: In most cases you want to assign a new id.- Parameters:
object
- RPObject to addassignId
- true to assign a new, conflict free ID.- Returns:
- the id of the object
-
get
Gets the object from the slot- Parameters:
id
- the object id. Note that only object_id field is relevant.- Returns:
- the object or null if it is not found.
-
getFirst
Gets the first object from the slot.- Returns:
- the first object of the slot or null if it is empty.
-
remove
This method removes the object from the slot. When an object is removed from the slot, its contained information is set to null.- Parameters:
id
- the object id. Note that only object_id field is relevant.- Returns:
- the object or null if it is not found.
-
clear
public void clear()This method empty the slot by removing all the objects inside. -
has
This method returns true if the slot has the object whose id is id- Parameters:
id
- the object id. Note that only object_id field is relevant.- Returns:
- true if it is found or false otherwise.
-
hasAsAncestor
Traverses up the container tree to see if the slot is owned by object or by one of its parents- Parameters:
object
- the object id. Note that only object_id field is relevant.- Returns:
- true if this slot is owned (at any depth) by id or false otherwise.
-
hasAsAncestor
Traverses up the container tree to see if the slot is owned by object or by one of its parents- Parameters:
object
- the object id. Note that only object_id field is relevant.- Returns:
- true if this slot is owned (at any depth) by id or false otherwise.
-
size
public int size()Return the number of elements in the slot- Returns:
- the number of elements in the slot
-
getCapacity
public int getCapacity()Returns the maximum amount of objects that can be stored at the slot. When there is no limit we use the -1 value.- Returns:
- the maximum amount of objects that can be stored at the slot.
-
setCapacity
public void setCapacity(int capacity)Set the capacity of the slot. By default the value from the RPClass definition is used. It is the responsibility of the caller to ensure sane behavior if the capacity of a non-empty slot is modified. Also, since the slot size is not serialized, the client will always use the value from the RPClass. Therefore, do not use this method to increase the capacity, because the client will not be able cope with slots that have more objects than the capacity defined in the RPClass.- Parameters:
capacity
- new capacity
-
isFull
public boolean isFull()Returns true if the slot is full.- Returns:
- true if the slot is full.
-
isEmpty
public boolean isEmpty()Is this slot empty?- Returns:
- true if there are no objects in this slot
-
iterator
Iterate over the objects of the slot. We disallow removing objects from the iterator to avoid breaking delta^2 algorithm -
equals
Returns true if both objects are equal -
hashCode
public int hashCode() -
toString
-
writeObject
This method serialize the object with the default level of detail, that removes private and hidden attributes- Specified by:
writeObject
in interfaceSerializable
- Parameters:
out
- the output serializer- Throws:
IOException
- in case of an IO-error
-
writeObject
This method serialize the object with the given level of detail.- Parameters:
out
- the output serializerlevel
- the level of Detail- Throws:
IOException
- in case of an IO error
-
writeToJson
This method serialize the object with the given level of detail.- Parameters:
out
- the output bufferlevel
- the level of Detail
-
readObject
Fills this object with the data that has been serialized.- Specified by:
readObject
in interfaceSerializable
- Parameters:
in
- InputSerializer to read from- Throws:
IOException
- in case of an IO-error
-
clone
This method create a copy of the slot -
resetAddedAndDeletedRPObjects
public void resetAddedAndDeletedRPObjects()Clear stored delta^2 information. -
setAddedRPObject
Copy to given slot the objects added. It does a depth copy of the objects.- Parameters:
slot
- the slot to copy added objects.- Returns:
- true if there is any object added.
-
setDeletedRPObject
Copy to given slot the objects deleted. It does a depth copy of the objects.- Parameters:
slot
- the slot to copy added objects.- Returns:
- true if there is any object added.
-
clearVisible
public void clearVisible(boolean sync)Removes the visible objects from this slot. It iterates through the slots to remove the attributes too of the contained objects if they are empty.- Parameters:
sync
- keep the structure intact, by not removing empty slots and links.
-