// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from duration.djinni

package com.dropbox.djinni.test;

import java.util.concurrent.atomic.AtomicBoolean;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

public abstract class TestDuration {
    @Nonnull
    public static native String hoursString(@Nonnull java.time.Duration dt);

    @Nonnull
    public static native String minutesString(@Nonnull java.time.Duration dt);

    @Nonnull
    public static native String secondsString(@Nonnull java.time.Duration dt);

    @Nonnull
    public static native String millisString(@Nonnull java.time.Duration dt);

    @Nonnull
    public static native String microsString(@Nonnull java.time.Duration dt);

    @Nonnull
    public static native String nanosString(@Nonnull java.time.Duration dt);

    @Nonnull
    public static native java.time.Duration hours(int count);

    @Nonnull
    public static native java.time.Duration minutes(int count);

    @Nonnull
    public static native java.time.Duration seconds(int count);

    @Nonnull
    public static native java.time.Duration millis(int count);

    @Nonnull
    public static native java.time.Duration micros(int count);

    @Nonnull
    public static native java.time.Duration nanos(int count);

    @Nonnull
    public static native java.time.Duration hoursf(double count);

    @Nonnull
    public static native java.time.Duration minutesf(double count);

    @Nonnull
    public static native java.time.Duration secondsf(double count);

    @Nonnull
    public static native java.time.Duration millisf(double count);

    @Nonnull
    public static native java.time.Duration microsf(double count);

    @Nonnull
    public static native java.time.Duration nanosf(double count);

    @CheckForNull
    public static native java.time.Duration box(long count);

    public static native long unbox(@CheckForNull java.time.Duration dt);

    public static final class CppProxy extends TestDuration
    {
        private final long nativeRef;
        private final AtomicBoolean destroyed = new AtomicBoolean(false);

        private CppProxy(long nativeRef)
        {
            if (nativeRef == 0) throw new RuntimeException("nativeRef is zero");
            this.nativeRef = nativeRef;
        }

        private native void nativeDestroy(long nativeRef);
        public void destroy()
        {
            boolean destroyed = this.destroyed.getAndSet(true);
            if (!destroyed) nativeDestroy(this.nativeRef);
        }
        protected void finalize() throws java.lang.Throwable
        {
            destroy();
            super.finalize();
        }
    }
}
