com.church.tools.MemberID.java Source code

Java tutorial

Introduction

Here is the source code for com.church.tools.MemberID.java

Source

/*
 * Church Software
 *
 * Package : com.church.tools
 * Filename: MemberID.java
 * Author  : Felix Chandrakumar <i@fc.id.au>
 * Website : www.churchsw.org
 * 
 * PUBLIC DOMAIN
 * 
 * As the Word of God says,
 * 
 * Freely you have received, freely give. - (Mat 10:8). For all things are from Jesus Christ,
 * by Jesus Christ, and for Jesus Christ. - (Romans 11:36)
 * 
 * Free means completely free! Church Software has no restrictions at all. The source code, 
 * binary and everything that is not licensed by others but included in Church Software bundle
 * is released to public domain and you can modify anything to fit your church needs. Public 
 * domain simply means everyone can use it without any restrictions.
 * 
 * WHY PUBLIC DOMAIN?
 * 
 * The manifestation of the Spirit is given to each one for the profit of all: for to one is
 * given the word of wisdom through the Spirit, to another the word of knowledge through the
 * same Spirit, to another faith by the same Spirit, to another gifts of healings by the same
 * Spirit, to another the working of miracles, to another prophecy, to another discerning of
 * spirits, to another different kinds of tongues, to another the interpretation of tongues.
 * But one and the same Spirit works all these things, distributing to each one individually
 * as He wills. - 1 Co 12:7-11
 * 
 * Woe unto them! for they have gone in the way of Cain, and ran greedily after the error of
 * Balaam for reward, and perished in the rebellion of Korah. - Jud 1:11
 * 
 * Jesus Christ gives word of knowledge through Holy Spirit for the profit of all. I dont
 * want to run greedily after the error of Balaam for reward. Balaam is a prophet of God who
 * went greedily to Balak. Unfortunately, many christian organizations, churches, bands, song
 * writers, musicians etc market the gifts of Holy Spirit, doing the same error of Balam for
 * reward. My Bible says, Woe to them and I don't want to be a part of them.
 */
package com.church.tools;

import org.apache.commons.codec.binary.Base64;

import com.church.gateway.Global;

/**
 * The Class MemberID.
 */
public class MemberID {

    /**
     * Gets the translated id.
     * 
     * @param member_id the member_id
     * @param name the name
     * 
     * @return the translated id
     */
    public static String getTranslatedID(int member_id, String name) {
        if (Global.useSimpleMemberID)
            return String.valueOf(member_id);
        int starter = 1000000000;
        String str = Integer.toHexString(starter - member_id).toUpperCase();
        String str2 = "";
        for (int i = str.length(); i < 8; i++)
            str2 += "0";
        str = str2 + str;
        String b64 = new String(Base64.encodeBase64((name + "     ").getBytes())).substring(0, 3).toUpperCase();
        return "#" + b64 + str;
    }

    /**
     * Gets the original id.
     * 
     * @param translated_id the translated_id
     * 
     * @return the original id
     */
    public static int getOriginalID(String translated_id) {
        int member_id = -99;
        try {
            if (Global.useSimpleMemberID)
                return Integer.parseInt(translated_id);
            String str = translated_id.substring(4);
            member_id = 1000000000 - Integer.parseInt(str, 16);
        } catch (NumberFormatException e) {
            //e.printStackTrace();
            member_id = -99;
        }
        return member_id;
    }
}