Example usage for java.util LinkedHashMap getClass

List of usage examples for java.util LinkedHashMap getClass

Introduction

In this page you can find the example usage for java.util LinkedHashMap getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:net.tachtler.browscap4j.Browscap4jFileReader.java

/**
 * Initialize the Browscap4jDataBean./* w ww. j  a v  a 2s. c om*/
 * 
 * @param csvFile
 * @return Browscap4jDataBean
 * @throws IllegalStateException
 * @throws FileNotFoundException
 * @throws IOException
 */
public static Browscap4jDataBean initBrowscap4jData(File csvFile)
        throws IllegalStateException, FileNotFoundException, IOException {

    log.debug("*csvFile                                : " + csvFile);

    /**
     * Browscap4jDataBean with the LinkedHashMap<Pattern, Browscap4jPositionBean>
     * browscap4jMap and the String browscap4jString as data.
     */
    Browscap4jDataBean browscap4jDataBean = new Browscap4jDataBean();

    /**
     * LinkedHashMap with regular expression pattern as key from the original
     * userAgentString and Browscap4jPositionBean integer variables as value object
     * by determining the offset and the length for each line.
     */
    LinkedHashMap<Pattern, Browscap4jPositionBean> browscap4jMap = new LinkedHashMap<Pattern, Browscap4jPositionBean>();

    /**
     * Generate browscap4jString with all fields filled up with data from
     * browscap.csv to a single String.
     */
    String browscap4jString = null;

    /**
     * StringBuilder for fast concatenation.
     */
    StringBuilder stringBuilder = new StringBuilder();

    /*
     * Check if csvFile is null.
     */
    if (null == csvFile) {
        throw new IllegalStateException("Argument csvFile is null (NOT set).");
    }

    /*
     * Iterate over the csvFile - browscap.csv with all the data and generate a
     * string with all the lines concatenated. Generate a regular expression pattern
     * from the first column of the csvFile - browscap.csv as key and calculate the
     * offset and the length for every single line inside the concatenated string as
     * Browscap4jPositionBean as value.
     */
    LineIterator lineIterator = FileUtils.lineIterator(csvFile, "UTF-8");

    try {
        int offset = 0;
        String[] col = null;

        while (lineIterator.hasNext()) {
            String line = lineIterator.nextLine();

            Browscap4jPositionBean browscap4jPositionBean = new Browscap4jPositionBean(offset,
                    offset + line.length());

            offset += line.length();

            col = line.split("\",\"");

            browscap4jMap.put(Pattern.compile(convertToRegex(col[0].substring(1))), browscap4jPositionBean);

            stringBuilder.append(line);
        }
    } finally {
        LineIterator.closeQuietly(lineIterator);
    }

    /*
     * Generate the String browscap4jString from StringBuilder stringBuilder.
     */
    browscap4jString = stringBuilder.toString();

    /*
     * Debug NOT the Map and the String, because of too much entry's, only the class
     * should be printed out in debug mode, to see if the browscap4jMap and the
     * browscap4jString are NOT null.
     */
    log.debug("*browscap4jMap                          : " + browscap4jMap.getClass());
    log.debug("*browscap4jString                       : " + browscap4jString.getClass());

    browscap4jDataBean.setBrowscap4jMap(browscap4jMap);
    browscap4jDataBean.setBrowscap4jString(browscap4jString);

    return browscap4jDataBean;
}