Package name.moore.kevin.ze.game
Class warehouse
java.lang.Object
name.moore.kevin.ze.game.warehouse
Any planet with manufacturing facilities will deliver manufactured equipment
into a planet-wide/orbit-wide warehouse.
Items can be added to the warehouse to increase stock, they can be reserved for use (and effectively reducing stock) or finally checkedout for usage.
The expected pattern is :
- add parts to the warehouse
.put(S,A); - check if in stock
if( .isInStock(S) ) - reserve it
.reserve(S); - use it
.checkout(S);
- Author:
- Kevin Moore
<dev@kevin.moore.name>
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate com.google.common.collect.ListMultimap<com.simsilica.es.EntityId,com.simsilica.es.EntityId>Map of spec entityid ->List[manufactured parts having this spec].private static org.slf4j.Loggerprivate com.google.common.collect.ListMultimap<com.simsilica.es.EntityId,com.simsilica.es.EntityId>Parts in this list are reserved for specific build tickets. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionMap<com.simsilica.es.EntityId,com.simsilica.es.EntityId>checkout(com.simsilica.es.EntityId spec)Checkout an item in the order (of specs) from the warehouse so we can use them for eg installation where they become assigned to a build ticket.booleanisInStock(com.simsilica.es.EntityId spec)Warehouse contains at least one built item of the required specification available and in stock.booleanisReserved(com.simsilica.es.EntityId spec)Do we have a part of the spec under reservation? This doesn't differentiate if a particular ticket has the reservation, just that someone has.voidput(com.simsilica.es.EntityId spec, com.simsilica.es.EntityId item)It is an assumption that only valid items are are stored in the warehouse, so no planets or stars!com.simsilica.es.EntityIdreserve(com.simsilica.es.EntityId spec)If we have an item in stock, reserve it and reduce stock levels.toString()This will be a dump of the map {a=b,c=d}
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
instock
private com.google.common.collect.ListMultimap<com.simsilica.es.EntityId,com.simsilica.es.EntityId> instockMap of spec entityid ->List[manufactured parts having this spec]. parts in this list are on the shelf and ready to be used. -
reserved
private com.google.common.collect.ListMultimap<com.simsilica.es.EntityId,com.simsilica.es.EntityId> reservedParts in this list are reserved for specific build tickets. Multiple parts having the same spec may be reserved. Spec ->List[parts]
-
-
Constructor Details
-
warehouse
public warehouse()
-
-
Method Details
-
put
public void put(com.simsilica.es.EntityId spec, com.simsilica.es.EntityId item)It is an assumption that only valid items are are stored in the warehouse, so no planets or stars!Increases the stock level
- Parameters:
spec-item-
-
getStockLevels
- Returns:
-
getReservedLevels
- Returns:
-
isInStock
public boolean isInStock(com.simsilica.es.EntityId spec)Warehouse contains at least one built item of the required specification available and in stock.- Returns:
- true if there is at least one item of the required spec available ie not yet reserved.
-
isReserved
public boolean isReserved(com.simsilica.es.EntityId spec)Do we have a part of the spec under reservation? This doesn't differentiate if a particular ticket has the reservation, just that someone has.- Parameters:
spec-- Returns:
-
reserve
public com.simsilica.es.EntityId reserve(com.simsilica.es.EntityId spec)If we have an item in stock, reserve it and reduce stock levels.- Parameters:
spec-- Returns:
- reserved part
-
checkout
public Map<com.simsilica.es.EntityId,com.simsilica.es.EntityId> checkout(com.simsilica.es.EntityId spec)Checkout an item in the order (of specs) from the warehouse so we can use them for eg installation where they become assigned to a build ticket.It is assumed the requested items are available, so check before asking. If they are not, the return is an empty Map. Items are removed from the warehouse and stock levels reduced.
- Parameters:
spec- part with this spec is requested- Returns:
- spec ->part
-
toString
This will be a dump of the map {a=b,c=d}
-