Home | History | Annotate | Download | only in ast
      1 package com.github.javaparser.ast;
      2 
      3 /**
      4  * A key to a piece of user data associated with a {@link Node} at runtime.
      5  * The key contains type information that can be used to check the
      6  * type of any user data value for the key when the value is set. UserDataKey is abstract in order to
      7  * force the creation of a subtype. That subtype is used to test for identity when looking for the
      8  * user data because actual object identity would suffer from problems under serialization.
      9  * So, the correct way to declare a UserDataKey is like this:
     10  *
     11  * <pre>
     12  * <code>
     13  * public static final UserDataKey&lt;Role&gt; ROLE = new UserDataKey&lt;Role&gt;() { };
     14  * </code>
     15  * </pre>
     16  *
     17  * This code was taken from the <a href="http://wicket.apache.org/">Wicket project</a>.
     18  *
     19  * @param <T>
     20  *            The type of the object which is stored
     21  *
     22  * @see Node#getUserData(UserDataKey)
     23  */
     24 public abstract class UserDataKey<T> {
     25     @Override
     26     public int hashCode()
     27     {
     28         return getClass().hashCode();
     29     }
     30 
     31     /**
     32      * @see java.lang.Object#equals(java.lang.Object)
     33      */
     34     @Override
     35     public boolean equals(Object obj)
     36     {
     37         return obj != null && getClass().equals(obj.getClass());
     38     }
     39 }
     40