Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**
     * The alphabet used for generate strings of element ID.
     */
    private static char[] alphabet = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e',
            'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
            'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
            'V', 'W', 'X', 'Y', 'Z', '_', '=' };

    /**
     * Convert element ID to string, in the radix of 64. The string may contains
     * the characters: {@code 0-9, a-z, A-Z, _, =}. The generated string can be
     * parsed by {@code MUtility.parseID()}.
     * @param id element ID
     * @return string
     */
    public static String stringID(long id) {
        StringBuilder builder = new StringBuilder();
        int ch = 0;
        long _id = id;
        while (_id != 0) {
            ch = (int) (_id & 0x000000000000003FL);
            _id >>>= 6;
            builder.append(alphabet[ch]);
        }
        return builder.reverse().toString();
    }
}