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);
    }
  }
Creates size estimators for java objects. The estimators attempt to do most of the reflection
work at initialization time, and also take some shortcuts, to minimize the amount of work done
during the actual estimation.
TODO: clean up
storage-api/src/java/org/apache/hadoop/hive/ql/util/IncrementalObjectSizeEstimator.java