Java Card
v2.2.2

javacardx.framework.util
Class ArrayLogic

java.lang.Object
  extended by javacardx.framework.util.ArrayLogic

public final class ArrayLogic
extends Object

The ArrayLogic class contains common utility functions for manipulating arrays of primitive components - byte, short or int. Some of the methods may be implemented as native functions for performance reasons. All the methods in ArrayLogic class are static methods.

Some methods of ArrayLogic, namely arrayCopyRepack(), arrayCopyRepackNonAtomic() and arrayFillGenericNonAtomic(), refer to the persistence of array objects. The term persistent means that arrays and their values persist from one CAD session to the next, indefinitely. The JCSystem class is used to control the persistence and transience of objects.

Since:
2.2.2
See Also:
javacard.framework.JCSystem

Method Summary
static byte arrayCompareGeneric(Object src, short srcOff, Object dest, short destOff, short length)
          Compares an array from the specified source array, beginning at the specified position, with the specified position of the destination array from left to right.
static short arrayCopyRepack(Object src, short srcOff, short srcLen, Object dest, short destOff)
          Copies data from the specified source array, beginning at the specified position, to the specified position of the destination array.
static short arrayCopyRepackNonAtomic(Object src, short srcOff, short srcLen, Object dest, short destOff)
          Non-atomically copies data from the specified source array, beginning at the specified position, to the specified position of the destination array.
static short arrayFillGenericNonAtomic(Object theArray, short off, short len, Object valArray, short valOff)
          Fills the array of primitive components(non-atomically) beginning at the specified position, for the specified length with the specified value.
static short arrayFindGeneric(Object theArray, short off, byte[] valArray, short valOff)
          Finds the first occurrence of the specified value within the specified array.
 
Methods inherited from class java.lang.Object
equals
 

Method Detail

arrayCopyRepack

public static final short arrayCopyRepack(Object src,
                                          short srcOff,
                                          short srcLen,
                                          Object dest,
                                          short destOff)
                                   throws ArrayIndexOutOfBoundsException,
                                          NullPointerException,
                                          TransactionException,
                                          UtilException
Copies data from the specified source array, beginning at the specified position, to the specified position of the destination array. Note that this method may be used to copy from an array of any primitive component - byte, short or int to another (or same) array of any primitive component - byte, short or int. If the source array primitive component size is smaller than that of the destination array, a packing conversion is performed; if the source array primitive component size is larger than that of the destination array, an unpacking operation is performed; if the source and destination arrays are of the same component type, simple copy without any repacking is performed.

Note:

Parameters:
src - source array object
srcOff - offset within source array to start copy from
srcLen - number of source component values to be copied from the source array
dest - destination array object
destOff - offset within destination array to start copy into
Returns:
a value of one more than the offset within the dest array where the last copy was performed
Throws:
ArrayIndexOutOfBoundsException - if copying would cause access of data outside array bounds
NullPointerException - if either src or dest is null
TransactionException - if copying would cause the commit capacity to be exceeded
UtilException - with the following reason codes:
  • UtilException.ILLEGAL_VALUE if src or dest is not an array of primitive components, or if the srcLen parameter is incorrect
See Also:
javacard.framework.JCSystem.getUnusedCommitCapacity()

arrayCopyRepackNonAtomic

public static final short arrayCopyRepackNonAtomic(Object src,
                                                   short srcOff,
                                                   short srcLen,
                                                   Object dest,
                                                   short destOff)
                                            throws ArrayIndexOutOfBoundsException,
                                                   NullPointerException,
                                                   UtilException
Non-atomically copies data from the specified source array, beginning at the specified position, to the specified position of the destination array. Note that this method may be used to copy from an array of any primitive component - byte, short or int to another (or same) array of any primitive component - byte, short or int. If the source array primitive component size is smaller than that of the destination array, a packing conversion is performed; if the source array primitive component size is larger than that of the destination array, an unpacking operation is performed; if the source and destination arrays are of the same component type, simple copy without any repacking is performed.

This method does not use the transaction facility during the copy operation even if a transaction is in progress. Thus, this method is suitable for use only when the contents of the destination array can be left in a partially modified state in the event of a power loss in the middle of the copy operation.

Note:

Parameters:
src - source array object
srcOff - offset within source array to start copy from
srcLen - number of source component values to be copied from the source array
dest - destination array object
destOff - offset within destination array to start copy into
Returns:
a value of one more than the offset within the dest array where the last copy was performed
Throws:
ArrayIndexOutOfBoundsException - if copying would cause access of data outside array bounds
NullPointerException - if either src or dest is null
UtilException - with the following reason codes:
  • UtilException.ILLEGAL_VALUE if src or dest is not an array of primitive components, or if the srcLen parameter is incorrect

