Object identifier for IlpObject

Article ID: 2142
Last updated: 28 May, 2018
Article ID: 2142
Last updated: 28 May, 2018
Revision: 3
Views: 711
Posted: 19 Feb, 2010
by Dean J.
Updated: 28 May, 2018
by Gargani A.

Question

How should I implement an object identifier for my IlpObject?

Answer

The identifier is an Object that can be used to identify and retrieve an IlpObject. It must beunique (even across data sources).
The identifier is provided when the IlpObject is created. It can be either a String or another type of Java object.

If the identifier is a String, the code which creates an IlpObject and assigns an identifier to it must ensure that the identifier is unique.

If the identifier is another type of object, it must satisfy the following constraints:

  • The identifier must be convertible to String, through an IlpTypeConverter installed in the IlpContext. The IlpDefaultTypeConverter uses the Object.toString() method to convert objects of unknown types to String. The String that results from this conversion must be unique.

  • It must be possible to create or retrieve the identifier Object, given the corresponding String, by using the IlpTypeConverter installed in the IlpContext. The IlpDefaultTypeConverter uses a constructor with a single String argument to create instances of unknown types.

  • The identifier Object itself must not be an instance of IlpObject

Please note the following recommendations:

  • Ideally the identifier should be implemented as a simple object in order to perform a fast comparison. For the sake of simplicity, it is recommended to use simple objects, such as Number or String, which already satisfy the constraints listed above.

  • If you are using your own Java class as identifier, the "public boolean equals(Object obj)" method of the identifier class should be overridden to perform an efficient comparison of identifier instances. The "public int hashcode()" method should also be overriden and must be consistent with the "public boolean equals(Object obj)" implementation.

  • An identifier generator can be used to generate the object identifiers in a consistent manner. A predefined identifier generator is available in ilog.cpl.util.IlpIDGenerator.

Note that once the proper implementation for the IlpTypeConverter is created (normally you do this by subclassing IlpDefaultTypeConverter), you can register it with the IlpContext implementation as follows:

IlpDefaultContext context = ...;
context.addService(IlpTypeConverter.class, new CustomTypeConverter(context));

This article was:   Helpful | Not helpful
Report an issue
Article ID: 2142
Last updated: 28 May, 2018
Revision: 3
Views: 711
Posted: 19 Feb, 2010 by Dean J.
Updated: 28 May, 2018 by Gargani A.
Also listed in


Others in this category