Alachisoft.NCache.Common.ProductVersion Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nc-common Show documentation
Show all versions of nc-common Show documentation
Internal package of Alachisoft.
package Alachisoft.NCache.Common;
// Copyright (c) 2020 Alachisoft
import com.alachisoft.ncache.serialization.core.io.InternalCompactSerializable;
import com.alachisoft.ncache.serialization.standard.io.CompactReader;
import com.alachisoft.ncache.serialization.standard.io.CompactWriter;
import java.io.IOException;
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License
public class ProductVersion implements java.lang.Comparable, InternalCompactSerializable {
private static volatile ProductVersion _productInfo;
private static Object _syncRoot = new Object(); // this object is to serve as locking instance to avoid deadlocks
private byte _majorVersion1 = 0;
private byte _majorVersion2 = 0;
private byte _minorVersion1 = 0;
private byte _minorVersion2 = 0;
private String _productName = "";
private int _editionID = -1;
private byte[] _additionalData;
public ProductVersion() {
}
public static ProductVersion getProductInfo() {
if (_productInfo == null) {
synchronized (_syncRoot) {
if (_productInfo == null) {
_productInfo = new ProductVersion();
_productInfo._editionID = 32;
_productInfo._majorVersion1 = 4;
_productInfo._majorVersion2 = 3;
_productInfo._minorVersion1 = 0;
_productInfo._minorVersion2 = 0;
_productInfo._productName = "NCACHE";
_productInfo._additionalData = new byte[0];
}
}
}
return _productInfo;
}
public final String getProductName() {
return _productName;
}
private void setProductName(String value) {
_productName = value;
}
public final int getEditionID() {
return _editionID;
}
private void setEditionID(int value) {
_editionID = value;
}
public final byte[] getAdditionalData() {
return _additionalData;
}
private void setAdditionalData(byte[] value) {
_additionalData = value;
}
public final byte getMinorVersion2() {
return _minorVersion2;
}
private void setMinorVersion2(byte value) {
_minorVersion2 = value;
}
public final byte getMinorVersion1() {
return _minorVersion1;
}
private void setMinorVersion1(byte value) {
_minorVersion1 = value;
}
public final byte getMajorVersion2() {
return _majorVersion2;
}
private void setMajorVersion2(byte value) {
_majorVersion2 = value;
}
public final byte getMajorVersion1() {
return _majorVersion1;
}
private void setMajorVersion1(byte value) {
_majorVersion1 = value;
}
public final boolean IsValidVersion(int editionID) {
if (this.getEditionID() == editionID) {
return true;
} else {
return false;
}
}
public final void Deserialize(CompactReader reader) throws IOException, ClassNotFoundException {
_majorVersion1 = reader.ReadByte();
_majorVersion2 = reader.ReadByte();
_minorVersion1 = reader.ReadByte();
_minorVersion2 = reader.ReadByte();
_productName = (String) reader.ReadObject();
_editionID = reader.ReadInt32();
int temp = reader.ReadInt32();
_additionalData = reader.ReadBytes(temp);
}
public final void Serialize(CompactWriter writer) throws IOException {
writer.Write(_majorVersion1);
writer.Write(_majorVersion2);
writer.Write(_minorVersion1);
writer.Write(_minorVersion2);
writer.WriteObject(_productName);
writer.Write(_editionID);
writer.Write(_additionalData.length); // to know the lengt5h of the additional data to be followed; used when deserializing
writer.Write(_additionalData);
}
public final int compareTo(Object obj) {
int result = -1;
if (obj != null && obj instanceof ProductVersion) {
ProductVersion other = (ProductVersion) obj;
if (_editionID == other.getEditionID()) {
if (_majorVersion1 == other.getMajorVersion1()) {
if (_majorVersion2 == other.getMajorVersion2()) {
if (_minorVersion1 == other.getMinorVersion1()) {
if (_minorVersion2 == other._minorVersion2) {
result = 0;
} else if (_minorVersion2 < other.getMinorVersion2()) {
result = -1;
} else {
result = 1;
}
} else if (_minorVersion1 < other.getMinorVersion1()) {
result = -1;
} else {
result = 1;
}
} else if (_majorVersion2 < other.getMajorVersion2()) {
result = -1;
} else {
result = 1;
}
} else if (_majorVersion1 < other.getMajorVersion1()) {
result = -1;
} else {
result = 1;
}
} else {
result = -1;
}
}
return result;
}
}