SAP NetWeaver '04

com.sap.netweaver.bc.rf.util.flyweight
Class FlyWeight

[contained in: com.sap.netweaver.bc.rf.par - bc.rf.util_api.jar]
java.lang.Object
  |
  +--com.sap.netweaver.bc.rf.util.flyweight.FlyWeight
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable
Direct Known Subclasses:
Enum, FlyWeightWithDescription, Name, Permission

public abstract class FlyWeight
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

Abstract class implementing the flyweight pattern. You have to extend this class and make all methods derived from this abstract class final (except for toString())! This is necessary in order to ensure, that no class can be derived from your class overriding and thereby changing the inner mechanism to create an flyweight instance only once, return the same object on clone() etc. It is of greatest importance to ensure that both the id and the flyweight object itself are immutable! Preknown flyweight instances may be added as public final static flyweight members. If you just need to have the predefined flyweight instances, implement an appropriate private constructor, otherwise make it public:


 public class Property extends FlyWeight
 {
     public final static Property RO = new Property( "RO" );
     public final static Property MV = new Property( "MV" );

     private Property ( final Serializable id )
     {
         super( id );
     }
 }
 

See Also:
Serialized Form

Constructor Summary
protected FlyWeight(java.io.Serializable id, boolean ignoreDuplicateRegistration)
          Construct instance of a flyweight.
 
Method Summary
 java.lang.Object clone()
          Clone this flyweight.
 boolean equals(java.lang.Object obj)
          Compare this and another object for equality.
static java.util.List getAllFlyWeights(java.lang.Class flyWeightClass)
          Get all so far registered flyweight instances of the given flyweight class.
static java.util.List getAllFlyWeightsInherited(java.lang.Class flyWeightClass)
          Get all so far registered flyweight instances of the given flyweight class and all sub classes of that class.
static FlyWeight getFlyWeight(java.lang.Class flyWeightClass, java.io.Serializable id)
          Get flyweight instance by id of the given flyweight class.
 java.io.Serializable getFlyWeightId()
          Get id of the flyweight instance.
static FlyWeight getFlyWeightInherited(java.lang.Class flyWeightClass, java.io.Serializable id)
          Get flyweight instance by id of the given flyweight class and all sub classes of that class.
 int hashCode()
          Get hashcode for this flyweight instance.
static java.util.List removeAllFlyWeights(java.lang.Class flyWeightClass)
          Remove all so far registered flyweight instances of the given flyweight class.
static java.util.List removeAllFlyWeightsInherited(java.lang.Class flyWeightClass)
          Remove all so far registered flyweight instances of the given flyweight class and all sub classes of that class.
static FlyWeight removeFlyWeight(java.lang.Class flyWeightClass, java.io.Serializable id)
          Remove flyweight instance by id of the given flyweight class.
static FlyWeight removeFlyWeightInherited(java.lang.Class flyWeightClass, java.io.Serializable id)
          Remove flyweight instance by id of the given flyweight class and all sub classes of that class.
 java.lang.String toString()
          Get descriptive text for this flyweight instance.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FlyWeight

protected FlyWeight(java.io.Serializable id,
                    boolean ignoreDuplicateRegistration)
             throws java.lang.IllegalArgumentException
Construct instance of a flyweight.
Parameters:
id - flyweight id
ignoreDuplicateRegistration - when true, don't throw IllegalArgumentException exception when the id is already in use
Throws:
java.lang.IllegalArgumentException - when the id is already in use
Method Detail

getFlyWeightId

public java.io.Serializable getFlyWeightId()
Get id of the flyweight instance.
Returns:
flyweight id

toString

public java.lang.String toString()
Get descriptive text for this flyweight instance.
Overrides:
toString in class java.lang.Object
Returns:
descriptive text for this flyweight instance

hashCode

public int hashCode()
Get hashcode for this flyweight instance.
Overrides:
hashCode in class java.lang.Object
Returns:
flyweight hashcode

equals

public boolean equals(java.lang.Object obj)
Compare this and another object for equality. Works only fine when handling objects of classes loaded by same class classloader.
Overrides:
equals in class java.lang.Object
Parameters:
obj - object to be compared against
Returns:
result of comparison

