Class CompositePrincipal

    • Constructor Detail

      • CompositePrincipal

        public CompositePrincipal​(Collection<Principal> principals)
        Construct a new instance.
        Parameters:
        principals - the collection of principals to use (must not be null)
      • CompositePrincipal

        public CompositePrincipal​(Principal... principals)
        Construct a new instance.
        Parameters:
        principals - the principals to use (must not be null)
    • Method Detail

      • getName

        public String getName()
        Get the principal name.
        Specified by:
        getName in interface Principal
        Returns:
        the principal name, which is a string containing all of the nested principals
      • contains

        public boolean contains​(Principal principal)
        Determine whether this composite principal contains the given nested principal.
        Parameters:
        principal - the nested principal (must not be null)
        Returns:
        true if this principal contains the nested principal, false otherwise
      • contains

        public boolean contains​(Class<? extends Principal> type)
        Determine whether this composite principal contains the a nested principal of the given type class.
        Parameters:
        type - the nested principal type class (must not be null)
        Returns:
        true if this principal contains a nested principal of the given type, false otherwise
      • size

        public int size()
        Get the number of nested principals.
        Returns:
        the number of nested principals
      • get

        public Principal get​(int idx)
        Get the principal at the given index.
        Parameters:
        idx - the index
        Returns:
        the principal at the given index (not null)
        Throws:
        IndexOutOfBoundsException - if the given index is less than zero or greater than or equal to size()
      • get

        public <P extends Principal> P get​(int idx,
                                           Class<P> type)
        Get the principal at the given index, if it is of the given type.
        Type Parameters:
        P - the principal type
        Parameters:
        idx - the index
        type - the principal type class (must not be null)
        Returns:
        the principal at the given index or null if that principal is not of the given type
        Throws:
        IndexOutOfBoundsException - if the given index is less than zero or greater than or equal to size()
      • get

        public <P extends Principal> P get​(Class<P> type)
        Get the first principal with the given type, if any.
        Type Parameters:
        P - the principal type
        Parameters:
        type - the principal type class (must not be null)
        Returns:
        the first principal with the given type, or null if none was found
        Throws:
        IndexOutOfBoundsException - if the given index is less than zero or greater than or equal to size()
      • equals

        public boolean equals​(Object obj)
        Determine whether this principal is equal to the given object.
        Specified by:
        equals in interface Principal
        Overrides:
        equals in class Object
        Parameters:
        obj - the object
        Returns:
        true if they are equal, false otherwise
      • equals

        public boolean equals​(CompositePrincipal obj)
        Determine whether this principal is equal to the given object.
        Parameters:
        obj - the object
        Returns:
        true if they are equal, false otherwise
      • hashCode

        public int hashCode()
        Get the hash code of this principal.
        Specified by:
        hashCode in interface Principal
        Overrides:
        hashCode in class Object
        Returns:
        the hash code of this principal
      • toString

        public String toString()
        Get this principal as a string.
        Specified by:
        toString in interface Principal
        Overrides:
        toString in class Object
        Returns:
        this principal as a string (not null)