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

de.uni_hildesheim.sse.monitoring.runtime.boot.Flags Maven / Gradle / Ivy

package de.uni_hildesheim.sse.monitoring.runtime.boot;

/**
 * Some operations for working with bit flags.
 * 
 * @author Holger Eichelberger
 * @since 1.00
 * @version 1.00
 */
public class Flags {

    /**
     * Prevents this class from being instantiated from outside.
     * 
     * @since 1.00
     */
    private Flags() {
    }

    /**
     * Returns if the given mask is set in flags.
     * 
     * @param flags the current flags
     * @param mask the mask to check
     * @return true if mask is set in 
     *   flags, false else
     * 
     * @since 1.00
     */
    public static final boolean isSet(int flags, int mask) {
        return ((flags & mask) == mask);
    }

    /**
     * Turns the given mask on in flags.
     * 
     * @param flags the current flags
     * @param mask the mask to set
     * @return the new flags value
     * 
     * @since 1.00
     */
    public static final int set(int flags, int mask) {
        return flags | mask;
    }

    /**
     * Turns the given mask off in flags.
     * 
     * @param flags the current flags
     * @param mask the mask to clear
     * @return the new flags value
     * 
     * @since 1.00
     */
    public static final int unset(int flags, int mask) {
        return flags & ~mask;
    }

    /**
     * Turns the given mask on or off in flags.
     * 
     * @param flags the current flags
     * @param mask the mask to clear
     * @param set if true call {@link #set(int, int)} 
     *     else {@link #unset(int, int)}.
     * @return the new flags value
     * 
     * @since 1.00
     */
    public static final int change(int flags, int mask, boolean set) {
        int result;
        if (set) {
            result = set(flags, mask);
        } else {
            result = unset(flags, mask);
        }
        return result;
    }

}

    




© 2015 - 2025 Weber Informatics LLC | Privacy Policy