private static boolean applyGeneralFieldRules(EncodeMode[] generalFieldType) {

        int block_count, i, j, k;
        EncodeMode current, next, last;
        int[] blockLength = new int[200];
        EncodeMode[] blockType = new EncodeMode[200];

        block_count = 0;

        blockLength[block_count] = 1;
        blockType[block_count] = generalFieldType[0];

        for (i = 1; i < generalFieldType.length; i++) {
            current = generalFieldType[i];
            last = generalFieldType[i - 1];

            if (current == last) {
                blockLength[block_count] = blockLength[block_count] + 1;
            } else {
                block_count++;
                blockLength[block_count] = 1;
                blockType[block_count] = generalFieldType[i];
            }
        }

        block_count++;

        for (i = 0; i < block_count; i++) {
            current = blockType[i];
            next = blockType[i + 1];

            if ((current == EncodeMode.ISOIEC) && (i != (block_count - 1))) {
                if ((next == EncodeMode.ANY_ENC) && (blockLength[i + 1] >= 4)) {
                    blockType[i + 1] = EncodeMode.NUMERIC;
                }
                if ((next == EncodeMode.ANY_ENC) && (blockLength[i + 1] < 4)) {
                    blockType[i + 1] = EncodeMode.ISOIEC;
                }
                if ((next == EncodeMode.ALPHA_OR_ISO) && (blockLength[i + 1] >= 5)) {
                    blockType[i + 1] = EncodeMode.ALPHA;
                }
                if ((next == EncodeMode.ALPHA_OR_ISO) && (blockLength[i + 1] < 5)) {
                    blockType[i + 1] = EncodeMode.ISOIEC;
                }
            }

            if (current == EncodeMode.ALPHA_OR_ISO) {
                blockType[i] = EncodeMode.ALPHA;
                current = EncodeMode.ALPHA;
            }

            if ((current == EncodeMode.ALPHA) && (i != (block_count - 1))) {
                if ((next == EncodeMode.ANY_ENC) && (blockLength[i + 1] >= 6)) {
                    blockType[i + 1] = EncodeMode.NUMERIC;
                }
                if ((next == EncodeMode.ANY_ENC) && (blockLength[i + 1] < 6)) {
                    if ((i == block_count - 2) && (blockLength[i + 1] >= 4)) {
                        blockType[i + 1] = EncodeMode.NUMERIC;
                    } else {
                        blockType[i + 1] = EncodeMode.ALPHA;
                    }
                }
            }

            if (current == EncodeMode.ANY_ENC) {
                blockType[i] = EncodeMode.NUMERIC;
            }
        }

        if (block_count > 1) {
            i = 1;
            while (i < block_count) {
                if (blockType[i - 1] == blockType[i]) {
                    /* bring together */
                    blockLength[i - 1] = blockLength[i - 1] + blockLength[i];
                    j = i + 1;

                    /* decrease the list */
                    while (j < block_count) {
                        blockLength[j - 1] = blockLength[j];
                        blockType[j - 1] = blockType[j];
                        j++;
                    }
                    block_count--;
                    i--;
                }
                i++;
            }
        }

        for (i = 0; i < block_count - 1; i++) {
            if (blockType[i] == EncodeMode.NUMERIC && (blockLength[i] & 1) != 0) {
                /* Odd size numeric block */
                blockLength[i] = blockLength[i] - 1;
                blockLength[i + 1] = blockLength[i + 1] + 1;
            }
        }

        j = 0;
        for (i = 0; i < block_count; i++) {
            for (k = 0; k < blockLength[i]; k++) {
                generalFieldType[j] = blockType[i];
                j++;
            }
        }

        if (blockType[block_count - 1] == EncodeMode.NUMERIC && (blockLength[block_count - 1] & 1) != 0) {
            /* If the last block is numeric and an odd size, further processing needs to be done outside this procedure */
            return true;
        } else {
            return false;
        }
    }