clone

public java.lang.Object clone()
Clone this flyweight. The clone method will always return the same instance for faster equality comparison. This is not harmful, since the flyweight is immutable.
Overrides:
clone in class java.lang.Object
Returns:
this flyweight instance

getFlyWeight

public static FlyWeight getFlyWeight(java.lang.Class flyWeightClass,
                                     java.io.Serializable id)
Get flyweight instance by id of the given flyweight class.
Parameters:
id - flyweight id
flyWeightClass - flyweight class
Returns:
flyweight instance

getFlyWeightInherited

public static FlyWeight getFlyWeightInherited(java.lang.Class flyWeightClass,
                                              java.io.Serializable id)
Get flyweight instance by id of the given flyweight class and all sub classes of that class. If, follwoing the inheritance, multiple fyweights have the same id, the first found (behaviour is not deterministic) will be returned.
Parameters:
id - flyweight id
flyWeightClass - flyweight class
Returns:
flyweight instance

removeFlyWeight

public static FlyWeight removeFlyWeight(java.lang.Class flyWeightClass,
                                        java.io.Serializable id)
Remove flyweight instance by id of the given flyweight class.
Parameters:
id - flyweight id
flyWeightClass - flyweight class
Returns:
flyweight instance removed or null

removeFlyWeightInherited

public static FlyWeight removeFlyWeightInherited(java.lang.Class flyWeightClass,
                                                 java.io.Serializable id)
Remove flyweight instance by id of the given flyweight class and all sub classes of that class. If, follwoing the inheritance, multiple fyweights have the same id, the first found (behaviour is not deterministic) will be removed.
Parameters:
id - flyweight id
flyWeightClass - flyweight class
Returns:
flyweight instance removed or null

getAllFlyWeights

public static java.util.List getAllFlyWeights(java.lang.Class flyWeightClass)
Get all so far registered flyweight instances of the given flyweight class. Note that only the so far registered instances can be returned. When for example some instances haven't been registered, because the class wasn't loaded, these instances won't be returned.
Parameters:
flyWeightClass - flyweight class for which all instances should be looked up
Returns:
all so far registered flyweight instances of the given flyweight class

getAllFlyWeightsInherited

public static java.util.List getAllFlyWeightsInherited(java.lang.Class flyWeightClass)
Get all so far registered flyweight instances of the given flyweight class and all sub classes of that class. Note that only the so far registered instances can be returned. When for example some instances haven't been registered, because the class wasn't loaded, these instances won't be returned.
Parameters:
flyWeightClass - flyweight class (all sub classes of that class will also be checked) for which all instances should be looked up
Returns:
all so far registered flyweight instances of the given flyweight class and all sub classes of that class

removeAllFlyWeights

public static java.util.List removeAllFlyWeights(java.lang.Class flyWeightClass)
Remove all so far registered flyweight instances of the given flyweight class. Note that only the so far registered instances can be removed. When for example some instances haven't been registered, because the class wasn't loaded, these instances won't be removed.
Parameters:
flyWeightClass - flyweight class for which all instances should be removed
Returns:
all so far removed flyweight instances of the given flyweight class

removeAllFlyWeightsInherited

public static java.util.List removeAllFlyWeightsInherited(java.lang.Class flyWeightClass)
Remove all so far registered flyweight instances of the given flyweight class and all sub classes of that class. Note that only the so far registered instances can be removed. When for example some instances haven't been registered, because the class wasn't loaded, these instances won't be removed.
Parameters:
flyWeightClass - flyweight class (all sub classes of that class will also be checked) for which all instances should be removed
Returns:
all so far removed flyweight instances of the given flyweight class and all sub classes of that class

SAP NetWeaver '04

Copyright © 2004 by SAP AG. All Rights Reserved.
SAP, R/3, mySAP, mySAP.com, xApps, xApp, SAP NetWeaver, and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and in several other countries all over the world. All other product and service names mentioned are the trademarks of their respective companies. Data contained in this document serves informational purposes only. National product specifications may vary.

These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty.