org.pfsw.reflect
Class Modifiers

java.lang.Object
  extended by org.pfsw.reflect.Modifiers

public class Modifiers
extends java.lang.Object

This class provides methods to conveniently set/unset modifier bits without having to fiddle around with bit logic.


Field Summary
static java.lang.String VIS_DEFAULT
          String constant for "".
static java.lang.String VIS_PRIVATE
          String constant for "private".
static java.lang.String VIS_PROTECTED
          String constant for "protected".
static java.lang.String VIS_PUBLIC
          String constant for "public".
 
Constructor Summary
Modifiers()
          Initialize the new instance with default value 0.
Modifiers(int initialValue)
          Initialize the new instance with given value.
 
Method Summary
static Modifiers create()
          Returns a new unintialized instance.
static Modifiers create(java.lang.reflect.Field field)
          Returns a new instance initialized with the modifier bits of the given field.
static Modifiers create(int initialValue)
          Returns a new instance initialized with the given bit settings.
 boolean equals(java.lang.Object object)
          Indicates whether some other object is "equal to" this one.
 int getBits()
          Return the bits as they are currently set.
 int hashCode()
          Returns a hash code value for the object.
 boolean isAbstract()
          Return true if the modifiers includes the abstract modifier, false otherwise.
 boolean isDefaultVisibility()
          Return true if the modifier bits does not include any of the visibility modifiers public, protected private, false otherwise.
 boolean isFinal()
          Return true if the modifiers includes the final modifier, false otherwise.
 boolean isInterface()
          Return true if the modifiers includes the interface modifier, false otherwise.
 boolean isNative()
          Return true if the modifiers includes the native modifier, false otherwise.
 boolean isPrivate()
          Return true if the modifiers includes the private modifier, false otherwise.
 boolean isProtected()
          Return true if the modifiers includes the protected modifier, false otherwise.
 boolean isPublic()
          Return true if the modifiers includes the public modifier, false otherwise.
 boolean isStatic()
          Return true if the modifiers includes the static modifier, false otherwise.
 boolean isStrict()
          Return true if the modifiers includes the strict modifier, false otherwise.
 boolean isSynchronized()
          Return true if the modifiers includes the synchronized modifier, false otherwise.
 boolean isTransient()
          Return true if the modifiers includes the transient modifier, false otherwise.
 boolean isVolatile()
          Return true if the modifiers includes the volatile modifier, false otherwise.
static Modifiers of(java.lang.Class<?> type)
          Returns a new instance initialized with the modifier bits of the given class.
static Modifiers of(java.lang.reflect.Member member)
          Returns a new instance initialized with the modifier bits of the given member (i.e.
 Modifiers reset()
          Resets the modifier to 0.
 Modifiers setAbstract()
          Sets the ABSTRACT bit.
protected  void setBits(int newValue)
           
 Modifiers setDefaultVisibility()
          Sets the visibility to default that means unset PUBLIC, PROTECTED, PRIVATE bits.
 Modifiers setFinal()
          Sets the FINAL bit.
 Modifiers setInterface()
          Sets the INTERFACE bit.
protected  void setModifier(int mod)
          Sets the bits in the underlying int that are specified by mod.
 Modifiers setNative()
          Sets the NATIVE bit.
 Modifiers setPrivate()
          Sets the PRIVATE bit.
 Modifiers setProtected()
          Sets the PROTECTED bit.
 Modifiers setPublic()
          Sets the PUBLIC bit.
 Modifiers setStatic()
          Sets the STATIC bit.
 Modifiers setStrict()
          Sets the STRICT bit.
 Modifiers setSynchronized()
          Sets the SYNCHRONIZED bit.
 Modifiers setTransient()
          Sets the TRANSIENT bit.
 Modifiers setVisibility(java.lang.String visibility)
          Sets the visibility from the given string.
 Modifiers setVolatile()
          Sets the VOLATILE bit.
 java.lang.String toString()
          Return a string describing the access modifier flags in the specified modifier.
 Modifiers unsetAbstract()
          Unsets the ABSTRACT bit.
 Modifiers unsetFinal()
          Unsets the FINAL bit.
 Modifiers unsetInterface()
          Unsets the INTERFACE bit.
protected  void unsetModifier(int mod)
          Unsets the bits in the underlying int that are specified by mod.
 Modifiers unsetNative()
          Unsets the NATIVE bit.
 Modifiers unsetPrivate()
          Unsets the PRIVATE bit.
 Modifiers unsetProtected()
          Unsets the PROTECTED bit.
 Modifiers unsetPublic()
          Unsets the PUBLIC bit.
 Modifiers unsetStatic()
          Unsets the STATIC bit.
 Modifiers unsetStrict()
          Unsets the STRICT bit.
 Modifiers unsetSynchronized()
          Unsets the SYNCHRONIZED bit.
 Modifiers unsetTransient()
          Unsets the TRANSIENT bit.
 Modifiers unsetVolatile()
          Unsets the VOLATILE bit.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

VIS_PUBLIC

public static final java.lang.String VIS_PUBLIC
String constant for "public".

See Also:
Constant Field Values

VIS_PROTECTED

public static final java.lang.String VIS_PROTECTED
String constant for "protected".

See Also:
Constant Field Values

VIS_PRIVATE

public static final java.lang.String VIS_PRIVATE
String constant for "private".

See Also:
Constant Field Values

VIS_DEFAULT

public static final java.lang.String VIS_DEFAULT
String constant for "".

See Also:
Constant Field Values
Constructor Detail

Modifiers

public Modifiers()
Initialize the new instance with default value 0.


Modifiers

public Modifiers(int initialValue)
Initialize the new instance with given value.

Method Detail

create

public static Modifiers create()
Returns a new unintialized instance.


create

public static Modifiers create(int initialValue)
Returns a new instance initialized with the given bit settings.


create

public static Modifiers create(java.lang.reflect.Field field)
Returns a new instance initialized with the modifier bits of the given field.


of

public static Modifiers of(java.lang.reflect.Member member)
Returns a new instance initialized with the modifier bits of the given member (i.e. Field, Method, Constructor).


of

public static Modifiers of(java.lang.Class<?> type)
Returns a new instance initialized with the modifier bits of the given class.


getBits

public int getBits()
Return the bits as they are currently set.


reset

public Modifiers reset()
Resets the modifier to 0.


isAbstract

public boolean isAbstract()
Return true if the modifiers includes the abstract modifier, false otherwise.


isFinal

public boolean isFinal()
Return true if the modifiers includes the final modifier, false otherwise.


isInterface

public boolean isInterface()
Return true if the modifiers includes the interface modifier, false otherwise.


isNative

public boolean isNative()
Return true if the modifiers includes the native modifier, false otherwise.


isPrivate

public boolean isPrivate()
Return true if the modifiers includes the private modifier, false otherwise.


isProtected

public boolean isProtected()
Return true if the modifiers includes the protected modifier, false otherwise.


isPublic

public boolean isPublic()
Return true if the modifiers includes the public modifier, false otherwise.


isStatic

public boolean isStatic()
Return true if the modifiers includes the static modifier, false otherwise.


isStrict

public boolean isStrict()
Return true if the modifiers includes the strict modifier, false otherwise.


isSynchronized

public boolean isSynchronized()
Return true if the modifiers includes the synchronized modifier, false otherwise.


isTransient

public boolean isTransient()
Return true if the modifiers includes the transient modifier, false otherwise.


isVolatile

public boolean isVolatile()
Return true if the modifiers includes the volatile modifier, false otherwise.


isDefaultVisibility

public boolean isDefaultVisibility()
Return true if the modifier bits does not include any of the visibility modifiers public, protected private, false otherwise.


toString

public java.lang.String toString()
Return a string describing the access modifier flags in the specified modifier.

Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object object)
Indicates whether some other object is "equal to" this one.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Returns a hash code value for the object.

