|
21 | 21 |
|
22 | 22 | import java.io.*; |
23 | 23 | import java.nio.file.Files; |
24 | | -import java.util.ArrayList; |
25 | | -import java.util.HashMap; |
26 | | -import java.util.List; |
27 | | -import java.util.Map; |
28 | | -import java.util.Properties; |
| 24 | +import java.util.*; |
29 | 25 | import java.util.stream.Collectors; |
30 | 26 |
|
31 | 27 | import sporemodder.MessageManager; |
@@ -101,13 +97,13 @@ public enum PackageSignature { |
101 | 97 | /** External projects have a file in the Projects folder that links to the real path. */ |
102 | 98 | private File externalLink; |
103 | 99 |
|
104 | | - private final List<Project> references = new ArrayList<>(); |
| 100 | + private final Set<Project> references = new LinkedHashSet<>(); |
105 | 101 |
|
106 | 102 | /** The object that holds the path to the folder where the project DBPF is packed. */ |
107 | 103 | private final GamePathConfiguration packPath; |
108 | 104 |
|
109 | 105 | /** A list of relative paths of all those files that are fixed tabs. */ |
110 | | - private final List<String> fixedTabPaths = new ArrayList<>(); |
| 106 | + private final Set<String> fixedTabPaths = new LinkedHashSet<>(); |
111 | 107 |
|
112 | 108 | /** The embedded 'editorPackages~' file that represents the package signature. */ |
113 | 109 | private PackageSignature packageSignature = PackageSignature.NONE; |
@@ -142,7 +138,7 @@ public Project(String name, File folder, File externalLink) { |
142 | 138 | onNameChanged(null); |
143 | 139 | } |
144 | 140 |
|
145 | | - public List<Project> getReferences() { |
| 141 | + public Set<Project> getReferences() { |
146 | 142 | return references; |
147 | 143 | } |
148 | 144 |
|
@@ -177,15 +173,15 @@ public void loadSettings() { |
177 | 173 | ProjectManager projectManager = ProjectManager.get(); |
178 | 174 |
|
179 | 175 | String[] sourceNames = stringListSplit(PROPERTY_sources); |
| 176 | + references.clear(); |
180 | 177 | for (String str : sourceNames) { |
181 | 178 | Project p = projectManager.getProject(str); |
182 | 179 | if (p != null) references.add(p); |
183 | 180 | } |
184 | 181 |
|
185 | 182 | String[] tabPaths = stringListSplit(PROPERTY_fixedTabPaths); |
186 | | - for (String str : tabPaths) { |
187 | | - fixedTabPaths.add(str); |
188 | | - } |
| 183 | + fixedTabPaths.clear(); |
| 184 | + fixedTabPaths.addAll(Arrays.asList(tabPaths)); |
189 | 185 |
|
190 | 186 | packageName = settings.getProperty(PROPERTY_packageName); |
191 | 187 | if (packageName == null) packageName = getDefaultPackageName(name); |
@@ -229,24 +225,12 @@ public void saveSettings() { |
229 | 225 | //if (!sources.isEmpty()) { |
230 | 226 | // Do this even if it's empty, as we need to update it if sources were removed |
231 | 227 | { |
232 | | - StringBuilder sb = new StringBuilder(); |
233 | | - |
234 | | - for (int i = 0; i < references.size(); i++) { |
235 | | - sb.append("\"" + references.get(i).name + "\""); |
236 | | - if (i != references.size()-1) sb.append("|"); |
237 | | - } |
238 | | - |
239 | | - settings.setProperty(PROPERTY_sources, sb.toString()); |
| 228 | + String referencesStr = references.stream().map(r -> '"' + r.name + '"').collect(Collectors.joining("|")); |
| 229 | + settings.setProperty(PROPERTY_sources, referencesStr); |
240 | 230 | } |
241 | 231 | if (!fixedTabPaths.isEmpty()) { |
242 | | - StringBuilder sb = new StringBuilder(); |
243 | | - |
244 | | - for (int i = 0; i < fixedTabPaths.size(); i++) { |
245 | | - sb.append("\"" + fixedTabPaths.get(i) + "\""); |
246 | | - if (i != fixedTabPaths.size()-1) sb.append("|"); |
247 | | - } |
248 | | - |
249 | | - settings.setProperty(PROPERTY_fixedTabPaths, sb.toString()); |
| 232 | + String str = fixedTabPaths.stream().map(r -> '"' + r + '"').collect(Collectors.joining("|")); |
| 233 | + settings.setProperty(PROPERTY_fixedTabPaths, str); |
250 | 234 | } |
251 | 235 |
|
252 | 236 | settings.put(PROPERTY_packageName, packageName); |
@@ -304,7 +288,7 @@ public void setReadOnly(boolean isReadOnly) { |
304 | 288 | * Returns a list of relative paths of all those files that are fixed tabs. |
305 | 289 | * @return |
306 | 290 | */ |
307 | | - public List<String> getFixedTabPaths() { |
| 291 | + public Set<String> getFixedTabPaths() { |
308 | 292 | return fixedTabPaths; |
309 | 293 | } |
310 | 294 |
|
|
0 commit comments