1 | /* |
---|---|
2 | * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. |
3 | * Copyright (C) 2011, 2013-2020 The JavaParser Team. |
4 | * |
5 | * This file is part of JavaParser. |
6 | * |
7 | * JavaParser can be used either under the terms of |
8 | * a) the GNU Lesser General Public License as published by |
9 | * the Free Software Foundation, either version 3 of the License, or |
10 | * (at your option) any later version. |
11 | * b) the terms of the Apache License |
12 | * |
13 | * You should have received a copy of both licenses in LICENCE.LGPL and |
14 | * LICENCE.APACHE. Please refer to those files for details. |
15 | * |
16 | * JavaParser is distributed in the hope that it will be useful, |
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19 | * GNU Lesser General Public License for more details. |
20 | */ |
21 | |
22 | package com.github.javaparser.ast; |
23 | |
24 | /** |
25 | * A key to a piece of data associated with a {@link Node} at runtime. |
26 | * The key contains type information that can be used to check the |
27 | * type of any user data value for the key when the value is set. DataKey is abstract in order to |
28 | * force the creation of a subtype. That subtype is used to test for identity when looking for the |
29 | * user data because actual object identity would suffer from problems under serialization. |
30 | * So, the correct way to declare a DataKey is like this: |
31 | * <p> |
32 | * <pre> |
33 | * {@code |
34 | * public static final DataKey<Role> ROLE = new DataKey<Role>() { }; |
35 | * } |
36 | * </pre> |
37 | * <p> |
38 | * This code was taken from the <a href="http://wicket.apache.org/">Wicket project</a>. |
39 | * |
40 | * @param <T> The type of the object which is stored |
41 | * @see Node#getData(DataKey) |
42 | */ |
43 | public abstract class DataKey<T> { |
44 | @Override |
45 | public int hashCode() { |
46 | return getClass().hashCode(); |
47 | } |
48 | |
49 | /** |
50 | * @see java.lang.Object#equals(java.lang.Object) |
51 | */ |
52 | @Override |
53 | public boolean equals(Object obj) { |
54 | return obj != null && getClass().equals(obj.getClass()); |
55 | } |
56 | } |
57 |