Utilities.GlobalVar.java Source code

Java tutorial

Introduction

Here is the source code for Utilities.GlobalVar.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Utilities;

import Encryption.BitInputStream;
import Encryption.BitOutputStream;
import Encryption.HuffmanTree;
//import java.awt.SplashScreen;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import static java.lang.System.exit;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import javax.swing.JOptionPane;
import org.apache.pdfbox.cos.COSArray;
import org.apache.pdfbox.cos.COSString;
import org.apache.pdfbox.pdfparser.PDFStreamParser;
import org.apache.pdfbox.pdfwriter.ContentStreamWriter;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.common.PDStream;
import org.apache.pdfbox.util.PDFOperator;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

/**
 *
 * @author SPC Cui
 */
public class GlobalVar {
    // index in database//               String data = LAST4SSN + GlobalVar.PARSE + LAST_NAME 
    //                        + GlobalVar.PARSE + LEAVE_TYPE + GlobalVar.PARSE 
    //                        + SO_DATE + GlobalVar.PARSE + SI_DATE + GlobalVar.PARSE
    //                        + LEAVE_DAYS + GlobalVar.PARSE + LEAVE_AREA 
    //                        + GlobalVar.PARSE + CTRL_NUM + GlobalVar.PARSE 
    //                        + FIRST_FIVE_LETTER_NAME + GlobalVar.PARSE + INPUT_SOURCE;  
    // --- new leave txt file----
    public static final int LAST4SSN_ID = 0; //SSN
    public static final int LN_ID = 1; // last name
    public static final int LV_T_ID = 2; //leave type
    public static final int PSO_D_ID = 3; // projected sign out date
    public static final int PSI_D_ID = 4; // projected sign in date
    public static final int P_ND_ID = 5; // project number of leave days;
    public static final int LV_A_ID = 6; // leave area
    public static final int CN_ID = 7; // PACID
    public static final int L5_ID = 8; // last five letter name
    public static final int IS_ID = 9; //input source  
    // -- sign out txt file ---
    public static final int SO_D_ID = 10; // Sign out date
    public static final int SO_T_ID = 11; // Sign out time
    // -- sign in ---
    public static final int SI_D_ID = 12; // Sign in date
    public static final int SI_T_ID = 13; // Sign in time   
    public static final int A_ND_ID = 14; // Actual number of leave days.    
    //  dates    
    public static final int DATE_LEN = 6; //150101 -  Jan 1, 2015
    public static final int ORDER_LEAVE_DAYS_IN_DMO = 3; // three digits in dmo
    public static final int YEAR_BASE = 2000; //  two-digit year to four digit year,e.g. 15 -> 2015
    public static final int SSN_LEN = 9;
    public static final int LAST4SSN_LEN = 4;
    public static final int PACID_LEN = 8; //e.g. NM1FB5AA 
    public static final double ONE_DAY_IN_MILLISECOND = 86400000.0;
    public static final double SOME_SEC_IN_MILLISECOND = 10.0; // unit: milliseconds

    public static Boolean ENCRYPTED = true;
    // Splash screen
    public static final long PROCESS_STEP = 2; // In splash screen, 2 increment  
    public static int START_PROCESS = 0; // 0%
    public static int DECODING_PROCESS = 10; // 10%
    public static int DECODED_PROCESS = 85; // 85%
    public static int LOADED_PROCESS = 95; // 95%

    // response from sign in sign out handler
    public static final int SSN_NOT_FOUND = -5;
    public static final int NAME_SSN_NOT_MATCH = -4;
    public static final int LEAVE_FORM_EXPIRED = -3;
    public static final int SIGN_IN_TOO_LATE = -2;
    public static final int SIGN_OUT_TOO_EARLY = -2;
    public static final int SUCCESS = 1;

    // new leave form 
    public static final int INPUT_SOURCE_LENGTH = 2;
    public static final int MAX_CTRL_NUM_LEN = 7;
    public static final String FOLDER_NAME = "data";
    public static final String SECURE_FOLDER_NAME = "source";
    public static final String ICON_NAME = "crest.jpg";
    public static final String SPLASHSCREN_NAME = "photo.jpg";
    public static final int NUM_SPLASHSCREEN = 4; // random number generator

    // check if the leaves have been previously logged
    public static final int DUP_CTRL_NUM_ERR = -1;
    public static final int OVERLAP_LEAVE_ERR = -2;
    public static final int GOOD_LEAVE = 1;
    public static final int SIGN_IN_SIGN_OUT_ERR = 2;
    public static final int NULL_INFO_ERR = 3;
    public static final int FUTURE_SIGN_IN_OUT_ERR = 4;
    public static final int IAS_ERR = 5;
    public static final int NULL_SSN_ERR = 6;
    public static final int NULL_DATE_ERR = 7;
    public static final int ELEVEN_MONTH = 330;

    public static final String FILE_EXT = ".txt";
    // public static final String ADSN = "4824";    
    public static final String CYCLE = "C0";
    public static final int NUM_WHITE_SPACE = 21; //for dmo transaction
    public static final int LEN_CTRL_NUM = 5;
    public static final int LEN_SEQ_NUM = 4; // in the batch file
    public static final int LEN_SEQ_NUM_5_DIGIT = 5; // sequence number on the documents

    public static final String PARSE = "`";
    public static final String CSV_PARSE = ",";
    public static final String SPACE_PARSE = " ";
    public static final String LIST_SPACE_PARSE = "   "; // used in the list on the panel.

    public static final String NEW_LEAVE_DB_NAME = "NewLeaveRoster";
    public static final String SIGN_IN_LEAVE_DB_NAME = "SignInRoster";
    public static final String SIGN_OUT_LEAVE_DB_NAME = "SignOutRoster";

    public static final String BATCH_FILE_NAME = "UNVERIFIED_AFAFC.DAT";
    public static final String VERIFIED_BATCH_FILE_NAME = "AFAFC.DAT";
    public static final String BATCH_FILE_NAME_EXT = ".DAT";

    // drot file
    public static final String DROT_FILE_NAME = "DROT";
    public static final String DROT_FILE_EXT = ".drot";
    public static final String ENCRYPTED_DROT = "ENCRYPTED.drot";

    // data array for encrypted drot file
    public static final int DROT_NUM_DATA = 3; // total pieces of data below    
    public static final int DROT_PROCESS_STATUS_INDEX = 0; // proc = P, recycle = Y, rej = R
    public static final int DROT_SSN_INDEX = 1;
    public static final int DROT_CTRL_NUM_INDEX = 2; // the order saved on the drot file

    // public static final int DROT_PROCESS_TYPE_INDEX = 0; // report = 3, start = 1, stop = 2
    public static final String DECODED_EXT = ".lon";
    public static final String ENCODED_EXT = ".src";
    public static final int NUM_LINES = 1000; //max num of lines in the output files
    public static final int DB_FILE_DELAY = 0; //delay between encoding and decoding files

    // process status
    public static final String LEAVE_PROCESSED = "P";
    public static final String LEAVE_REJECT = "J";
    public static final String LEAVE_RECYCLED = "Y";
    public static final String LEAVE_REJPART = "A";
    public static final String LEAVE_OTHER = "O";
    public static final int CHAR_MAX = 256; // max char value to be encoded

