Class PermissionSet
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractSet<Permission>
-
- discord4j.rest.util.PermissionSet
-
- All Implemented Interfaces:
Iterable<Permission>,Collection<Permission>,Set<Permission>
public final class PermissionSet extends AbstractSet<Permission>
An immutable, specializedSet<Permission>.This is a value-based class; use of identity-sensitive operations (including reference equality (
==), identity hash code, or synchronization) on instances ofPermissionSetmay have unpredictable results and should be avoided. Theequalsmethod should be used for comparisons.- See Also:
- Discord Permissions
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static PermissionSetall()Returns aPermissionSetcontaining all permissions.PermissionSetand(PermissionSet other)Performs a logical AND of this permission set with the other permission set.PermissionSetandNot(PermissionSet other)Performs a logical AND NOT of this permission set with the other permission set.EnumSet<Permission>asEnumSet()Gets thisPermissionSetas anEnumSet.booleancontains(Object o)booleanequals(Object o)longgetRawValue()Gets the raw value for thisPermissionSet.inthashCode()Iterator<Permission>iterator()static PermissionSetnone()Returns aPermissionSetcontaining no permissions.PermissionSetnot()Performs a logical NOT of this permission set.static PermissionSetof(long rawValue)Returns aPermissionSetcontaining all the permissions represented by the raw value.static PermissionSetof(Permission... permissions)Returns aPermissionSetcontaining all the supplied permissions.static PermissionSetof(String rawValue)Returns aPermissionSetcontaining all the permissions represented by the raw value.PermissionSetor(PermissionSet other)Performs a logical OR of this permission set with the other permission set.intsize()PermissionSetsubtract(PermissionSet other)Deprecated.UseandNot(PermissionSet)instead.StringtoString()PermissionSetxor(PermissionSet other)Performs a logical XOR of this permission set with the other permission set.-
Methods inherited from class java.util.AbstractSet
removeAll
-
Methods inherited from class java.util.AbstractCollection
add, addAll, clear, containsAll, isEmpty, remove, retainAll, toArray, toArray
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
-
-
-
Method Detail
-
all
public static PermissionSet all()
Returns aPermissionSetcontaining all permissions.- Returns:
- A
PermissionSetcontaining all permissions.
-
none
public static PermissionSet none()
Returns aPermissionSetcontaining no permissions.- Returns:
- A
PermissionSetcontaining no permissions.
-
of
public static PermissionSet of(long rawValue)
Returns aPermissionSetcontaining all the permissions represented by the raw value.- Parameters:
rawValue- A bit-wise OR evaluation of multiple values returned byPermission.getValue().- Returns:
- A
PermissionSetcontaining all the permissions represented by the raw value.
-
of
public static PermissionSet of(String rawValue)
Returns aPermissionSetcontaining all the permissions represented by the raw value.- Parameters:
rawValue- A bit-wise OR evaluation of multiple values returned byPermission.getValue(), as a string.- Returns:
- A
PermissionSetcontaining all the permissions represented by the raw value.
-
of
public static PermissionSet of(Permission... permissions)
Returns aPermissionSetcontaining all the supplied permissions.- Parameters:
permissions- The permissions to add to thePermissionSet.- Returns:
- A
PermissionSetcontaining all the supplied permissions.
-
and
public PermissionSet and(PermissionSet other)
Performs a logical AND of this permission set with the other permission set.The resultant set is the intersection of this set and the other set. A permission is contained if and only if it was contained in both this set and the other set. This is analogous to
Set.retainAll(java.util.Collection).PermissionSet set0 = PermissionSet.of(KICK_MEMBERS, BAN_MEMBERS); PermissionSet set1 = PermissionSet.of(KICK_MEMBERS); set0.and(set1) = PermissionSet.of(KICK_MEMBERS)- Parameters:
other- The other permission set.- Returns:
- The intersection of this set with the other set.
-
or
public PermissionSet or(PermissionSet other)
Performs a logical OR of this permission set with the other permission set.The resultant set is the union of this set and the other set. A permission is contained if and only if it was contained in either this set or the other set. This is analogous to
Set.addAll(java.util.Collection).PermissionSet set0 = PermissionSet.of(KICK_MEMBERS); PermissionSet set1 = PermissionSet.of(BAN_MEMBERS); set0.or(set1) = PermissionSet.of(KICK_MEMBERS, BAN_MEMBERS)- Parameters:
other- The other permission set.- Returns:
- The union of this set with the other set.
-
xor
public PermissionSet xor(PermissionSet other)
Performs a logical XOR of this permission set with the other permission set.The resultant set is the symmetric difference of this set and the other set. A permission is contained if and only if it was contained in only this set or contained in only the other set.
PermissionSet set0 = PermissionSet.of(KICK_MEMBERS, BAN_MEMBERS, ATTACH_FILES); PermissionSet set1 = PermissionSet.of(ATTACH_FILES, CONNECT); set0.xor(set1) = PermissionSet.of(KICK_MEMBERS, BAN_MEMBERS, CONNECT)- Parameters:
other- The other permission set.- Returns:
- The symmetric difference of this set with the other set.
-
andNot
public PermissionSet andNot(PermissionSet other)
Performs a logical AND NOT of this permission set with the other permission set.The resultant set is the relative complement of this set and the other set. A permission is contained if and only if it was contained in this set and not contained in the other set. This is analogous to
Set.removeAll(java.util.Collection).PermissionSet set0 = PermissionSet.of(KICK_MEMBERS, BAN_MEMBERS, ATTACH_FILES); PermissionSet set1 = PermissionSet.of(BAN_MEMBERS, ATTACH_FILES, CONNECT); set0.andNot(set1) = PermissionSet.of(KICK_MEMBERS)- Parameters:
other- The other permission set.- Returns:
- The relative complement of this set with the other set.
-
subtract
@Deprecated public PermissionSet subtract(PermissionSet other)
Deprecated.UseandNot(PermissionSet)instead.Performs a logical AND NOT of this permission set with the other permission set.The resultant set is the relative complement of this set and the other set. A permission is contained if and only if it was contained in this set and not contained in the other set.
PermissionSet set0 = PermissionSet.of(KICK_MEMBERS, BAN_MEMBERS, ATTACH_FILES); PermissionSet set1 = PermissionSet.of(BAN_MEMBERS, ATTACH_FILES, CONNECT); set0.subtract(set1) = PermissionSet.of(KICK_MEMBERS)- Parameters:
other- The other permission set.- Returns:
- The relative complement of this set with the other set.
-
not
public PermissionSet not()
Performs a logical NOT of this permission set.The resultant set is the complement of this set. A permission is contained if and only if it was not contained in this set.
PermissionSet set = PermissionSet.none(); set.not() = PermissionSet.all()- Returns:
- The complement of this set.
-
asEnumSet
public EnumSet<Permission> asEnumSet()
Gets thisPermissionSetas anEnumSet.- Returns:
- This
PermissionSetas anEnumSet.
-
getRawValue
public long getRawValue()
Gets the raw value for thisPermissionSet.- Returns:
- The raw value for this
PermissionSet. - See Also:
PermissionSet
-
contains
public boolean contains(Object o)
- Specified by:
containsin interfaceCollection<Permission>- Specified by:
containsin interfaceSet<Permission>- Overrides:
containsin classAbstractCollection<Permission>
-
iterator
public Iterator<Permission> iterator()
- Specified by:
iteratorin interfaceCollection<Permission>- Specified by:
iteratorin interfaceIterable<Permission>- Specified by:
iteratorin interfaceSet<Permission>- Specified by:
iteratorin classAbstractCollection<Permission>
-
size
public int size()
- Specified by:
sizein interfaceCollection<Permission>- Specified by:
sizein interfaceSet<Permission>- Specified by:
sizein classAbstractCollection<Permission>
-
equals
public boolean equals(@Nullable Object o)
- Specified by:
equalsin interfaceCollection<Permission>- Specified by:
equalsin interfaceSet<Permission>- Overrides:
equalsin classAbstractSet<Permission>
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfaceCollection<Permission>- Specified by:
hashCodein interfaceSet<Permission>- Overrides:
hashCodein classAbstractSet<Permission>
-
toString
public String toString()
- Overrides:
toStringin classAbstractCollection<Permission>
-
-