Debian Codegraph @

src/smetana/core/OFFSET.java

raw symbols SCIP
1 /* ========================================================================
2 * PlantUML : a free UML diagram generator
3 * ========================================================================
4 *
5 * Project Info: http://plantuml.com
6 *
7 * If you like this project or if you find it useful, you can support us at:
8 *
9 * http://plantuml.com/patreon (only 1$ per month!)
10 * http://plantuml.com/paypal
11 *
12 * This file is part of Smetana.
13 * Smetana is a partial translation of Graphviz/Dot sources from C to Java.
14 *
15 * (C) Copyright 2009-2020, Arnaud Roques
16 *
17 * This translation is distributed under the same Licence as the original C program.
18 *
19 * THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC
20 * LICENSE ("AGREEMENT"). [Eclipse Public License - v 1.0]
21 *
22 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES
23 * RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
24 *
25 * You may obtain a copy of the License at
26 *
27 * http://www.eclipse.org/legal/epl-v10.html
28 *
29 * Unless required by applicable law or agreed to in writing, software
30 * distributed under the License is distributed on an "AS IS" BASIS,
31 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32 * See the License for the specific language governing permissions and
33 * limitations under the License.
34 *
35 */
36
37 package smetana.core;
38
39 import java.util.Arrays;
40 import java.util.HashMap;
41 import java.util.Map;
42
43 public class OFFSET {
44
45 private static int CPT = 10000;
46 private static Map<Integer, OFFSET> byID = new HashMap<Integer, OFFSET>();
47 private static Map<Object, OFFSET> primaryKey = new HashMap<Object, OFFSET>();
48
49 private final Class cl;
50 private final String field;
51 private final int id;
52
53 private OFFSET(Class cl, String field) {
54 this.cl = cl;
55 this.field = field;
56 this.id = CPT++;
57 JUtils.LOG("REAL CREATING OF " + this);
58 }
59
60 @Override
61 public String toString() {
62 return cl.getName() + "::" + field;
63 }
64
65 public static OFFSET create(Class cl, String field) {
66 final Object key = Arrays.asList(cl, field);
67 JUtils.LOG("getting OFFSET " + key);
68 OFFSET result = primaryKey.get(key);
69 if (result != null) {
70 JUtils.LOG("FOUND!");
71 return result;
72 }
73 result = new OFFSET(cl, field);
74 byID.put(result.id, result);
75 primaryKey.put(key, result);
76 return result;
77 }
78
79 public int toInt() {
80 return id;
81 }
82
83 public static OFFSET fromInt(int value) {
84 final OFFSET result = byID.get(value);
85 if (result == null) {
86 throw new IllegalArgumentException("value=" + value);
87 }
88 return result;
89 }
90
91 public final Class getTheClass() {
92 return cl;
93 }
94
95 public final String getField() {
96 return field;
97 }
98
99 }