    //Excel writer
    public static final int COL_WIDTH = 20; //column width of in units of 1/256th of a character width 
    //    public static final String[] NEW_LEAVE_TITLES = {"Ctrl Number",
    //            "Last Four SSN", "Last Name", "Projected Sign-out Date", "Projected Sign-in Date", "Leave Area",
    //        "Leave Type", "Num of Days", "First Five"};
    //    public static final String[] NEW_LEAVE_TITLES = {"Ctrl Number",
    //            "Last Four SSN", "Last Name", "Projected Sign-out Date", "Projected Sign-in Date", "Leave Area",
    //        "Leave Type"};
    //    public static final String LEAVE_LIST_TITLE = "Control Number | Last 4 SSN | Last Name | Sign-out Date | Sign-in Date | Leave Area "
    //            + "| Leave Type";

    public static final String[] LEAVE_TITLES_V1 = { "Ctrl Number", "Last Four SSN", "Last Name", "Sign-out Date",
            "Sign-in Date", "Leave Area", "Leave Type" };
    // excel sheet.  Must match the title above
    public static final int CTRL_NUM_CELL_INDEX_V1 = 0;
    public static final int LAST4_CELL_INDEX_V1 = 1;
    public static final int LAST_NAME_CELL_INDEX_V1 = 2;
    public static final int SIGN_OUT_DATE_CELL_INDEX_V1 = 3; // for compare drot vs roster
    public static final int SIGN_IN_DATE_CELL_INDEX_V1 = 4;
    public static final int LEAVE_AREA_CELL_INDEX_V1 = 5; // the 5th cell data
    public static final int LEAVE_TYPE_CELL_INDEX_V1 = 6;

    // contains Full SSN, should avoid using this format as much as possible
    public static final String[] LEAVE_TITLES_V2 = { "Ctrl Number", "Full SSN", "Sign-out Date", "Sign-in Date",
            "Leave Area", "Leave Type" };
    public static final int CTRL_NUM_CELL_INDEX_V2 = 0;
    public static final int FULL_SSN_CELL_INDEX_V2 = 1;
    public static final int SIGN_OUT_DATE_CELL_INDEX_V2 = 2; // for compare drot vs roster
    public static final int SIGN_IN_DATE_CELL_INDEX_V2 = 3;
    public static final int LEAVE_AREA_CELL_INDEX_V2 = 4; // the 5th cell data
    public static final int LEAVE_TYPE_CELL_INDEX_V2 = 5;

    public static final int EFF_LAST_NAME_CHAR = 4; //  number of effective characters of last names, multi-key map 

    public static final int JUNK_LINES_UCFR_ROSTER = 6; // skip the junk lines

    //for SSNDataBase
    public static final String SSN_DB_KEY = "SSN";
    public static final String LAST_NAME_DB_KEY = "LAST NAME";
    public static final String FIRST_NAME_DB_KEY = "FIRST NAME";
    public static final String FIRST_FIVE_LETTER_DB_KEY = "FIRST FIVE";
    public static final String DUTY_STATUS_DB_KEY = "DUTY STATUS";

    public static final String[] SIGNED_LEAVE_TITLES = { "Ctrl Number", "Last Four", "Last Name", "Sign-out Date",
            "Sign-in Date", "Leave Area", "Leave Type" };

    public static final String OS = System.getProperty("sun.arch.data.model"); //32 bit os

    public static final String XLS_NEW_LEAVE_FILE_NAME = "NewLeaveFormRoster.xlsx";
    public static final String XLS_SIGNED_LEAVE_FILE_NAME = "SignedLeaveFormRoster.xlsx";

    // on the UCFR roster
    //public static final String SSN_CSV_FIRST_CELL_CONTENT = "Unit/PAS";
    public static final int NAME_INDEX_SSN_CSV = 4;
    public static final int SSN_INDEX_SSN_CSV = 6;
    public static final int DUTY_STATUS_INDEX_SSN_CSV = 7;
    public static final boolean DELETE_MODIFIED_UCFR_FILE = true;

    // LTR:  Proc 525196233 GONZA SB01 T6 2 RY 4830 20150717 07-16 [WEB] RY99999 
    public static final int PROCESS_STATUS_INDEX_LTR = 0;
    public static final int SSN_INDEX_LTR = 1;
    //    public static final int ITEM_NO = 12;  // no. of items in a valid leave transaction contains
    //    public static final int CHAR_NO = 113; // no of characters for a valid trimmed leave transaction (before shrinking) 

    // robot delay
    public static final int SPEED_DJMS = 2000;
    public static final int SPEED1 = 1;
    public static int SPEED2 = 400;
    public static final int PAGE_NUM_LINE = 4; //the line shows 01 OF 02 in djms

    //batch files
    public static final int FID_START_INDEX = 0;
    public static final int FID_STOP_INDEX = 5;
    public static final int SSN_START_INDEX = 5;
    public static final int SSN_STOP_INDEX = 14; //exclusive
    public static final int SO_START_INDEX = 19;
    public static final int SO_STOP_INDEX = 25; //exclusive
    public static final int SI_START_INDEX = 25;
    public static final int SI_STOP_INDEX = 31; //exclusive
    public static final int LV_TYPE_START_INDEX = 31;
    public static final int LV_TYPE_STOP_INDEX = 32; //exclusive
    public static final int LV_DAYS_START_INDEX = 32;
    public static final int LV_DAYS_STOP_INDEX = 35; //exclusive
    public static final int CTRL_NUM_START_INDEX = 36;
    public static final int CTRL_NUM_STOP_INDEX = 43; //exclusive
    public static final int OVERSEA_LEAVE_DAYS = 30;
    public static final String TEMP_DMO_NAME = "XXXXX"; // for full SSN xlsx file if UCFR is not loaded, xlsx2BatchHandler.java

    // pdf button
    public static int VOID_BUTTON_INDEX = 0;
    public static int SKIP_BUTTON_INDEX = 1;
    public static int SELECT_BUTTON_INDEX = 2;
    public static int NUM_BUTTON = 3;
    public static int MAX_NUM_PAGES = 500; //max number of pages a pdf file can have    

    // pdf file  processing    
    public static int COMMENT_TEXT_X_POSITION = 200;
    public static int COMMENT_TEXT_Y_POSITION = 760;
    public static int COMMENT_FONT_SIZE = 14;

    public static int PRE_PROC_TEXT_X_POSITION = 100;
    public static int PRE_PROC_TEXT_Y_POSITION = 650;
    public static int PRE_PROC_FONT_SIZE = 6;
    public static String PRE_PROC_KEY_SYMBOL = "-@#"; //symbol determine if the pdf is pre-processed  

    public static int SEQ_NUM_TEXT_X_POSITION = 600;
    public static int SEQ_NUM_TEXT_Y_POSITION = 400;
    public static int SEQ_NUM_FONT_SIZE = 20;

    public static int DATE_STAMP_X_POSITION = 150;
    public static int DATE_STAMP_Y_POSITION = 20;
    public static int DATE_STAMP_FONT_SIZE = 20;

    //colored xlsx roster
    public static final short BAD_STATUS_COLOR = IndexedColors.DARK_RED.getIndex(); //AWOL, DFR, Suspend, etc dd
    public static final short ETS_STATUS_COLOR = IndexedColors.BLUE.getIndex(); //dd
    public static final short DUPLICATE_LV_COLOR = IndexedColors.YELLOW.getIndex(); //dd
    public static final short DUPLICATE_CTRL_NUM_COLOR = IndexedColors.CORAL.getIndex(); //dd
    public static final short AFTER_PCS_COLOR = IndexedColors.TAN.getIndex(); //dd
    public static final short INPROCESSING_COLOR = IndexedColors.ORCHID.getIndex(); //dd
    public static final short WRONG_SSN_COLOR = IndexedColors.CORNFLOWER_BLUE.getIndex(); // dd
    public static final short OVERLAP_LV_COLOR = IndexedColors.LIGHT_ORANGE.getIndex(); //dd
    public static final short AUDITOR_DELETED_COLOR = IndexedColors.GREY_50_PERCENT.getIndex(); //dd
    public static final short IN_CYCLE_DUPLICATE_COLOR = IndexedColors.WHITE.getIndex(); //dd

    //BathInDJMS.java global 
    public static final int NO_ERR = 0;
    public static final int BAD_STATUS_ERR = 1; //ETS, AWOL, DFR, Suspend, etc
    public static final int ETS_ERR = 2;
    //private final int PCS_ERR = 3;
    public static final int DUPLICATE_LV_ERR = 3;
    public static final int DUPLICATE_CTRL_NUM_ERR = 4;
    public static final int AFTER_PCS_ERR = 5; //SM took leave after PCS
    public static final int INPROCESSING_ERR = 6; //SM took leave after PCS
    public static final int WRONG_SSN_ERR = 7;
    public static final int OVERLAP_LV_ERR = 8;
    public static final int AUDIT_DELETE_ERR = 9;
    public static final int IN_CYCLE_DUPLICATION_INVALID_FIRST_FIVE_ERR = 10;

    // position of legend color map
    public static final int LEGEND_X = 7;
    public static final int LEGEND_Y = 9;

    // temp file name 
    public static final String PRE_CEDMS_PDF = "temp_CEDMS.pdf";
    public static final String NUMBERED_PDF = "temp_numbered.pdf";
    // public static final String MERGED_PDF = "temp_merged.pdf";

    // return true if dir is created successfully, return false, otherwise.
    public static Boolean dirMake(File dir) {
        if (!dir.exists()) {
            if (dir.mkdir()) {
                System.out.println("Directory is created");
                return true;
            } else {
                System.out.println("Directory is created unsuccessfully!");
                return false;
            }
        }
        return false;
    }

    // return true if the syntax of the date valid
    public static Boolean isDateSyntaxValid(String date) {
        // System.out.println("date length " + date.length());
        if (date.length() != GlobalVar.DATE_LEN) {
            return false;
        }
        String num = date.replaceAll("[^\\d]", ""); //remove all the non-digits chars      
        // throw illegal argeument exception if non-digits characters passed in
        if (num.length() != GlobalVar.DATE_LEN) {
            return false;
        }

        MyDate myDate = new MyDate(date); //if string passed in can't create a new date, get null       
        if (myDate.getDay() == null) {
            return false;
        } else {
            return true;
        }
    }

    public static String computeNumOfDays(MyDate so, MyDate si) {
        if (so != null && si != null) {
            String days = "" + so.getDaysDiff(si);
            while (days.length() < GlobalVar.ORDER_LEAVE_DAYS_IN_DMO) {
                days = "0" + days;
            }
            return days;
        } else {
            return null;
        }
    }

    // read the data from the cell, return the correspondance DMO code for leave type
    public static String getDMOLeaveType(String cellStringValue) {
        if (cellStringValue != null) {
            if (cellStringValue.length() == 1) {
                cellStringValue = cellStringValue.toUpperCase().trim();
                char letter = cellStringValue.charAt(0);
                switch (letter) {
                case 'A':
                    return "A";
                case 'D':
                    return "D";
                case 'F':
                    return "F";
                case 'T':
                    return "T";
                case 'N':
                    return "N";
                case 'P':
                    return "P";
                //case 'T':  return "T";     
                default:
                    return null;

                }
            } else {
                String key = cellStringValue.substring(0, 3);
                if (key.equalsIgnoreCase("Ord")) {
                    return "A";
                } else if (key.equalsIgnoreCase("Eme")) {
                    return "D";
                } else if (key.equalsIgnoreCase("Con")) {
                    return "F";
                } else if (key.equalsIgnoreCase("Per")) {
                    return "T";
                } else {
                    JOptionPane.showMessageDialog(null,
                            "GlobalVar.java: Invalid leave type is given! Return null.");
                    //exit(1);
                    return null;
                }
            }
        } else {
            JOptionPane.showMessageDialog(null, "GlobalVar.java: DMO leave type is not given!");
            exit(1);
        }
        throw new IllegalArgumentException("GlobalVar.java: String value is null");
        //return "";  // shall never fall here.
    }

    // read the data from the cell, return the correspondance DMO code for leave area
    public static String getDMOLeaveArea(String cellStringValue) {
        cellStringValue = cellStringValue.toUpperCase().trim();
        if (cellStringValue != null) {
            switch (cellStringValue.charAt(0)) { //CONUS, OCONUS
            case 'C':
                return "1";
            case 'O':
                return "2";
            default:
                return null;
            }
        } else {
            return null;
        }
    }

    public static String getDMOLeaveArea(double cellNumericValue) {
        int value = (int) cellNumericValue;
        switch (value) {
        case 1:
            return "1";
        case 2:
            return "2";
        default:
            return null;
        }
    }

    // take an integer, return LEN_SEQ_NUM character long string
    public static String globalCountGenerator(int globalCount) {
        int base = 1;
        for (int i = 0; i < LEN_SEQ_NUM; i++) {
            base *= 10;
        }
        int global = globalCount + base;
        String ans = global + "";
        return ans.substring(ans.length() - GlobalVar.LEN_SEQ_NUM, ans.length());
    }

    // take an integer, return LEN_SEQ_NUM character long string
    public static String globalCountGenerator5Digit(int globalCount) {
        int base = 1;
        for (int i = 0; i < LEN_SEQ_NUM_5_DIGIT; i++) {
            base *= 10;
        }
        int global = globalCount + base;
        String ans = global + "";
        return ans.substring(ans.length() - LEN_SEQ_NUM_5_DIGIT, ans.length());
    }

    // for DMO
    public static String whiteSpace() {
        String whiteSpace = "";
        for (int i = 0; i < GlobalVar.NUM_WHITE_SPACE; i++) {
            whiteSpace = " " + whiteSpace;
        }
        return whiteSpace;
    }

    // oversea 2nd line: 1SB03111111111ROMER15070815080700000000000000000000000000          4830KHE2@0003
    public static String overseaPadding() {
        return "00000000000000000000000000          ";
    }

