com.alachisoft.ncache.client.internal.util.ConversionUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ncache-professional-client Show documentation
Show all versions of ncache-professional-client Show documentation
NCache Professional client for java.
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);
}
}