// Path: src/main/java/me/welkinbai/bsonmapper/exception/BsonMapperConverterException.java
// public class BsonMapperConverterException extends RuntimeException {
// 
//     public BsonMapperConverterException() {
//         super();
//     }
// 
//     public BsonMapperConverterException(String message) {
//         super(message);
//     }
// 
//     public BsonMapperConverterException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public BsonMapperConverterException(Throwable cause) {
//         super(cause);
//     }
// 
// }


import me.welkinbai.bsonmapper.exception.BsonMapperConverterException;
package me.welkinbai.bsonmapper;


/**
 * Created by welkinbai on 2017/6/17.
 */
public enum MapperLayerCounter {
    MAPPER_LAYER_COUNTER;

    private final ThreadLocal<Integer> threadLocalCount = new ThreadLocal<Integer>();

    public void addCount(BsonMapperConfig bsonMapperConfig) {
        Integer count = threadLocalCount.get();
        if (count == null) {
            threadLocalCount.set(1);
            return;
        }
        count++;
        if (count > bsonMapperConfig.getMaxMapperLayerNum()) {
            threadLocalCount.remove();
// Path: src/main/java/me/welkinbai/bsonmapper/exception/BsonMapperConverterException.java
// public class BsonMapperConverterException extends RuntimeException {
// 
//     public BsonMapperConverterException() {
//         super();
//     }
// 
//     public BsonMapperConverterException(String message) {
//         super(message);
//     }
// 
//     public BsonMapperConverterException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public BsonMapperConverterException(Throwable cause) {
//         super(cause);
//     }
// 
// }


// Path: src/main/java/me/welkinbai/bsonmapper/MapperLayerCounter.java
import me.welkinbai.bsonmapper.exception.BsonMapperConverterException;

package me.welkinbai.bsonmapper;


/**
 * Created by welkinbai on 2017/6/17.
 */
public enum MapperLayerCounter {
    MAPPER_LAYER_COUNTER;

    private final ThreadLocal<Integer> threadLocalCount = new ThreadLocal<Integer>();

    public void addCount(BsonMapperConfig bsonMapperConfig) {
        Integer count = threadLocalCount.get();
        if (count == null) {
            threadLocalCount.set(1);
            return;
        }
        count++;
        if (count > bsonMapperConfig.getMaxMapperLayerNum()) {
            threadLocalCount.remove();
            throw new BsonMapperConverterException(String.format("exceed max layer in bsonMapperConfig.current layer is %s.max layer is %s", count, bsonMapperConfig.getMaxMapperLayerNum()));