private static boolean applyGeneralFieldRules ( EncodeMode [ ] generalFieldType ) { int block_count , i , j , k ; EncodeMode current , next , last ; int [ ] blockLength = new int [ 200 ] ; EncodeMode [ ] blockType = new EncodeMode [ 200 ] ; block_count = 0 ; blockLength [ block_count ] = 1 ; blockType [ block_count ] = generalFieldType [ 0 ] ; for ( i = 1 ; i < generalFieldType . length ; i ++ ) { current = generalFieldType [ i ] ; last = generalFieldType [ i - 1 ] ; if ( current == last ) { blockLength [ block_count ] = blockLength [ block_count ] + 1 ; } else { block_count ++ ; blockLength [ block_count ] = 1 ; blockType [ block_count ] = generalFieldType [ i ] ; } } block_count ++ ; for ( i = 0 ; i < block_count ; i ++ ) { current = blockType [ i ] ; next = blockType [ i + 1 ] ; if ( ( current == EncodeMode . ISOIEC ) && ( i != ( block_count - 1 ) ) ) { if ( ( next == EncodeMode . ANY_ENC ) && ( blockLength [ i + 1 ] >= 4 ) ) { blockType [ i + 1 ] = EncodeMode . NUMERIC ; } if ( ( next == EncodeMode . ANY_ENC ) && ( blockLength [ i + 1 ] < 4 ) ) { blockType [ i + 1 ] = EncodeMode . ISOIEC ; } if ( ( next == EncodeMode . ALPHA_OR_ISO ) && ( blockLength [ i + 1 ] >= 5 ) ) { blockType [ i + 1 ] = EncodeMode . ALPHA ; } if ( ( next == EncodeMode . ALPHA_OR_ISO ) && ( blockLength [ i + 1 ] < 5 ) ) { blockType [ i + 1 ] = EncodeMode . ISOIEC ; } } if ( current == EncodeMode . ALPHA_OR_ISO ) { blockType [ i ] = EncodeMode . ALPHA ; current = EncodeMode . ALPHA ; } if ( ( current == EncodeMode . ALPHA ) && ( i != ( block_count - 1 ) ) ) { if ( ( next == EncodeMode . ANY_ENC ) && ( blockLength [ i + 1 ] >= 6 ) ) { blockType [ i + 1 ] = EncodeMode . NUMERIC ; } if ( ( next == EncodeMode . ANY_ENC ) && ( blockLength [ i + 1 ] < 6 ) ) { if ( ( i == block_count - 2 ) && ( blockLength [ i + 1 ] >= 4 ) ) { blockType [ i + 1 ] = EncodeMode . NUMERIC ; } else { blockType [ i + 1 ] = EncodeMode . ALPHA ; } } } if ( current == EncodeMode . ANY_ENC ) { blockType [ i ] = EncodeMode . NUMERIC ; } } if ( block_count > 1 ) { i = 1 ; while ( i < block_count ) { if ( blockType [ i - 1 ] == blockType [ i ] ) { blockLength [ i - 1 ] = blockLength [ i - 1 ] + blockLength [ i ] ; j = i + 1 ; while ( j < block_count ) { blockLength [ j - 1 ] = blockLength [ j ] ; blockType [ j - 1 ] = blockType [ j ] ; j ++ ; } block_count -- ; i -- ; } i ++ ; } } for ( i = 0 ; i < block_count - 1 ; i ++ ) { if ( blockType [ i ] == EncodeMode . NUMERIC && ( blockLength [ i ] & 1 ) != 0 ) { blockLength [ i ] = blockLength [ i ] - 1 ; blockLength [ i + 1 ] = blockLength [ i + 1 ] + 1 ; } } j = 0 ; for ( i = 0 ; i < block_count ; i ++ ) { for ( k = 0 ; k < blockLength [ i ] ; k ++ ) { generalFieldType [ j ] = blockType [ i ] ; j ++ ; } } if ( blockType [ block_count - 1 ] == EncodeMode . NUMERIC && ( blockLength [ block_count - 1 ] & 1 ) != 0 ) { return true ; } else { return false ; } }
Attempts to apply encoding rules from sections 7.2.5.5.1 to 7.2.5.5.3 of ISO/IEC 24724:2006