    // check if the leaves have been previously logged.
    // return GOOD_LEAVE if passed in leave is a valid one
    // return DUPLICATE_CTRL_NUM if it has duplicate ctrl number
    // return OVERLAP_LEAVE if its overlaps with previouos leaves.
    // Map<String, Map<String, List<String>>> has key of SSN, dates of values, leaves posted before
    public static int checkLeaves(String ctrl, String SSN, String SO, String SI, String first5,
            Map<String, Map<String, List<String>>> leaves) {
        if (ctrl != null && SSN != null && SO != null && SI != null && first5 != null) {
            MyDate today = new MyDate();
            MyDate newSO = new MyDate(SO);
            MyDate newSI = new MyDate(SI);

            if (newSO.after(newSI)) {
                return SIGN_IN_SIGN_OUT_ERR;
            }
            if (newSO.after(today) || newSI.after(today)) {
                return FUTURE_SIGN_IN_OUT_ERR;
            }
            if (!leaves.containsKey(SSN)) {
                Map<String, List<String>> value = new HashMap<String, List<String>>();
                List<String> dates = new ArrayList<String>();
                dates.add(SO);
                dates.add(SI);
                value.put(ctrl, dates);
                leaves.put(SSN, value);
                return GOOD_LEAVE;
            } else { //has the ssn
                Map<String, List<String>> leavesOftheSSN = leaves.get(SSN); // Map<ctrlNum, List<leave>>
                if (leavesOftheSSN.containsKey(ctrl)) {
                    return DUPLICATE_CTRL_NUM_ERR; //duplicate control number
                } else { //look through each leave 
                    Set<String> valueSet = new HashSet<>(leavesOftheSSN.keySet());
                    for (String thisCtrl : valueSet) {
                        //System.out.println(thisCtrl);                    
                        List<String> dates = leavesOftheSSN.get(thisCtrl);
                        MyDate thisSO = new MyDate(dates.get(0));
                        MyDate thisSI = new MyDate(dates.get(1));
                        //    System.out.println();
                        if (newSO.getDaysDiff(today) > ELEVEN_MONTH) {
                            return IAS_ERR;
                        }
                        if (newSO.beforeOrEqual(thisSI) && newSI.afterOrEqual(thisSO)) {
                            System.out.println("GlobalVar.java: overlap leaves 1.");
                            return OVERLAP_LEAVE_ERR;
                        } else if (newSI.afterOrEqual(thisSO) && newSI.beforeOrEqual(thisSI)) {
                            //     System.out.println("GlobalVar.java: overlap leaves 2. ");
                            return OVERLAP_LEAVE_ERR;
                        } else if (newSI.afterOrEqual(thisSI) && newSO.beforeOrEqual(thisSO)) {
                            System.out.println("GlobalVar.java: overlap leaves 3.");
                            return OVERLAP_LEAVE_ERR;
                        } else { //ok to add
                            List<String> newDates = new ArrayList<String>();
                            newDates.add(SO);
                            newDates.add(SI);
                            leavesOftheSSN.put(ctrl, newDates);
                            //                            //return GOOD_LEAVE;
                        }
                    }
                    //                    // went through all the leaves before the current one. Good to add
                    //                    List<String> newDates = new ArrayList<String>();
                    //                    newDates.add(SO);
                    //                    newDates.add(SI);
                    //                    leavesOftheSSN.put(ctrl, newDates);                                           
                    return GOOD_LEAVE;
                }
            }
        } else if (SSN != null && (SI == null || SO == null)) {
            return NULL_DATE_ERR;
        } else if (SSN != null) {
            return NULL_SSN_ERR;
        } else {
            return NULL_INFO_ERR;
        }
    }

    // given input file and output File Name
    public static void encode(String inFile, String outputFile) throws IOException {
        // open input file and count character frequencies
        FileInputStream input = new FileInputStream(inFile);
        int[] count = new int[CHAR_MAX];
        int n = input.read();
        while (n != -1) {
            count[n]++;
            n = input.read();
        }

        // build tree, get codes
        HuffmanTree t = new HuffmanTree(count);
        String[] codes = new String[CHAR_MAX + 1];
        t.assign(codes);

        // open output, write header
        BitOutputStream output = new BitOutputStream(outputFile);
        t.writeHeader(output);

        // reset input, encode file, close output
        input.close();//        
        input = new FileInputStream(inFile); //cause file occupied by the user

        n = input.read();
        while (n != -1) {
            writeString(codes[n], output);
            n = input.read();
        }
        writeString(codes[CHAR_MAX], output);
        input.close();
        output.close();
    }

    public static void decode(String inFile, String outputFile) throws IOException {
        // open encoded file, open output, build tree, decode
        BitInputStream input = new BitInputStream(inFile);
        PrintStream output = new PrintStream(new File(outputFile));
        HuffmanTree t = new HuffmanTree(input);
        t.decode(input, output, CHAR_MAX);
        output.close();
        input.close();

    }

    public static void writeString(String s, BitOutputStream output) {
        for (int i = 0; i < s.length(); i++)
            output.writeBit(s.charAt(i) - '0');
    }

