1.257. MapContext

Full Name: herschel.ia.pal.MapContext
Type: Java Class - Java Class
Import: from herschel.ia.pal import MapContext
Category

Data access

Description

Groups products (or other Contexts that in turn group products) in a map-like structure.

Products grouped in a MapContext can be subsequently retrieved by key, through the 'refs' method. Note: users may be confused as to why there is a need to have to go though a 'refs' method to add or access products from a MapContext. This is due to a technical limitation in the design which will be addressed in due course.

Examples

Example 1: Adding a product to a MapContext
product = Product()
ref = storage.save(product) # the ref is a ProductRef object
mapcontext = MapContext()
mapcontext.refs.put("john", ref)
Example 2: Getting a product from a MapContext
ref_john = mapcontext.refs.get("john")
product = ref_john.product
Example 3: Saving a MapContext to ProductStorage (same way as any other product)
ref_context = storage.save(mapcontext)

API Summary

Method
Map getRefs

get the 'map' of ProductRefs stored. From this 'map', you can put

API Details

Method

Map getRefs

get the 'map' of ProductRefs stored. From this 'map', you can put

products into the MapContext, or retrieve products by key.

Return
Map

A map of product refs.

Examples
Putting a product into the the MapContext
ref = storage.save(product) # the ref is a ProductRef object
mapcontext.refs.put("john", ref)
Getting the product from the MapContext with key "john"
ref_john = mapcontext.refs.get("john")

See also