Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    /**
     * Convert item reference number to string of length according to partition
     *
     * @param itemRefNo irn
     * @param partition p
     * @return Item reference number string
     * @throws Exception
     */
    private static String getItemRefNoString(int itemRefNo, byte partition) throws Exception {
        String result = Integer.toString(itemRefNo);
        int length;
        switch (partition) {
        case 0:
            length = 1;
            break;
        case 1:
            length = 2;
            break;
        case 2:
            length = 3;
            break;
        case 3:
            length = 4;
            break;
        case 4:
            length = 5;
            break;
        case 5:
            length = 6;
            break;
        case 6:
            length = 7;
            break;
        default:
            throw new Exception("Unknown partition: " + partition);
        }
        while (result.length() < length)
            result = "0" + result;
        return result;
    }
}