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

com.alachisoft.ncache.client.CacheItemVersion Maven / Gradle / Ivy

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

/**
 * Represents the version of each cache item. An instance of this class is used
 * in the optimistic concurrency model to ensure the data integrity.
 */
public class CacheItemVersion implements Comparable {


    private long _version;

    public CacheItemVersion() {
        _version = 0;
    }

    public CacheItemVersion(long version) {
        _version = version;
    }

//    /**
//     *
//     * @param version
//     * @deprecated to get GacheItemVersion, use the Cache.getCacheItem("key") command and extract the version information from it
//     */
//     public CacheItemVersion(long version)
//   {
//        this._version = version;
//    }

    /**
     * Get item version
     *
     * @return Item's version
     */
    public long getVersion() {
        return this._version;
    }

    /**
     * Set item version
     *
     * @param version Item's version
     */
    public void setVersion(long version) {
        this._version = version;
    }

    /**
     * The string representation of this class.
     *
     * @return a string representation of the object.
     */
    @Override
    public String toString() {
        return Long.toString(this._version);
    }

    /**
     * Compare CacheItemVersion with current instance of item version
     *
     * @param itemVersion item version to be compared
     * @return 0 if two instance are equal. An integer greater then 0 if
     * this instance is greater. An integer less than 0 if this instance is smaller
     */
    public int compareTo(CacheItemVersion itemVersion) {

        if (itemVersion == null) {
            return -1;
        }
        long version = itemVersion._version;
        if (version == this._version) {
            return 0;
        }
        if (version < this._version) {
            return 1;
        }
        if (version > this._version) {
            return -1;
        }

        return -1;
    }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy