View Javadoc
1   /*
2    * Themis: Java Project Framework
3    * Copyright 2012-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  package io.github.tonywasher.joceanus.themis.xanalysis.solver.proj;
18  
19  import io.github.tonywasher.joceanus.themis.xanalysis.parser.proj.ThemisXAnalysisFile;
20  import io.github.tonywasher.joceanus.themis.xanalysis.parser.proj.ThemisXAnalysisPackage;
21  import io.github.tonywasher.joceanus.themis.xanalysis.solver.proj.ThemisXAnalysisSolverDef.ThemisXAnalysisSolverModuleDef;
22  import io.github.tonywasher.joceanus.themis.xanalysis.solver.proj.ThemisXAnalysisSolverDef.ThemisXAnalysisSolverPackageDef;
23  
24  import java.util.ArrayList;
25  import java.util.List;
26  
27  /**
28   * Solver Package.
29   */
30  public class ThemisXAnalysisSolverPackage
31          implements ThemisXAnalysisSolverPackageDef {
32      /**
33       * The owning module.
34       */
35      private final ThemisXAnalysisSolverModuleDef theModule;
36  
37      /**
38       * The underlying package.
39       */
40      private final ThemisXAnalysisPackage thePackage;
41  
42      /**
43       * The files.
44       */
45      private final List<ThemisXAnalysisSolverFile> theFiles;
46  
47      /**
48       * The list of packages that are referenced by this package.
49       */
50      private final List<ThemisXAnalysisSolverPackage> theReferenced;
51  
52      /**
53       * Is the reference list circular?
54       */
55      private boolean isCircular;
56  
57      /**
58       * Constructor.
59       *
60       * @param pModule  the owning module
61       * @param pPackage the parsed package
62       */
63      ThemisXAnalysisSolverPackage(final ThemisXAnalysisSolverModuleDef pModule,
64                                   final ThemisXAnalysisPackage pPackage) {
65          /* Store the package and register with parser */
66          theModule = pModule;
67          thePackage = pPackage;
68          theReferenced = new ArrayList<>();
69  
70          /* Populate the fileList */
71          theFiles = new ArrayList<>();
72          for (ThemisXAnalysisFile myFile : thePackage.getFiles()) {
73              final ThemisXAnalysisSolverFile mySolverFile = new ThemisXAnalysisSolverFile(this, myFile);
74              theFiles.add(mySolverFile);
75          }
76      }
77  
78      @Override
79      public ThemisXAnalysisSolverModuleDef getOwningModule() {
80          return theModule;
81      }
82  
83      @Override
84      public ThemisXAnalysisPackage getUnderlyingPackage() {
85          return thePackage;
86      }
87  
88      /**
89       * Obtain the package name.
90       *
91       * @return the package name
92       */
93      public String getPackageName() {
94          return thePackage.getPackage();
95      }
96  
97      /**
98       * Obtain the file list.
99       *
100      * @return the file list
101      */
102     public List<ThemisXAnalysisSolverFile> getFiles() {
103         return theFiles;
104     }
105 
106     /**
107      * Obtain the list of referenced packages.
108      *
109      * @return the list of referenced packages
110      */
111     public List<ThemisXAnalysisSolverPackage> getReferenced() {
112         return theReferenced;
113     }
114 
115     /**
116      * Is teh reference list circular?
117      *
118      * @return true/false
119      */
120     public boolean isCircular() {
121         return isCircular;
122     }
123 
124     /**
125      * Mark the package as circular.
126      */
127     public void markCircular() {
128         isCircular = true;
129     }
130 
131     @Override
132     public boolean equals(final Object pThat) {
133         /* Handle the trivial cases */
134         if (this == pThat) {
135             return true;
136         }
137         if (pThat == null) {
138             return false;
139         }
140 
141         /* Make sure that the object is a DSMPackage */
142         if (!(pThat instanceof ThemisXAnalysisSolverPackage myThat)) {
143             return false;
144         }
145 
146         /* Check name of package */
147         return getPackageName().equals(myThat.getPackageName());
148     }
149 
150     @Override
151     public int hashCode() {
152         return getPackageName().hashCode();
153     }
154 
155     @Override
156     public String toString() {
157         return thePackage.toString();
158     }
159 }