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

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

There is a newer version: 5.3.3
Show newest version
package Alachisoft.NCache.Common;

/**
 * Summary description for Class1
 */

public class FlagsByte {
    /**
     * The Field that will store our 64 flags
     */
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: private byte _DataByte;
    private byte _DataByte;

    /**
     * Contructor
     * Add all initialization here
     */
    public FlagsByte() {
        ClearField();
    }

    /**
     * Public property SET and GET to access the Field
     */
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public byte getDataByte()
    public final byte getDataByte() {
        return _DataByte;
    }

    //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public void setDataByte(byte value)
    public final void setDataByte(byte value) {
        _DataByte = value;
    }

    /**
     * ClearField clears all contents of the Field
     * Set all bits to zero using the clear flag
     */
    public final void ClearField() {
        SetField(Flag.Clear);
    }

    /**
     * FillField fills all contents of the Field
     * Set all bits to zero using the negation of clear
     */
    public final void FillField() {
        SetField(Flag.Clear);
    }

    /**
     * Setting the specified flag(s) and turning all other flags off.
     * - Bits that are set to 1 in the flag will be set to one in the Field.
     * - Bits that are set to 0 in the flag will be set to zero in the Field.
     *
     * @param flg The flag to set in Field
     */
    private void SetField(Flag flg) {
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: DataByte = (byte)flg;
        setDataByte((byte) flg.getValue());
    }

    /**
     * Setting the specified flag(s) and leaving all other flags unchanged.
     * - Bits that are set to 1 in the flag will be set to one in the Field.
     * - Bits that are set to 0 in the flag will be unchanged in the Field.
     *
     * 
     * OR truth table
     * 0 | 0 = 0
     * 1 | 0 = 1
     * 0 | 1 = 1
     * 1 | 1 = 1
     * 
     *
     * @param flg The flag to set in Field
     */
    public final void SetOn(Flag flg) {
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: DataByte |= (byte)flg;
        setDataByte((byte) (getDataByte() | (byte) flg.getValue()));
    }

    /**
     * Unsetting the specified flag(s) and leaving all other flags unchanged.
     * - Bits that are set to 1 in the flag will be set to zero in the Field.
     * - Bits that are set to 0 in the flag will be unchanged in the Field.
     *
     * 
     * AND truth table
     * 0 & 0 = 0
     * 1 & 0 = 0
     * 0 & 1 = 0
     * 1 & 1 = 1
     * 
     *
     * @param flg The flag(s) to unset in Field
     */
    public final void SetOff(Flag flg) {
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: DataByte &= (byte)~flg;
        setDataByte((byte) (getDataByte() & (byte) flg.getValue()));
    }

    /**
     * Toggling the specified flag(s) and leaving all other bits unchanged.
     * - Bits that are set to 1 in the flag will be toggled in the Field.
     * - Bits that are set to 0 in the flag will be unchanged in the Field.
     *
     * 
     * XOR truth table
     * 0 ^ 0 = 0
     * 1 ^ 0 = 1
     * 0 ^ 1 = 1
     * 1 ^ 1 = 0
     * 
     *
     * @param flg The flag to toggle in Field
     */
    public final void SetToggle(Flag flg) {
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: DataByte ^= (byte)flg;
        setDataByte((byte) (getDataByte() ^ (byte) flg.getValue()));
    }

    /**
     * AnyOn checks if any of the specified flag are set/on in the Field.
     *
     * @param flg flag(s) to check
     * @return true if flag is set in Field
     * false otherwise
     */
    public final boolean AnyOn(Flag flg) {
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: return (DataByte & (byte)flg) != 0;
        return (getDataByte() & (byte) flg.getValue()) != 0;
    }

    /**
     * AllOn checks if all the specified flags are set/on in the Field.
     *
     * @param flg flag(s) to check
     * @return true if all flags are set in Field
     * false otherwise
     */
    public final boolean AllOn(Flag flg) {
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: return (DataByte & (byte)flg) == (byte)flg;
        return (getDataByte() & (byte) flg.getValue()) == (byte) flg.getValue();
    }

    /**
     * IsEqual checks if all the specified flags are the same as in the Field.
     *
     * @param flg flag(s) to check
     * @return true if all flags identical in the Field
     * false otherwise
     */
    public final boolean IsEqual(Flag flg) {
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: return DataByte == (byte)flg;
        return getDataByte() == (byte) flg.getValue();
    }

    //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public enum Flag : byte
//C# TO JAVA CONVERTER TODO TASK: Java annotations will not correspond to .NET attributes:
    //[FlagsAttribute]
    public enum Flag { // Hexidecimal        Decimal        Binary
        Clear(0x00), // 0x...0000        0            ...00000000000000000
        TRANS(0x01), // 0x...0001        1            ...00000000000000001
        COR(0x01 << 1), // 0x...0002        2            ...00000000000000010
        TOTAL(0x01 << 1 << 1), // 0x...0004        4            ...00000000000000100
        TCP(0x01 << 1 << 1 << 1), // 0x...0008        8            ...00000000000001000
        f5(0x01 << 1 << 1 << 1 << 1), // 0x...0010        16            ...00000000000010000
        f6(0x01 << 1 << 1 << 1 << 1 << 1), // 0x...0020        32            ...00000000000100000
        f7(0x01 << 1 << 1 << 1 << 1 << 1 << 1), // 0x...0040        64            ...00000000001000000
        f8(0x01 << 1 << 1 << 1 << 1 << 1 << 1 << 1); // 0x...0080        128            ...00000000010000000

        private static java.util.HashMap mappings;
        private int intValue;

        private Flag(int value) {
            intValue = value;
            Flag.getMappings().put(value, this);
        }

        private static java.util.HashMap getMappings() {
            if (mappings == null) {
                synchronized (Flag.class) {
                    if (mappings == null) {
                        mappings = new java.util.HashMap();
                    }
                }
            }
            return mappings;
        }

        public static Flag forValue(int value) {
            return getMappings().get(value);
        }

        public int getValue() {
            return intValue;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy