Class PrivilegeBits

    • Field Detail

      • BUILT_IN

        public static final java.util.Map<java.lang.String,​PrivilegeBits> BUILT_IN
      • NEXT_AFTER_BUILT_INS

        public static final PrivilegeBits NEXT_AFTER_BUILT_INS
    • Method Detail

      • getInstance

        public static PrivilegeBits getInstance()
        Creates a mutable instance of privilege bits.
        Returns:
        a new instance of privilege bits.
      • getInstance

        @NotNull
        public static @NotNull PrivilegeBits getInstance​(@NotNull
                                                         @NotNull PrivilegeBits... base)
        Creates a mutable instance of privilege bits.
        Parameters:
        base - The base for this mutable instance.
        Returns:
        a new instance of privilege bits.
      • getInstance

        @NotNull
        public static @NotNull PrivilegeBits getInstance​(@Nullable
                                                         @Nullable PropertyState property)
        Get or create an instance of privilege bits for a specific property that stores privileges.
        Parameters:
        property - The property state storing privilege bits information.
        Returns:
        an instance of PrivilegeBits
      • getInstance

        @NotNull
        public static @NotNull PrivilegeBits getInstance​(@Nullable
                                                         @Nullable Tree tree)
        Get or create an instance of privilege bits for a privilege definition.
        Parameters:
        tree - A privilege definition tree or the privileges root.
        Returns:
        an instance of PrivilegeBits
      • calculatePermissions

        public static long calculatePermissions​(@NotNull
                                                @NotNull PrivilegeBits bits,
                                                @NotNull
                                                @NotNull PrivilegeBits parentBits,
                                                boolean isAllow)
        Calculate the granted permissions by evaluating the given privileges. Note, that only built-in privileges can be mapped to permissions. Any other privileges will be ignored.
        Parameters:
        bits - The set of privileges present at given tree.
        parentBits - The privileges present on the parent tree. These are required in order to determine permissions that include a modification of the parent tree (add_child_nodes, remove_child_nodes).
        isAllow - true if the privileges are granted; false otherwise.
        Returns:
        the resulting permissions.
      • isEmpty

        public boolean isEmpty()
        Returns true if this privilege bits includes no privileges at all.
        Returns:
        true if this privilege bits includes no privileges at all; false otherwise.
        See Also:
        Permissions.NO_PERMISSION
      • unmodifiable

        @NotNull
        public @NotNull PrivilegeBits unmodifiable()
        Returns an unmodifiable instance.
        Returns:
        an unmodifiable PrivilegeBits instance.
      • modifiable

        @NotNull
        public @NotNull PrivilegeBits modifiable()
      • includes

        public boolean includes​(@NotNull
                                @NotNull PrivilegeBits otherBits)
        Returns true if all privileges defined by the specified otherBits are present in this instance.
        Parameters:
        otherBits -
        Returns:
        true if all privileges defined by the specified otherBits are included in this instance; false otherwise.
      • isBuiltin

        public boolean isBuiltin()
        Returns:
        true if this instance represents one of the built-in privilege
        See Also:
        BUILT_IN
      • add

        @NotNull
        public @NotNull PrivilegeBits add​(@NotNull
                                          @NotNull PrivilegeBits other)
        Adds the other privilege bits to this instance.
        Parameters:
        other - The other privilege bits to be added.
        Returns:
        The updated instance.
        Throws:
        java.lang.UnsupportedOperationException - if this instance is immutable.
      • diff

        @NotNull
        public @NotNull PrivilegeBits diff​(@NotNull
                                           @NotNull PrivilegeBits other)
        Subtracts the other PrivilegeBits from the this.
        If the specified bits do not intersect with this, it isn't modified.
        If this is included in other empty privilege bits is returned.
        Parameters:
        other - The other privilege bits to be subtracted from this instance.
        Returns:
        The updated instance.
        Throws:
        java.lang.UnsupportedOperationException - if this instance is immutable.
      • addDifference

        @NotNull
        public @NotNull PrivilegeBits addDifference​(@NotNull
                                                    @NotNull PrivilegeBits a,
                                                    @NotNull
                                                    @NotNull PrivilegeBits b)
        Subtracts the b from a and adds the result (diff) to this instance.
        Parameters:
        a - An instance of privilege bits.
        b - An instance of privilege bits.
        Returns:
        The updated instance.
        Throws:
        java.lang.UnsupportedOperationException - if this instance is immutable.
      • retain

        @NotNull
        public @NotNull PrivilegeBits retain​(@NotNull
                                             @NotNull PrivilegeBits other)
        Retains the elements in this PrivilegeBits that are contained in the specified other PrivilegeBits.
        Parameters:
        other - Other privilege bits.
        Returns:
        This modifiable instance of privilege bits modified such it contains only privileges that were also contained in the other instance.
      • asPropertyState

        @NotNull
        public @NotNull PropertyState asPropertyState​(@NotNull
                                                      @NotNull java.lang.String name)
      • nextBits

        @NotNull
        public @NotNull PrivilegeBits nextBits()
        Method to calculate the next privilege bits associated with this instance.
        Returns:
        an new instance of PrivilegeBits
      • writeTo

        public void writeTo​(@NotNull
                            @NotNull Tree tree)
        Write this instance as property to the specified tree.
        Parameters:
        tree - The target tree.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object