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

Alachisoft.NCache.Common.BitSet Maven / Gradle / Ivy

package Alachisoft.NCache.Common;

import com.alachisoft.ncache.serialization.core.io.ICompactSerializable;
import com.alachisoft.ncache.serialization.core.io.NCacheObjectInput;
import com.alachisoft.ncache.serialization.core.io.NCacheObjectOutput;

import java.io.IOException;
import java.io.Serializable;

/**
 * A class that encapsulates a bit set.
 */
public class BitSet implements Cloneable, Serializable, ICompactSerializable {

    private byte _bitset;

    public BitSet() {
    }

    public BitSet(byte bitset) {
        this._bitset = bitset;
    }

    public byte getData() {
        return _bitset;
    }

    public void setData(byte bitset) {
        _bitset = bitset;
    }

    ///  Bit set specific functions. 
    public boolean IsAnyBitSet(byte bit) {
        return ((_bitset & bit) != 0);
    }

    public boolean IsBitSet(byte bit) {
        return ((_bitset & bit) == bit);
    }

    public void SetBit(byte bit) {
        _bitset |= bit;
    }

    public void UnsetBit(byte bit) {
        _bitset &= (~bit & 0xff);
    }

    public void Set(byte bitsToSet, byte bitsToUnset) {
        SetBit(bitsToSet);
        UnsetBit(bitsToUnset);
    }

    public Object Clone() {
        BitSet other = new BitSet();
        other._bitset = _bitset;
        return other;
    }

    public void Dispose() {
    }

    //region ICompactSerializable Implementation
    public void deserialize(NCacheObjectInput reader) throws IOException
    {
        _bitset = reader.readByte();
    }

    public void serialize(NCacheObjectOutput writer) throws IOException
    {
        writer.write(_bitset);
    }
    //endregion
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy