Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    /**
     * Convert company prefix to string of length according to partition
     *
     * @param companyPrefix cp
     * @param partition     p
     * @return Company prefix string
     * @throws Exception
     */
    private static String getCompanyPrefixString(long companyPrefix, byte partition) throws Exception {
        String result = Long.toString(companyPrefix);
        int length;
        switch (partition) {
        case 0:
            length = 12;
            break;
        case 1:
            length = 11;
            break;
        case 2:
            length = 10;
            break;
        case 3:
            length = 9;
            break;
        case 4:
            length = 8;
            break;
        case 5:
            length = 7;
            break;
        case 6:
            length = 6;
            break;
        default:
            throw new Exception("Unknown partition: " + partition);
        }
        while (result.length() < length)
            result = "0" + result;
        return result;
    }
}