private static void addCollectionEstimator(HashMap<Class<?>, ObjectEstimator> byType, Deque<Object> stack, Field field, Class<?> fieldClass, Object fieldObj) { Collection<?> fieldCol = null; if (fieldObj != null) { fieldCol = (Collection<?>) fieldObj; if (fieldCol.size() == 0) { fieldCol = null; LOG.trace("Empty collection {}", field); } } if (fieldCol != null) { for (Object element : fieldCol) { if (element != null) { addToProcessing(byType, stack, element, element.getClass()); } } } if (field != null) { Class<?> collectionArg = getCollectionArg(field); if (collectionArg != null) { addToProcessing(byType, stack, null, collectionArg); } // TODO: there was code here to create guess-estimate for collection wrt how usage changes // when removing elements. However it's too error-prone for anything involving // pre-allocated capacity, so it was discarded. // We will estimate collection as an object (only if it's a field). addToProcessing(byType, stack, fieldObj, fieldClass); } }
private static void addCollectionEstimator(HashMap<Class<?>, ObjectEstimator> byType, Deque<Object> stack, Field field, Class<?> fieldClass, Object fieldObj) { Collection<?> fieldCol = null; if (fieldObj != null) { fieldCol = (Collection<?>) fieldObj; if (fieldCol.size() == 0) { fieldCol = null; LOG.trace("Empty collection {}", field); } } if (fieldCol != null) { for (Object element : fieldCol) { if (element != null) { addToProcessing(byType, stack, element, element.getClass()); } } } if (field != null) { Class<?> collectionArg = getCollectionArg(field); if (collectionArg != null) { addToProcessing(byType, stack, null, collectionArg); } // TODO: there was code here to create guess-estimate for collection wrt how usage changes // when removing elements. However it's too error-prone for anything involving // pre-allocated capacity, so it was discarded. // We will estimate collection as an object (only if it's a field). addToProcessing(byType, stack, fieldObj, fieldClass); } }