Class Accessor<T>

  • Type Parameters:
    T - Variable type

    public class Accessor<T>
    extends java.lang.Object
    Wrapper class for accessing a private variable
    • Constructor Summary

      Constructors 
      Constructor Description
      Accessor​(java.lang.String fieldName, java.lang.Class<?> ownerClass, java.lang.Class<T> classOfT)
      Create an Accessor for a static field
      Accessor​(java.lang.String fieldName, java.lang.Object owner, java.lang.Class<T> classOfT)
      Create an Accessor
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      T get()
      Get the variable value
      T getOrNull()
      Get the variable value, or NULL on error
      void set​(T value)
      Set the variable value
      boolean setOrFailQuietly​(T value)
      Set the variable value
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Accessor

        public Accessor​(java.lang.String fieldName,
                        java.lang.Object owner,
                        java.lang.Class<T> classOfT)
                 throws java.lang.NoSuchFieldException,
                        java.lang.SecurityException
        Create an Accessor
        Parameters:
        fieldName - Name of the private field
        owner - Object to fetch from
        classOfT - The class of generic type T
        Throws:
        java.lang.NoSuchFieldException
        java.lang.SecurityException
      • Accessor

        public Accessor​(java.lang.String fieldName,
                        java.lang.Class<?> ownerClass,
                        java.lang.Class<T> classOfT)
                 throws java.lang.NoSuchFieldException,
                        java.lang.SecurityException
        Create an Accessor for a static field
        Parameters:
        fieldName - Name of the private static field
        ownerClass - Class that wraps the static field
        classOfT - The class of generic type T
        Throws:
        java.lang.NoSuchFieldException
        java.lang.SecurityException
    • Method Detail

      • set

        public void set​(T value)
                 throws java.lang.IllegalArgumentException,
                        java.lang.IllegalAccessException
        Set the variable value
        Parameters:
        value - Value
        Throws:
        java.lang.IllegalArgumentException
        java.lang.IllegalAccessException
      • setOrFailQuietly

        public boolean setOrFailQuietly​(T value)
        Set the variable value
        Parameters:
        value - Value
        Returns:
        True if successful
      • get

        public T get()
              throws java.lang.IllegalArgumentException,
                     java.lang.IllegalAccessException
        Get the variable value
        Returns:
        Value
        Throws:
        java.lang.IllegalArgumentException
        java.lang.IllegalAccessException
      • getOrNull

        public T getOrNull()
        Get the variable value, or NULL on error
        Returns:
        Value or NULL