package com.exmertec.dummie.cache.impl;

import java.lang.reflect.Field;
import java.util.Stack;

public class LevelCache extends DefaultCache {

    private Integer floor;

    private Stack<Class<?>> parents;

    public LevelCache(Integer floor) {
        super();

        this.floor = floor;
        this.parents = new Stack<Class<?>>();
    }

    // TODO: still has bug if a class has field with same type as itself.
    public boolean isOverFloor(Field field) {
        if (parents.empty()) {
            parents.push(field.getDeclaringClass());
        } else if (parents.contains(field.getDeclaringClass())) {
            while (!parents.peek().equals(field.getDeclaringClass())) {
                parents.pop();
            }
        } else {
            if (parents.size() >= floor) {
                return true;
            }
            parents.push(field.getDeclaringClass());
        }
        return false;
    }

    public Object getCachedData(Field field) {
        return isOverFloor(field) ? null : super.getCachedData(field);
    }
}

@@ -421,22 +421,24 @@
 lf.%0A    
-public
+ private
  boolean

make method isOverFloor as private