arrayFillGenericNonAtomic

public static final short arrayFillGenericNonAtomic(Object theArray,
                                                    short off,
                                                    short len,
                                                    Object valArray,
                                                    short valOff)
                                             throws ArrayIndexOutOfBoundsException,
                                                    NullPointerException,
                                                    UtilException
Fills the array of primitive components(non-atomically) beginning at the specified position, for the specified length with the specified value. Note that this method may be used to fill an array of any primitive component type - byte, short or int. The value used for the fill operation is itself specified using an array (valArray) of the same primitive component type at offset valOff.

This method does not use the transaction facility during the fill operation even if a transaction is in progress. Thus, this method is suitable for use only when the contents of the array can be left in a partially filled state in the event of a power loss in the middle of the fill operation.

The following code snippet shows how this method is typically used:

   public short[] myArray = new short[10];
  ..
  // Fill the entire array myArray of 10 short components with the value 0x1234
  myArray[0] = (short)0x1234;
  ArrayLogic.arrayFillGenericNonAtomic(myArray, (short)0, (short)10, myArray, (short)0);
  ..
 

Note:

Parameters:
theArray - the array object
off - offset within array to start filling the specified value
len - the number of component values to be filled
valArray - the array object containing the fill value
valOff - the offset within the valArray array containing the fill value
Returns:
off+len
Throws:
ArrayIndexOutOfBoundsException - if the fill operation would cause access of data outside array bounds
NullPointerException - if theArray or valArray is null
UtilException - with the following reason codes:
  • UtilException.ILLEGAL_VALUE if theArray or valArray is not an array of primitive components
  • UtilException.TYPE_MISMATCHED if the valArray parameter is not an array of the same primitive component type as the theArray.

arrayCompareGeneric

public static final byte arrayCompareGeneric(Object src,
                                             short srcOff,
                                             Object dest,
                                             short destOff,
                                             short length)
                                      throws ArrayIndexOutOfBoundsException,
                                             NullPointerException,
                                             UtilException
Compares an array from the specified source array, beginning at the specified position, with the specified position of the destination array from left to right. Note that this method may be used to compare any two arrays of the same primitive component type - byte, short or int. Returns the ternary result of the comparison : less than(-1), equal(0) or greater than(1).

Note:

Parameters:
src - source array object
srcOff - offset within source array to start compare
dest - destination array object
destOff - offset within destination array to start compare
length - length to be compared
Returns:
the result of the comparison as follows:
  • 0 if identical
  • -1 if the first miscomparing primitive component in source array is less than that in destination array
  • 1 if the first miscomparing primitive component in source array is greater than that in destination array
Throws:
ArrayIndexOutOfBoundsException - if comparing all the components would cause access of data outside array bounds
NullPointerException - if either src or dest is null
UtilException - with the following reason codes:
  • UtilException.ILLEGAL_VALUE if src or dest is not an array of primitive components, or if the length parameter is incorrect
  • UtilException.TYPE_MISMATCHED if the dest parameter is not an array of the same primitive component type.

arrayFindGeneric

public static final short arrayFindGeneric(Object theArray,
                                           short off,
                                           byte[] valArray,
                                           short valOff)
                                    throws ArrayIndexOutOfBoundsException,
                                           NullPointerException,
                                           UtilException
Finds the first occurrence of the specified value within the specified array. The search begins at the specified position and proceeds until the end of the array. Note that this method may be used to search an array of any primitive component type - byte, short or int. The value used in the search operation is itself specified by the appropriate number of consecutive bytes at offset valOff in the byte array parameter valArray.

Note:

Parameters:
theArray - the array object to search
off - offset within the array to start serching for the specified value
valArray - the array object containing the search value
valOff - the offset within the valArray array containing the search value
Returns:
the offset into the specified array where the first occurrence of specified value was found or -1 if the specified value does not occur in the specified portion of the array
Throws:
ArrayIndexOutOfBoundsException - if the search operation would cause access of data outside array bounds
NullPointerException - if theArray is null
UtilException - with the following reason code:
  • UtilException.ILLEGAL_VALUE if theArray is not an array of primitive components.

Java Card
v2.2.2

Copyright © 1993-2005 Sun Microsystems, Inc. 4150 Network Circle,
Santa Clara, CA, 95054, U.S.A. All Rights Reserved.