1 /*
2 * Themis: Java Project Framework
3 * Copyright 2026. Tony Washer
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6 * use this file except in compliance with the License. You may obtain a copy
7 * of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 */
17
18 package io.github.tonywasher.joceanus.themis.solver.proj;
19
20 import io.github.tonywasher.joceanus.themis.solver.proj.ThemisSolverDef.ThemisSolverPackageDef;
21
22 import java.util.ArrayList;
23 import java.util.HashMap;
24 import java.util.List;
25 import java.util.Map;
26
27 /**
28 * Class holding references to other packages.
29 */
30 public class ThemisSolverReference {
31 /**
32 * Map of references to other packages.
33 */
34 private final Map<ThemisSolverPackageDef, ThemisSolverRefPackage> theMap;
35
36 /**
37 * Constructor.
38 */
39 public ThemisSolverReference() {
40 theMap = new HashMap<>();
41 }
42
43 /**
44 * Obtain the references for a package.
45 *
46 * @param pPackage the package
47 * @return the references
48 */
49 public ThemisSolverRefPackage getReferences(final ThemisSolverPackageDef pPackage) {
50 return theMap.get(pPackage);
51 }
52
53 /**
54 * Obtain the references for a package.
55 *
56 * @param pPackage the package
57 * @return the reference
58 */
59 public ThemisSolverRefPackage getReferredPackage(final ThemisSolverPackageDef pPackage) {
60 return theMap.get(pPackage);
61 }
62
63 /**
64 * Add references to map.
65 *
66 * @param pReferences the references
67 */
68 public void addReferences(final ThemisSolverRefPackage pReferences) {
69 final ThemisSolverPackageDef myPackage = pReferences.getPackage();
70 theMap.put(myPackage, pReferences);
71 }
72
73 /**
74 * Obtain references of type.
75 *
76 * @param pRefType the refType
77 * @return the references
78 */
79 public List<ThemisSolverRefPackage> getReferences(final ThemisRefType pRefType) {
80 return theMap.values().stream().filter(p -> p.getReferenceType() == pRefType).toList();
81 }
82
83 /**
84 * Class representing links from a class to classes in a particular package.
85 */
86 public static class ThemisSolverRefPackage {
87 /**
88 * The package that is referred to.
89 */
90 private final ThemisSolverPackageDef thePackage;
91
92 /**
93 * The referenceType.
94 */
95 private final ThemisRefType theRefType;
96
97 /**
98 * The list of classes that refer to the package.
99 */
100 private final List<ThemisSolverRefClass> theReferences;
101
102 /**
103 * Constructor.
104 *
105 * @param pPackage the package
106 * @param pRefType the reference type
107 */
108 public ThemisSolverRefPackage(final ThemisSolverPackageDef pPackage,
109 final ThemisRefType pRefType) {
110 thePackage = pPackage;
111 theRefType = pRefType;
112 theReferences = new ArrayList<>();
113 }
114
115 /**
116 * Obtain the class.
117 *
118 * @return the class
119 */
120 public ThemisSolverPackageDef getPackage() {
121 return thePackage;
122 }
123
124 /**
125 * Obtain the referenceType.
126 *
127 * @return the refType
128 */
129 public ThemisRefType getReferenceType() {
130 return theRefType;
131 }
132
133 /**
134 * Obtain the references.
135 *
136 * @return the references
137 */
138 public List<ThemisSolverRefClass> getReferences() {
139 return theReferences;
140 }
141
142 /**
143 * Add class that has references.
144 *
145 * @param pReferences the references
146 */
147 public void addReferences(final ThemisSolverRefClass pReferences) {
148 theReferences.add(pReferences);
149 }
150
151 @Override
152 public String toString() {
153 return thePackage.toString();
154 }
155 }
156
157 /**
158 * Class representing links from a class to classes in a particular package.
159 */
160 public static class ThemisSolverRefClass {
161 /**
162 * The class that holds the references.
163 */
164 private final ThemisSolverClass theClass;
165
166 /**
167 * The references.
168 */
169 private final List<ThemisSolverClass> theReferences;
170
171 /**
172 * Constructor.
173 *
174 * @param pClass the class
175 * @param pReferences the references
176 */
177 public ThemisSolverRefClass(final ThemisSolverClass pClass,
178 final List<ThemisSolverClass> pReferences) {
179 theClass = pClass;
180 theReferences = pReferences;
181 }
182
183 /**
184 * Obtain the class.
185 *
186 * @return the class
187 */
188 public ThemisSolverClass getSubject() {
189 return theClass;
190 }
191
192 /**
193 * Obtain the references.
194 *
195 * @return the references
196 */
197 public List<ThemisSolverClass> getReferences() {
198 return theReferences;
199 }
200
201 @Override
202 public String toString() {
203 return theClass.getFullName();
204 }
205 }
206
207
208 /**
209 * Map types.
210 */
211 public enum ThemisRefType {
212 /**
213 * Sibling.
214 */
215 SIBLING,
216
217 /**
218 * Child.
219 */
220 CHILD,
221
222 /**
223 * Parent.
224 */
225 PARENT;
226 }
227 }