Overrides:
hashCode in class java.lang.Object

setAbstract

public Modifiers setAbstract()
Sets the ABSTRACT bit.

Returns:
this object.

setFinal

public Modifiers setFinal()
Sets the FINAL bit.

Returns:
this object.

setInterface

public Modifiers setInterface()
Sets the INTERFACE bit.

Returns:
this object.

setNative

public Modifiers setNative()
Sets the NATIVE bit.

Returns:
this object.

setPrivate

public Modifiers setPrivate()
Sets the PRIVATE bit. This automatically unsets the PUBLIC and PROTECTED bits.

Returns:
this object.

setProtected

public Modifiers setProtected()
Sets the PROTECTED bit. This automatically unsets the PUBLIC and PRIVATE bits.

Returns:
this object.

setPublic

public Modifiers setPublic()
Sets the PUBLIC bit. This automatically unsets the PROTECTED and PRIVATE bits.

Returns:
this object.

setStatic

public Modifiers setStatic()
Sets the STATIC bit.

Returns:
this object.

setStrict

public Modifiers setStrict()
Sets the STRICT bit.

Returns:
this object.

setSynchronized

public Modifiers setSynchronized()
Sets the SYNCHRONIZED bit.

Returns:
this object.

setTransient

public Modifiers setTransient()
Sets the TRANSIENT bit.

Returns:
this object.

setVolatile

public Modifiers setVolatile()
Sets the VOLATILE bit.

Returns:
this object.

setDefaultVisibility

public Modifiers setDefaultVisibility()
Sets the visibility to default that means unset PUBLIC, PROTECTED, PRIVATE bits.

Returns:
this object.

setVisibility

public Modifiers setVisibility(java.lang.String visibility)
Sets the visibility from the given string. If the given string is not one of "public", "protected", "private" the the default visibility is set.

Parameters:
visibility - One of the visibility strings
Returns:
this object.

unsetAbstract

public Modifiers unsetAbstract()
Unsets the ABSTRACT bit.

Returns:
this object.

unsetFinal

public Modifiers unsetFinal()
Unsets the FINAL bit.

Returns:
this object.

unsetInterface

public Modifiers unsetInterface()
Unsets the INTERFACE bit.

Returns:
this object.

unsetNative

public Modifiers unsetNative()
Unsets the NATIVE bit.

Returns:
this object.

unsetPrivate

public Modifiers unsetPrivate()
Unsets the PRIVATE bit.

Returns:
this object.

unsetProtected

public Modifiers unsetProtected()
Unsets the PROTECTED bit.

Returns:
this object.

unsetPublic

public Modifiers unsetPublic()
Unsets the PUBLIC bit.

Returns:
this object.

unsetStatic

public Modifiers unsetStatic()
Unsets the STATIC bit.

Returns:
this object.

unsetStrict

public Modifiers unsetStrict()
Unsets the STRICT bit.

Returns:
this object.

unsetSynchronized

public Modifiers unsetSynchronized()
Unsets the SYNCHRONIZED bit.

Returns:
this object.

unsetTransient

public Modifiers unsetTransient()
Unsets the TRANSIENT bit.

Returns:
this object.

unsetVolatile

public Modifiers unsetVolatile()
Unsets the VOLATILE bit.

Returns:
this object.

setModifier

protected void setModifier(int mod)
Sets the bits in the underlying int that are specified by mod.


unsetModifier

protected void unsetModifier(int mod)
Unsets the bits in the underlying int that are specified by mod.


setBits

protected void setBits(int newValue)