org.opensubsystems.patterns.ordereddata.util
Class OrderedDataUtils

java.lang.Object
  extended by org.opensubsystems.patterns.ordereddata.util.OrderedDataUtils

public final class OrderedDataUtils
extends java.lang.Object

Utility methods for data object order manipulation.

Version:
$Id: OrderedDataUtils.java,v 1.6 2007/01/07 06:14:32 bastafidli Exp $
Author:
Julian Legeny
Code reviewer:
Miro Halas
Code reviewed:
1.3 2006/04/28 01:48:15 jlegeny

Field Summary
static java.lang.String ORDERED_ITEMS_POSTFIX
          Postfix for name of the hidden variable for particular dataobject.
 
Method Summary
static byte compare(int[] arrIdentifiers, java.util.List lstList)
          Compare array of ids and list of objects to find out if the order of the object as changed or if some objects were newly added or removed.
static byte compare(java.util.List lstList1, java.util.List lstList2)
          Compare lists of objects to find out if their order or attributes were changed or if some objects were added or deleted.
static java.lang.String getEncodedOrder(java.util.Collection colDataObjects)
          Construct string representation of all ordered items contained within the specified collection.
static int getOrder(java.lang.String strOrderedItems, int iItemId)
          Get order number for specified id encoded in the specified string
static java.util.Collection updateOrder(javax.servlet.http.HttpServletRequest hsrqRequest, java.util.Collection colDataObjects, java.lang.String strParamPrefix)
          Parse order numbers and set it up into collection of dataobject.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ORDERED_ITEMS_POSTFIX

public static final java.lang.String ORDERED_ITEMS_POSTFIX
Postfix for name of the hidden variable for particular dataobject. This hidden parameter will store ordered items with belonging order number. Format will be following: ID1:ORDER_NUMBER1;...;IDn:ORDER_NUMBERn

See Also:
Constant Field Values
Method Detail

updateOrder

public static java.util.Collection updateOrder(javax.servlet.http.HttpServletRequest hsrqRequest,
                                               java.util.Collection colDataObjects,
                                               java.lang.String strParamPrefix)
Parse order numbers and set it up into collection of dataobject.

Parameters:
hsrqRequest - - HTTP request containing request parameter defining order of data objects. The value format is documented in ORDERED_ITEMS_POSTFIX.
colDataObjects - - collection of data objects whose order number needs to be updated from the values passed in the request. The collection will be also sorted by the order number
strParamPrefix - - prefix for hidden variable storing changed IDs. The prefix has to be followed by ORDERED_ITEMS_POSTFIX so that the whole request parameter name is prefix + postfix.
Returns:
Collection - the same collection of items that is passed in with each data object updated with order number value from the request and sorted by te order number

getOrder

public static int getOrder(java.lang.String strOrderedItems,
                           int iItemId)
Get order number for specified id encoded in the specified string

Parameters:
strOrderedItems - - string specifying order of data objects identifiable by their ids. Format of the string is ID1:ORDER_NUMBER1;...;IDn:ORDER_NUMBERn
iItemId - - id of item for which we need to get order
Returns:
int - parsed order number for specified ID

getEncodedOrder

public static java.lang.String getEncodedOrder(java.util.Collection colDataObjects)
Construct string representation of all ordered items contained within the specified collection. The format of the order string is: ID1:ORDER_NUMBER1;...;IDn:ORDER_NUMBERn

Parameters:
colDataObjects - - collection of ordered data objects for which the order string will be constructed for
Returns:
String - string representation of all ordered data objects within the collection

compare

public static byte compare(java.util.List lstList1,
                           java.util.List lstList2)
Compare lists of objects to find out if their order or attributes were changed or if some objects were added or deleted. Objects in list have to be instances of DataObject and OrderedData.

Parameters:
lstList1 - - first list to compare
lstList2 - - second list to compare
Returns:
byte - result byte with bit flags of changes: [COMPARE_ORDER_CHANGE]-th bit = if order has been changed [COMPARE_ATTRIBUTES_CHANGE]-th bit - if attributes has been changed - Objects are not isSame() [COMPARE_CHANGED]-th bit = if list is changed (added or removed some objects) in this case order flag is false to check use CODE-th byte : (X & CODE) != 0

compare

public static byte compare(int[] arrIdentifiers,
                           java.util.List lstList)
Compare array of ids and list of objects to find out if the order of the object as changed or if some objects were newly added or removed. Objects in list have to be instances of DataObject and OrderedData

Parameters:
arrIdentifiers - - array of ints - ids of the data object
lstList - - list of data object to compare with the ist of ids
Returns:
byte - result byte with bit flags of changes: [COMPARE_ORDER_CHANGE]-th bit = if order has been changed [COMPARE_CHANGED]-th bit = if list is changed (added or removed some objects) in this case order flag is false to check use CODE-th byte : (X & CODE) != 0


Copyright © 2003 - 2006 OpenSubsystems s.r.o.