public class

DefaultIdStoringStrategy

extends IdStoringStrategy
java.lang.Object
   ↳ org.apache.commons.betwixt.strategy.IdStoringStrategy
     ↳ org.apache.commons.betwixt.strategy.DefaultIdStoringStrategy

Class Overview

Stores every ID that given to it into an internal HashMap and returns it on request.

DefaultIdStoringStrategy(Map, Map) allows the implementations to be specified. For example, those who want to use identity (rather than equality) should pass a IdentityHashMap instance.

Summary

[Expand]
Inherited Fields
From class org.apache.commons.betwixt.strategy.IdStoringStrategy
Public Constructors
DefaultIdStoringStrategy()
Constructs a IdStoringStrategy using a HashMap for storage.
DefaultIdStoringStrategy(Map idByBeanMap, Map beanByIdMap)
Constructs a IdStoringStrategyusing the Map implementations provided for storage.
Public Methods
String getReferenceFor(Context context, Object bean)
Returns a String id for the given bean if it has been stored previously.
Object getReferenced(Context context, String id)
Gets an object matching the given reference.
void reset()
Clears all beans.
void setReference(Context context, Object bean, String id)
Stores an ID for the given instance and context.
[Expand]
Inherited Methods
From class org.apache.commons.betwixt.strategy.IdStoringStrategy
From class java.lang.Object

Public Constructors

public DefaultIdStoringStrategy ()

Constructs a IdStoringStrategy using a HashMap for storage.

public DefaultIdStoringStrategy (Map idByBeanMap, Map beanByIdMap)

Constructs a IdStoringStrategyusing the Map implementations provided for storage.

Parameters
idByBeanMap Map implementation stores the ID's by bean
beanByIdMap Map implementation stores the bean's by ID

Public Methods

public String getReferenceFor (Context context, Object bean)

Returns a String id for the given bean if it has been stored previously. Otherwise returns null.

Parameters
context current context, not null
bean the instance, not null
Returns
  • id as String, or null if not found

public Object getReferenced (Context context, String id)

Gets an object matching the given reference.

Parameters
context Context, not null
id the reference id
Returns
  • an bean matching the given reference, or null if there is no bean matching the given reference

public void reset ()

Clears all beans.

public void setReference (Context context, Object bean, String id)

Stores an ID for the given instance and context. It will check first if this ID has been previously stored and will do nothing in that case.

Parameters
context current context, not null
bean current instance, not null
id the ID to store