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

com.alachisoft.ncache.client.internal.util.ConversionUtil Maven / Gradle / Ivy

There is a newer version: 5.3.0
Show newest version
package com.alachisoft.ncache.client.internal.util;

import com.alachisoft.ncache.client.EventUtil;
import com.alachisoft.ncache.runtime.caching.expiration.Expiration;
import com.alachisoft.ncache.client.internal.caching.EventTypeInternal;
import com.alachisoft.ncache.runtime.caching.expiration.ExpirationConstants;
import com.alachisoft.ncache.runtime.caching.*;
import com.alachisoft.ncache.runtime.util.NCDateTime;
import com.alachisoft.ncache.runtime.util.TimeSpan;
import com.google.common.collect.Iterables;

import java.util.Date;
import java.util.EnumSet;
import java.util.List;

public class ConversionUtil {



    public static java.util.Date getAbsoluteExpiration(Expiration _expiration) {
        return _expiration != null ? getExpirationAbsoluteInternal(_expiration) : NCDateTime.MaxValue;
    }

    public static TimeSpan getSlidingExpiration(Expiration _expiration) {
        return _expiration != null ? getExpirationSlidingInternal(_expiration) : TimeSpan.Zero;
    }


    public static java.util.Date getExpirationAbsoluteInternal(Expiration _expiration) {
        switch (_expiration.getExpirationType()) {
            case DefaultAbsolute:
                return ExpirationConstants.AbsoluteDefaultExpiration;

            case DefaultAbsoluteLonger:
                return ExpirationConstants.AbsoluteDefaultLongerExpiration;

            case Absolute:

                return new NCDateTime(new NCDateTime(new Date()).getTicks()+_expiration.getExpireAfter().getTotalTicks()).getDate();

            default:
                return ExpirationConstants.AbsoluteNoneExpiration;
        }
    }

    public static TimeSpan getExpirationSlidingInternal(Expiration _expiration) {
        switch (_expiration.getExpirationType()) {
            case DefaultSliding:
                return ExpirationConstants.SlidingDefaultExpiration;

            case DefaultSlidingLonger:
                return ExpirationConstants.SlidingDefaultLongerExpiration;

            case Sliding:
                return _expiration.getExpireAfter();

            case None:
                return TimeSpan.Zero;

            default:
                return ExpirationConstants.SlidingNoneExpiration;
        }
    }

    public  static  T[] toArray(Iterable values, Class cls) {
        if(values==null)
            return null;
        return Iterables.toArray(values, cls);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy