All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.javers.spring.auditable.AspectUtil Maven / Gradle / Ivy

There is a newer version: 7.7.0
Show newest version
package org.javers.spring.auditable;

import org.aspectj.lang.JoinPoint;
import org.javers.common.collections.Lists;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * @author bartosz walacik
 */
public class AspectUtil {
    public static List collectArguments(JoinPoint jp){
        List result = new ArrayList<>();

        for (Object arg: jp.getArgs()) {
            if (arg instanceof Collection) {
                result.addAll((Collection)arg);
            } else {
                result.add(arg);
            }
        }
        return result;
    }

    public static Iterable collectReturnedObjects(Object returnedObject){
        if (returnedObject instanceof Iterable) {
            return (Iterable)returnedObject;
        }
        if (returnedObject == null) {
            return Collections.emptyList();
        }
        return Lists.immutableListOf(returnedObject);
    }
}