    // clear new leave form temp data.  return true if action of deleting db is executed, return false otherwise
    public static boolean clearDataBase(String dataBaseName) {
        int response = JOptionPane.showConfirmDialog(null,
                "Contine to delete all the " + dataBaseName + " entered before?", "Confirm",
                JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
        if (response == JOptionPane.NO_OPTION) { //keep the old data file
            System.out.println("GlobalVar.java: No button clicked");
        } else if (response == JOptionPane.YES_OPTION) {
            if (dataBaseName.equals("New leave")) {
                String dir = GlobalVar.FOLDER_NAME + "/" + GlobalVar.NEW_LEAVE_DB_NAME + GlobalVar.FILE_EXT;
                File file = new File(dir);
                if (file.exists()) {
                    if (file.delete()) {
                        JOptionPane.showMessageDialog(null, dataBaseName + " are successfully cleared!");
                        return true;
                    } else {
                        JOptionPane.showMessageDialog(null,
                                "Can't delete" + dataBaseName + ". The temp file is opened by another program!");
                        return false;
                    }
                } else {
                    JOptionPane.showMessageDialog(null, dataBaseName + " have been successfully cleared");
                    return false;
                }
            } else {
                String dir1 = GlobalVar.FOLDER_NAME + "/" + GlobalVar.SIGN_IN_LEAVE_DB_NAME + GlobalVar.FILE_EXT;
                String dir2 = GlobalVar.FOLDER_NAME + "/" + GlobalVar.SIGN_OUT_LEAVE_DB_NAME + GlobalVar.FILE_EXT;
                File file1 = new File(dir1);
                File file2 = new File(dir2);
                if (file1.exists() || file2.exists()) {
                    file1.delete();
                    file2.delete();
                    JOptionPane.showMessageDialog(null, dataBaseName + " are successfully cleared!");
                    return true;
                } else {
                    JOptionPane.showMessageDialog(null, dataBaseName + " have been successfully cleared!");
                    return false;
                }
            }
        } else if (response == JOptionPane.CLOSED_OPTION) {
            System.out.println("GlobalVar.java: JOptionPane closed");
            //return false;
        }
        return false;
    }

    // return the last four of the SSN
    public static String last4Generator(String SSN) {
        if (SSN != null) {
            if (SSN.length() == SSN_LEN) {
                return SSN.substring(5);
            } else if (SSN.length() == LAST4SSN_LEN) {
                return SSN;
            } else if (SSN.length() < LAST4SSN_LEN) {
                while (SSN.length() < LAST4SSN_LEN) {
                    SSN = "0" + SSN;
                }
                return SSN;

            } else {
                JOptionPane.showMessageDialog(null, "Invalid SSN. Can't generate last four!");
                exit(1);
                return null;
            }
        } else {
            return null;
        }
    }

    // return input source given control number
    public static String getInputSource(String ctrlNum) {
        return ctrlNum.substring(0, 2);
    }

    public static void encodeSSNfile(String SSNfile)
            throws FileNotFoundException, IOException, InterruptedException {
        String tempFile = "modified.txt";
        File sourceFile = new File(SSNfile);
        File destFile = new File(tempFile);
        PrintStream output;
        try (Scanner input = new Scanner(sourceFile)) {
            output = new PrintStream(destFile);
            // skip the junk
            //                for (int i = 0; i < JUNK_LINES_UCFR_ROSTER; i++){
            //                    input.nextLine();
            //                }   
            int lineCount = 0;
            while (input.hasNextLine()) {
                String line = input.nextLine();
                String[] items = line.split(CSV_PARSE);

                if (items != null && items.length > DUTY_STATUS_INDEX_SSN_CSV) {
                    String rawSsn = items[GlobalVar.SSN_INDEX_SSN_CSV];

                    String letters = rawSsn.replaceAll("[0-9]", "");

                    if (rawSsn != null && rawSsn.length() > 0 && letters.length() == 0) { //contains no letters but digits
                        //System.out.println(rawSsn);
                        output.println(line);
                    }
                }
                lineCount++;
            }
            input.close();
            output.close();
            System.out.println(lineCount);
        }

        encodeSSNfileHelper(tempFile);
        if (DELETE_MODIFIED_UCFR_FILE) {// modified file that truncated irrelavant lines
            destFile.delete();
        }
    }

    // pre: passed in SSNfile must be valid
    // pass in a giant UCFR file and divide it into small ones and encrypt them
    private static void encodeSSNfileHelper(String SSNfile)
            throws FileNotFoundException, IOException, InterruptedException {
        File folder = new File(GlobalVar.SECURE_FOLDER_NAME);
        GlobalVar.dirMake(folder);
        //String file = "myData.lon";
        File sourceFile = new File(SSNfile);
        Scanner input = new Scanner(sourceFile);
        PrintStream output;
        int num = 0;
        //Boolean isNew = false;
        int fileCount = 0;

        ////////////////////////////////////////////////////////////////////////////////        
        // divide the DMO database into many small files
        ////////////////////////////////////////////////////////////////////////////////        
        String inFileName = SECURE_FOLDER_NAME + "/file" + fileCount + DECODED_EXT;
        File inFile = new File(inFileName); // decoded file        
        output = new PrintStream(inFile);

        // divide the file into small ones and encode each
        // stops if reaches empty line

        while (input.hasNext()) {
            String line = input.nextLine();
            //System.out.println(line);
            String[] items = line.split(CSV_PARSE);
            String name = items[NAME_INDEX_SSN_CSV]; // full name info on UCFR roster
            if (items != null && name != null) {

                output.println(line);
                num++;
                if (num % GlobalVar.NUM_LINES == 0) {
                    output.close(); // close the previous file

                    //encode the raw data file and delete after done
                    String targetFileName = SECURE_FOLDER_NAME + "/file" + fileCount + ENCODED_EXT;
                    GlobalVar.encode(inFileName, targetFileName);
                    System.out.println("GlobalVar.java: unencrypted file deleted: " + inFile.delete());
                    System.out.println("File: " + fileCount + " is processed.");

                    fileCount++;
                    inFileName = SECURE_FOLDER_NAME + "/file" + fileCount + DECODED_EXT; // open a new file
                    inFile = new File(inFileName);
                    output = new PrintStream(inFile);
                }
            }
        }
        //retrieve the last source file and target file
        //Thread.sleep(1000);
        output.close(); //must close before delete
        String targetFileName = SECURE_FOLDER_NAME + "/file" + fileCount + ENCODED_EXT;
        inFileName = SECURE_FOLDER_NAME + "/file" + fileCount + DECODED_EXT;
        inFile = new File(inFileName);
        encode(inFileName, targetFileName);
        System.out.println("GlobalVar.java: unencrypted file deleted: " + inFile.delete()); // delete status
        System.out.println("File: " + fileCount + " is processed.");

        /////////////////////////////////////////////////////////////////////////////////////
        //        // start decoding
        ///////////////////////////////////////////////////////////////////////////////////
        //        fileCount = 0;
        //        File encodedfolder = new File(GlobalVar.SECURE_FOLDER_NAME);
        //        for (File encodedfile : encodedfolder.listFiles()) {
        //            String encodedFileName = encodedfile.getName();
        //            String[] encodedFileNameArray = encodedFileName.split("\\.");
        //            
        //            String decodedFileName = GlobalVar.SECURE_FOLDER_NAME + "\\" + encodedFileNameArray[0] + GlobalVar.FILE_EXT;  //GlobalVar.FILE_EXT = ".txt"
        //            encodedFileName = GlobalVar.SECURE_FOLDER_NAME + "\\" + encodedFileName;
        //            GlobalVar.decode(encodedFileName, decodedFileName);
        //            encodedfile.delete();           
        //        }       

    }

    // given SSN, return false, if SSN is not valid, return true, otherwise
    public static Boolean isSSNvalid(String SSN_string) {
        if (SSN_string.length() != GlobalVar.SSN_LEN) {
            return false;
        }
        SSN_string = SSN_string.replaceAll("[^\\d]", "");
        if (SSN_string.length() != GlobalVar.SSN_LEN) {
            return false;
        }
        return true;
    }

    // pre: ssn is not an empty string
    // pad ssn with 0 in the front if it is not ssn long.
    public static String fullSSNgenerator(String ssn) {
        if (ssn != null) {
            ssn = ssn.replaceAll("-", ""); //replace some ssn with format of 000-00-0000
            if (ssn.length() > SSN_LEN) {
                JOptionPane.showMessageDialog(null, "GlobalVar.java: Invalid SSN! SSN is longer than 9 digits.");
                return null;
            } else if (ssn.contains("[^0-9]")) {
                JOptionPane.showMessageDialog(null,
                        "GlobalVar.java: SSN should not contain any non-digit characters.");
                return null;
            } else {
                while (ssn.length() < SSN_LEN) {
                    ssn = "0" + ssn;
                }
                return ssn;
            }
        } else {
            JOptionPane.showMessageDialog(null, "GlobalVar.java: SSN can not be null");
            return null;
        }
    }

    public static String shrinkLine(String raw) {
        return raw.replaceAll("\\s+", " ");
    }

    public static String removeNonDigits(String raw) {
        return raw.replaceAll("[^0-9]", ""); //.replaceAll("[^\\d]","");
    }

    public static String removeDigits(String raw) {
        return raw.replaceAll("[0-9]", ""); //.replaceAll("[\\d]","");
    }

    //sanity checks and return ctrl number from the raw one
    public static String readCtrlNum(String ctrlNum) {
        ctrlNum = ctrlNum.toUpperCase().trim();
        if (ctrlNum.length() == GlobalVar.MAX_CTRL_NUM_LEN) {
            String inputSource = ctrlNum.substring(0, GlobalVar.INPUT_SOURCE_LENGTH).toUpperCase();
            String is = inputSource.replaceAll("[^A-Z]", ""); //remove all non-letters
            //extract characters other than the input source
            String numStr = ctrlNum.substring(GlobalVar.INPUT_SOURCE_LENGTH).replaceAll("[^\\d]", ""); //extract all the numbers   
            if (is.length() == GlobalVar.INPUT_SOURCE_LENGTH && numStr.length() == GlobalVar.LEN_CTRL_NUM) {
                //JOptionPane.showMessageDialog(null, "Invalid ctrl number received.");
                return ctrlNum;
            } else {
                return null;
            }
        } else {
            return null;
        }
    }

    // return the process status code given the text, 
    // used in EncryptDrots.java & CompareDrotVSRoster.java 
    // e.g,  
    // PROCESSED = "P";
    // REJECT = "J";
    // RECYCLED = "Y";
    // REJPART = "A";
    // OTHER = "O";   
    public static String readProcessStatus(String status) {
        if (status.equalsIgnoreCase("pro")) {
            return GlobalVar.LEAVE_PROCESSED;
        } else if (status.equalsIgnoreCase("rej")) {
            return GlobalVar.LEAVE_REJECT;
        } else if (status.equalsIgnoreCase("rec")) {
            return GlobalVar.LEAVE_RECYCLED;
            //        } else if (status.equalsIgnoreCase("Rej*Part")) {
            //            return GlobalVar.LEAVE_REJPART;
        } else {
            return GlobalVar.LEAVE_OTHER;
        }
    }

    public static int batchGenerator(String SSN, String first5, String lastName, String signOutDate,
            String signInDate, String leaveType, String leaveDays, String leaveArea, String ctrlNum, int leaveMsg,
            int lineCount, int globalCount, PrintStream output, List<String> errorList, String ADSN) {
        String lc = ADSN;
        String cycle = GlobalVar.CYCLE;
        String inputSource = GlobalVar.getInputSource(ctrlNum);

        //int leaveMsg = GlobalVar.checkLeaves(ctrlNum, SSN, signOutDate, signInDate, first5, leaves);
        int leaveDaysIntType = Integer.parseInt(leaveDays);

        if (leaveMsg == GlobalVar.GOOD_LEAVE) {
            // ready to code and increment sequence for next transaction
            if (Integer.parseInt(leaveDays) > OVERSEA_LEAVE_DAYS) { //threshold for warning msg for leaves over 30 days
                JOptionPane.showMessageDialog(null,
                        "Line " + lineCount + " : " + ctrlNum + " " + SSN + " leaves over " + leaveDays + " days!");
            }
            if (leaveDaysIntType > GlobalVar.OVERSEA_LEAVE_DAYS && leaveArea.equals("2")) { // overseas over 30 days
                String data = "ASB03" + SSN + first5 + signOutDate + signInDate + leaveType + leaveDays + leaveArea
                        + ctrlNum + "000" + GlobalVar.whiteSpace() + lc + inputSource + cycle + "@"
                        + GlobalVar.globalCountGenerator(globalCount);
                output.println(data);
                String data1 = "1SB03" + SSN + first5 + signOutDate + signInDate + GlobalVar.overseaPadding() + lc
                        + inputSource + cycle + "@" + GlobalVar.globalCountGenerator(globalCount);
                output.println(data1);
            } else {
                String data = "0SB03" + SSN + first5 + signOutDate + signInDate + leaveType + leaveDays + leaveArea
                        + ctrlNum + "000" + GlobalVar.whiteSpace() + lc + inputSource + cycle + "@"
                        + GlobalVar.globalCountGenerator(globalCount);
                output.println(data);
            }
            globalCount++;
            //        } else if (leaveMsg == GlobalVar.OVERLAP_LEAVE_ERR){
            //            // String lastName = container.get("Last Name");
            //            String msg = "Line: " + lineCount + ": " +  ctrlNum 
            //                    + " " + lastName + " " + signOutDate + " - " + signInDate;
            //            JOptionPane.showMessageDialog(null, msg + "\n is overlapping with a leave posted before.");
            //        } else if (leaveMsg == GlobalVar.DUPLICATE_CTRL_NUM_ERR) {
            //            //String lastName = container.get("Last Name");
            //            JOptionPane.showMessageDialog(null,  "Line " + lineCount + ": Duplicate control number " 
            //                    + ctrlNum  + " for " + lastName + ".");
            //        }

        } else if (leaveMsg == GlobalVar.OVERLAP_LEAVE_ERR) {
            //String lastName = container.get(keyList.get(GlobalVar.LAST_NAME_INDEX));
            String msg = "Line " + lineCount + " : " + ctrlNum + " " + SSN + " " + signOutDate + " - " + signInDate
                    + " overlapps with a leave posted before.";
            errorList.add(msg);
            //JOptionPane.showMessageDialog(null, msg + "\n is overlapping with a leave posted before.");
        } else if (leaveMsg == GlobalVar.DUPLICATE_CTRL_NUM_ERR) {
            //String lastName = container.get(keyList.get(GlobalVar.LAST_NAME_INDEX));
            String msg = "Line " + lineCount + " : Duplicate control number " + ctrlNum + " for " + SSN + ".";
            errorList.add(msg);
            //            JOptionPane.showMessageDialog(null, "Line " + lineCount + " : Duplicate control number " 
            //                    + ctrlNum  + " for " + lastName + ".");
        } else if (leaveMsg == GlobalVar.SIGN_IN_SIGN_OUT_ERR) {
            String msg = "Line " + lineCount + " : sign-in sign-out dates invalid.";
            errorList.add(msg);
            //            JOptionPane.showMessageDialog(null, "Line " + lineCount + " : sign-in sigg-out dates invalid." );    
        } else if (leaveMsg == GlobalVar.NULL_INFO_ERR) {
            //JOptionPane.showMessageDialog(null, "Line " + lineCount + " : contains null info." );  
            String msg = "Line " + lineCount + " : contains null info.";
            errorList.add(msg);
        } else if (leaveMsg == GlobalVar.NULL_DATE_ERR) {
            //JOptionPane.showMessageDialog(null, "Line " + lineCount + " : contains null info." );  
            String msg = "Line " + lineCount + " : contains invalid date.";
            errorList.add(msg);
        } else if (leaveMsg == GlobalVar.NULL_SSN_ERR) {
            //JOptionPane.showMessageDialog(null, "Line " + lineCount + " : contains null info." );  
            String msg = "Line " + lineCount + " : contains invalid ssn.";
            errorList.add(msg);
        } else if (leaveMsg == GlobalVar.FUTURE_SIGN_IN_OUT_ERR) {
            String msg = "Line " + lineCount + " : Can't sign in, sign out in the future.";
            errorList.add(msg);
            //JOptionPane.showMessageDialog(null, "Line " + lineCount + " : Can't sign in, sign out in the future." );  
        } else if (leaveMsg == IAS_ERR) {
            //JOptionPane.showMessageDialog(null, "Line " + lineCount + " : IAS error. Please turn in leave form to DMPO in person." );  
            String msg = "Line " + lineCount + " : IAS error. Please turn in leave form to DMPO in person.";
            errorList.add(msg);
        }
        return globalCount;
    }

    // pre: given the copied string from a pdf page, 
    // post: return ctrl number and last full SSN ssn.
    public static String[] getCtrlNumAndfullSSN(String res) {
        String[] data = res.split(GlobalVar.PRE_PROC_KEY_SYMBOL);
        if (data != null && data.length > 1) {
            String ctrlNum = data[0];
            String fullSSN = data[1];
            if (ctrlNum.length() >= MAX_CTRL_NUM_LEN && fullSSN.length() >= GlobalVar.SSN_LEN) { // ctrlNum and last4SSN
                ctrlNum = ctrlNum.substring(ctrlNum.length() - MAX_CTRL_NUM_LEN);
                fullSSN = fullSSN.substring(0, GlobalVar.SSN_LEN);
                String[] result = { ctrlNum, fullSSN };
                return result;
            }
        }
        return null;
    }

    // create a standard style for given workbook
    public static CellStyle createStandardStyle(XSSFWorkbook myWorkBook) {
        CellStyle style = myWorkBook.createCellStyle();
        style.setBorderRight(CellStyle.BORDER_THIN);
        style.setRightBorderColor(IndexedColors.BLACK.getIndex());
        style.setBorderBottom(CellStyle.BORDER_THIN);
        style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
        style.setBorderLeft(CellStyle.BORDER_THIN);
        style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
        style.setBorderTop(CellStyle.BORDER_THIN);
        style.setTopBorderColor(IndexedColors.BLACK.getIndex());
        style.setWrapText(true);
        return style;
    }

    // pre: the pdf file pre-processed and pre-numbered
    // post:  re-number the sequence numbers if any
    public static void updateSeqNum(PDDocument doc, String cycle) throws IOException {
        int sequenceNum = 1;
        List pages = doc.getDocumentCatalog().getAllPages();

        for (int i = 0; i < pages.size(); i++) {
            PDPage page = (PDPage) pages.get(i);
            PDStream contents = page.getContents();
            PDFStreamParser parser = new PDFStreamParser(contents.getStream());
            parser.parse();
            List tokens = parser.getTokens();
            for (int j = 0; j < tokens.size(); j++) {
                Object next = tokens.get(j);
                if (next instanceof PDFOperator) {
                    PDFOperator op = (PDFOperator) next;
                    // Tj and TJ are the two operators that display strings in a PDF
                    if (op.getOperation().equals("Tj")) {
                        // Tj takes one operator and that is the string
                        // to display so lets update that operator
                        COSString previous = (COSString) tokens.get(j - 1);
                        String string = previous.getString();
                        //                        System.out.println(string);
                        //                        System.out.println(string.charAt(5));
                        if (string.contains("/0")) {
                            String seq = cycle + "/" + GlobalVar.globalCountGenerator5Digit(sequenceNum);
                            string = string.replaceFirst(string, seq);
                            previous.reset();
                            previous.append(string.getBytes("ISO-8859-1"));
                            sequenceNum++;
                            break;
                        }
                        //Word you want to change. Currently this code changes word "Solr" to "Solr123"
                        previous.reset();
                        previous.append(string.getBytes("ISO-8859-1"));

                    } else if (op.getOperation().equals("TJ")) {
                        COSArray previous = (COSArray) tokens.get(j - 1);
                        for (int k = 0; k < previous.size(); k++) {
                            Object arrElement = previous.getObject(k);
                            if (arrElement instanceof COSString) {
                                COSString cosString = (COSString) arrElement;
                                String string = cosString.getString();
                                //                                System.out.println(string);
                                if (string.contains("/00")) {
                                    String seq = cycle + "/" + GlobalVar.globalCountGenerator5Digit(sequenceNum);
                                    string = string.replaceFirst(string, seq);
                                    cosString.reset();
                                    cosString.append(string.getBytes("ISO-8859-1"));
                                    sequenceNum++;
                                    break;
                                }
                                // Currently this code changes word "Solr" to "Solr123"
                                cosString.reset();
                                cosString.append(string.getBytes("ISO-8859-1"));
                                //                                break;
                            }
                        }
                    }
                }
            }
            // now that the tokens are updated we will replace the page content stream.
            PDStream updatedStream = new PDStream(doc);
            OutputStream out = updatedStream.createOutputStream();
            ContentStreamWriter tokenWriter = new ContentStreamWriter(out);
            tokenWriter.writeTokens(tokens);
            page.setContents(updatedStream);
        }
    }

    // given the error code, return the comment that writes on the pdf page.
    public static String commentMap(int errCode, String adsn) {
        switch (errCode) {
        case GlobalVar.BAD_STATUS_ERR:
            return "Bad Status: AWOL, DFR, Confined, Suspend, etc";
        case GlobalVar.ETS_ERR:
            return "ETS status. Process in Separation";
        case GlobalVar.DUPLICATE_LV_ERR:
            return "Duplicate leave (NAR)";
        case GlobalVar.DUPLICATE_CTRL_NUM_ERR:
            return "Duplicate ctrl num";
        case GlobalVar.AFTER_PCS_ERR:
            return "SM took leave after left " + GlobalVar.ADSNmap(adsn);
        case GlobalVar.INPROCESSING_ERR:
            return "SM doesn't belong to " + GlobalVar.ADSNmap(adsn) + ". Needs in-processing";
        case GlobalVar.WRONG_SSN_ERR:
            return "Wrong SSN";
        case GlobalVar.OVERLAP_LV_ERR:
            return "Overlaps with leave posted before.";
        case GlobalVar.AUDIT_DELETE_ERR:
            return "Deleted by auditors due to format issues.";
        case GlobalVar.IN_CYCLE_DUPLICATION_INVALID_FIRST_FIVE_ERR:
            return "In cycle duplications/Invalid first five.";
        default:
            return "Good leave.";
        }
    }

    // return 
    public static String ADSNmap(String adsn) {
        if (adsn.charAt(0) == 'O') {
            throw new IllegalArgumentException(
                    "Please contact Cui, Wei for this issue. Check ADSN in lib/config.DAT.");
        } else {
            int adsnNumber = Integer.parseInt(adsn);
            switch (adsnNumber) {
            case 4801:
                return "Ft Rucker";
            case 4802:
                return "Ft Shafter";
            case 4803:
                return "Ft Benning";
            case 4804:
                return "Ft Eustis";
            case 4805:
                return "Ft Dix";
            case 4806:
                return "Ft McClellan";
            case 4807:
                return "DMPO Indianapolis";
            case 4808:
                return "Presidio Of Monterey";
            case 4809:
                return "Ft Belvoir";
            case 4810:
                return "Ft Sill";
            case 4811:
                return "Ft McCoy";
            case 4812:
                return "Ft Riley";
            case 4813:
                return "Ft Huachuca";
            case 4814:
                return "Ft McPherson";
            case 4815:
                return "Ft Meade";
            case 4816:
                return "Ft Buchanan";
            case 4817:
                return "Ft Richardson";
            case 4818:
                return "Ft Wainwright";
            case 4819:
                return "Ft Greely";
            case 4820:
                return "Ft Carson";
            case 4821:
                return "Ft. Leavenworth";
            case 4822:
                return "Ft. Sam Houston";
            case 4823:
                return "Ft. Drum";
            case 4824:
                return "Ft. Bliss";
            case 4825:
                return "Ft. Polk";
            case 4826:
                return "MICOM";
            case 4827:
                return "US Military Academy";
            case 4828:
                return "Ft. Leonardwood";
            case 4829:
                return "Schofield Barracks";
            case 4830:
                return "JBLM";
            case 4831:
                return "15th Finance";
            case 4832:
                return "215th Finance";
            case 4833:
                return "230th Finance";
            case 4834:
                return "13th Finance Group";
            case 4835:
                return "Ft. Jackson";
            case 4836:
                return "Ft Irwin";
            case 4837:
                return "Ft Stewart";
            case 4838:
                return "Aberdeen Proving Grounds";
            case 4839:
                return "Ft Lee";
            case 4840:
                return "Ft Campbell";
            case 4841:
                return "82nd Airborne";
            case 4842:
                return "107th Finance Battalion";
            case 4843:
                return "18th Airborne Corps";
            case 4844:
                return "Ft Knox";
            case 4845:
                return "Ft Gordon";
            case 4846:
                return "Camp Zama";
            case 4848:
                return "Bethesda";
            case 4901:
                return "USPFO For Montgomery";
            case 4902:
                return "USPFO For Ft Richardson";
            case 4904:
                return "USPFO For Phoenix";
            case 4905:
                return "USPFO For North Little Rock";
            case 4906:
                return "USPFO For San Luis Obispo";
            case 4908:
                return "USPFO For Englewood";
            case 4909:
                return "USPFO For Hartford";
            case 4910:
                return "USPFO For New Castle";
            case 4912:
                return "USPFO For St Augustine";
            case 4913:
                return "USPFO For Atlanta";
            case 4914:
                return "USPFO For Tamuning";
            case 4916:
                return "USPFO For Boise";
            case 4917:
                return "USPFO For Springfield";
            case 4918:
                return "USPFO For Indianapolis";
            case 4919:
                return "USPFO For Johnston";
            case 4920:
                return "USPFO For Topeka";
            case 4921:
                return "USPFO For Frankfort";
            case 4922:
                return "USPFO For New Orleans";
            case 4923:
                return "USPFO For Augusta";
            case 4924:
                return "USPFO For Havre De Grace";
            case 4925:
                return "USPFO For Natick";
            case 4926:
                return "USPFO For Lansing";
            case 4927:
                return "USPFO For St Paul";
            case 4928:
                return "USPFO For Jackson";
            case 4929:
                return "USPFO For Jefferson City";
            case 4930:
                return "USPFO For Helena";
            case 4931:
                return "USPFO For Lincoln";
            case 4932:
                return "USPFO For Carson City";
            case 4933:
                return "USPFO For Concord";
            case 4934:
                return "USPFO For Lawrenceville";
            case 4935:
                return "USPFO For Santa Fe";
            case 4936:
                return "USPFO For Latham";
            case 4937:
                return "USPFO For Raleigh";
            case 4938:
                return "USPFO For Bismark";
            case 4939:
                return "USPFO For Columbus";
            case 4940:
                return "USPFO For Oklahoma City";
            case 4941:
                return "USPFO For Salem";
            case 4942:
                return "USPFO For Annville";
            case 4943:
                return "USPFO For Puerto Rico";
            case 4944:
                return "USPFO For Providence";
            case 4945:
                return "USPFO For Columbia";
            case 4946:
                return "USPFO For Rapid City";
            case 4947:
                return "USPFO For Nashville";
            case 4948:
                return "USPFO For Austin";
            case 4949:
                return "USPFO For Draper";
            case 4950:
                return "USPFO For Colchester";
            case 4951:
                return "USPFO For Richmond";
            case 4952:
                return "USPFO For St Croix";
            case 4953:
                return "USPFO For Tacoma";
            case 4954:
                return "USPFO For Buckhannon";
            case 4955:
                return "USPFO For Madison";
            case 4956:
                return "USPFO For Cheyenne";
            case 5061:
                return "Ft Ritchie";
            case 5083:
                return "Ft Monmouth";
            case 5480:
                return "Camp Humphries";
            case 5499:
                return "SHAPE Headquarters";
            case 5548:
                return "Finance Office";
            case 5588:
                return "Riyahd";
            case 6311:
                return "Tongduchon";
            case 6321:
                return "Wurzburg";
            case 6332:
                return "Hanover";
            case 6335:
                return "Vicenza";
            case 6340:
                return "Ft Leavenworth";
            case 6342:
                return "Ft Clayton";
            case 6350:
                return "Camp Zama";
            case 6372:
                return "33rd Finance Support Unit";
            case 6375:
                return "USARCT";
            case 6387:
                return "Hanau";
            case 6409:
                return "Taegu";
            case 6411:
                return "Seoul";
            case 6420:
                return "Redstone Arsenal";
            case 6460:
                return "208th Finance Battalion";
            case 6552:
                return "Fitzsimmons AMC";
            case 6567:
                return "Class B Finance Office";
            case 6583:
                return "8th Finance Battalion";
            case 8508:
                return "USAMPAO";
            case 8520:
                return "SOFT-FSU";
            case 8586:
                return "USARPSA";
            case 8599:
                return "8th Finance Battalion Forward";
            case 8748:
                return "Dhahran";
            case 8763:
                return "Kosovo";
            case 9999:
                return "Intransit Accounts";
            case 81:
                return "White House Command"; //OO81
            case 155:
                return "US Military Academy"; //O155
            default:
                return "JBLM";
            }
        }
        // throw new IllegalArgumentException("Invaid ADSN is given! Check ADSN in lib/config.DAT.");

    }

    // return 
    public static String etsMapCode(String adsn) {
        int adsnNumber = Integer.parseInt(adsn);
        switch (adsnNumber) {
        case 4830:
            return "RY";
        case 4826:
            return "DT";
        case 4844:
            return "TR";
        //            case 4824: return "@@";
        //            case 4846: return "@@";
        //            case 4848: return "@@";
        default:
            return "@@";
        }
    }
}