/** * Resolves the truly underlying object in a possible chain of {@link gobblin.util.Decorator}. * * @param obj object to resolve. * @return the true non-decorator underlying object. */ public static Object resolveUnderlyingObject(Object obj) { while(obj instanceof Decorator) { obj = ((Decorator)obj).getDecoratedObject(); } return obj; }
/** * Finds the decorator lineage of the given object. * * <p> * If object is not a {@link gobblin.util.Decorator}, this method will return a singleton list with just the object. * If object is a {@link gobblin.util.Decorator}, it will return a list of the underlying object followed by the * decorator lineage up to the input decorator object. * </p> * * @param obj an object. * @return List of the non-decorator underlying object and all decorators on top of it, * starting with underlying object and ending with the input object itself (inclusive). */ public static List<Object> getDecoratorLineage(Object obj) { List<Object> lineage = Lists.newArrayList(obj); Object currentObject = obj; while(currentObject instanceof Decorator) { currentObject = ((Decorator)currentObject).getDecoratedObject(); lineage.add(currentObject); } return Lists.reverse(lineage); } }