package org.helioviewer.jhv.time;

import javax.annotation.Nonnull;

public class JHVDate implements Comparable<JHVDate> {

    public final long milli;
    private final int hash;
    private final String string;

    public JHVDate(String date) {
        this(TimeUtils.parse(date));
    }

    public JHVDate(long _milli) {
        if (_milli < 0)
            throw new IllegalArgumentException("Argument cannot be negative");
        milli = _milli;
        hash = (int) (milli ^ (milli >>> 32));
        string = TimeUtils.format(milli);
    }

    @Override
    public int compareTo(@Nonnull JHVDate dt) {
        return Long.compare(milli, dt.milli);
    }

    @Override
    public final boolean equals(Object o) {
        if (this == o)
            return true;
        if (!(o instanceof JHVDate))
            return false;
        JHVDate d = (JHVDate) o;
        return milli == d.milli;
    }

    @Override
    public int hashCode() {
        return hash;
    }

    @Override
    public String toString() {
        return string;
    }

}

@@ -62,16 +62,151 @@
 nnull;%0A%0A
+import com.google.common.cache.CacheBuilder;%0Aimport com.google.common.cache.CacheLoader;%0Aimport com.google.common.cache.LoadingCache;%0A%0A
 public c
@@ -312,41 +312,8 @@
 ash;
-%0A    private final String string;
 %0A%0A  
@@ -600,50 +600,8 @@
 ));%0A
-        string = TimeUtils.format(milli);%0A
     
@@ -1087,21 +1087,400 @@
     
-return string
+try %7B%0A            return cache.get(milli);%0A        %7D catch (Exception e) %7B%0A            e.printStackTrace();%0A        %7D%0A        return getString(milli);%0A    %7D%0A%0A    private static final LoadingCache%3CLong, String%3E cache = CacheBuilder.newBuilder().maximumSize(100000).build(CacheLoader.from(JHVDate::getString));%0A%0A    private static String getString(long ms) %7B%0A        return TimeUtils.format(ms)
 ;%0A  

Compute lazily the string of JHVDate