package org.gnode.nix.internal;

import org.bytedeco.javacpp.DoublePointer;
import org.bytedeco.javacpp.IntPointer;
import org.bytedeco.javacpp.Pointer;

import java.util.ArrayList;

public class Utils {

    /**
     * Converts {@link IntPointer} to {@link Integer} {@link ArrayList}
     *
     * @param ip {@link IntPointer} pointer to be converted
     * @return array list of ints
     */
    public static ArrayList<Integer> convertPointerToList(IntPointer ip) {
        ArrayList<Integer> intList = new ArrayList<Integer>();
        if (ip != null) {
            for (int i = 0; i < ip.capacity(); i++) {
                intList.add(ip.get(i));
            }
        }
        return intList;
    }

    /**
     * Converts {@link DoublePointer} to {@link Double} {@link ArrayList}
     *
     * @param dp {@link DoublePointer} pointer to be converted
     * @return array list of doubles
     */
    public static ArrayList<Double> convertPointerToList(DoublePointer dp) {
        ArrayList<Double> doubleList = new ArrayList<Double>();
        if (dp != null) {
            for (int i = 0; i < dp.capacity(); i++) {
                doubleList.add(dp.get(i));
            }
        }
        return doubleList;
    }

    /**
     * Converts a {@link Pointer} type object of particular class to an {@link ArrayList}
     *
     * @param pointer pointer to be converted
     * @param cls     pointer object class
     * @param <T>     generic type
     * @return array list of object of class cls
     */
    public static <T> ArrayList<T> convertPointerToList(Pointer pointer, Class<T> cls) {
        ArrayList<T> arrayList = new ArrayList<T>();
        if (pointer != null) {
            for (int i = 0; i < pointer.capacity(); i++) {
                arrayList.add(cls.cast(pointer.position(i)));
            }
        }
        return arrayList;
    }
}

@@ -174,16 +174,39 @@
 rayList;
+%0Aimport java.util.Date;
 %0A%0Apublic
@@ -1877,11 +1877,772 @@
 t;%0A    %7D
+%0A%0A    /**%0A     * Convert seconds to appropriate date%0A     * %3Cp/%3E%0A     * Required for functions that use time_t%0A     *%0A     * @param seconds seconds to be converted%0A     * @return date object%0A     */%0A    public static Date convertSecondsToDate(long seconds) %7B%0A        // convert to milliseconds by multiplying by 1000%0A        // DateTime expects input in milliseconds%0A        seconds *= 1000L;%0A%0A        return new Date(seconds);%0A    %7D%0A%0A    /**%0A     * Convert date object to seconds%0A     * %3Cp/%3E%0A     * Required for functions that use time_t%0A     *%0A     * @param dateTime date to be converted%0A     * @return seconds%0A     */%0A    public static long convertDateToSeconds(Date dateTime) %7B%0A        long seconds = dateTime.getTime() / 1000;%0A        return seconds;%0A    %7D
 %0A%7D%0A

add date conversion util funcs