Skip to content

Commit a571766

Browse files
committed
LibraryManager.java - reformatted
1 parent b98d1c9 commit a571766

File tree

1 file changed

+184
-184
lines changed

1 file changed

+184
-184
lines changed

io.sloeber.core/src/io/sloeber/core/api/LibraryManager.java

Lines changed: 184 additions & 184 deletions
Original file line numberDiff line numberDiff line change
@@ -14,205 +14,205 @@
1414
import io.sloeber.core.managers.Manager;
1515

1616
public class LibraryManager {
17-
public static LibraryTree getLibraryTree() {
18-
return new LibraryTree();
17+
public static LibraryTree getLibraryTree() {
18+
return new LibraryTree();
1919

20-
}
21-
22-
public static class LibraryTree {
23-
24-
private TreeMap<String, Category> categories = new TreeMap<>();
25-
26-
public class Category implements Comparable<Category>, Node {
27-
private String name;
28-
protected TreeMap<String, Library> libraries = new TreeMap<>();
29-
30-
public Category(String name) {
31-
this.name = name;
32-
}
33-
34-
@Override
35-
public String getName() {
36-
return this.name;
37-
}
38-
39-
public Collection<Library> getLibraries() {
40-
return this.libraries.values();
41-
}
42-
43-
@Override
44-
public int compareTo(Category other) {
45-
return this.name.compareTo(other.name);
46-
}
47-
48-
@Override
49-
public boolean hasChildren() {
50-
return !this.libraries.isEmpty();
51-
}
52-
53-
@Override
54-
public Object[] getChildren() {
55-
return this.libraries.values().toArray();
56-
}
57-
58-
@Override
59-
public Object getParent() {
60-
return LibraryTree.this;
61-
}
62-
}
63-
64-
public class Library implements Comparable<Library>, Node {
65-
private String name;
66-
private String indexName;
67-
private Category category;
68-
protected TreeSet<VersionNumber> versions = new TreeSet<>();
69-
protected String version;
70-
private String tooltip;
71-
72-
public Library(Category category, String name, String indexName, String tooltip) {
73-
this.category = category;
74-
this.name = name;
75-
this.tooltip = tooltip;
76-
this.indexName = indexName;
77-
}
78-
79-
public Collection<VersionNumber> getVersions() {
80-
return this.versions;
81-
}
82-
83-
@Override
84-
public String getName() {
85-
return this.name;
86-
}
87-
88-
public String getTooltip() {
89-
return this.tooltip;
90-
}
91-
92-
public String getLatest() {
93-
return this.versions.last().toString();
94-
}
95-
96-
public String getVersion() {
97-
return this.version;
98-
}
99-
100-
public String getIndexName() {
101-
return this.indexName;
102-
}
103-
104-
public void setVersion(String version) {
105-
this.version = version;
106-
}
107-
108-
@Override
109-
public int compareTo(Library other) {
110-
return this.name.compareTo(other.name);
111-
}
112-
113-
@Override
114-
public boolean hasChildren() {
115-
return false;
116-
}
117-
118-
@Override
119-
public Object[] getChildren() {
120-
return null;
121-
}
122-
123-
@Override
124-
public Object getParent() {
125-
return this.category;
126-
}
12720
}
12821

129-
public LibraryTree() {
130-
for (LibraryIndex libraryIndex : Manager.getLibraryIndices()) {
131-
for (String categoryName : libraryIndex.getCategories()) {
132-
Category category = this.categories.get(categoryName);
133-
if (category == null) {
134-
category = new Category(categoryName);
135-
this.categories.put(category.getName(), category);
136-
}
137-
for (io.sloeber.core.managers.Library library : libraryIndex.getLibraries(categoryName)) {
138-
Library lib = category.libraries.get(library.getName() + " (" + libraryIndex.getName() + ")");
139-
if (lib == null) {
140-
StringBuilder builder = new StringBuilder("Architectures:") //$NON-NLS-1$
141-
.append(library.getArchitectures().toString()).append("\n\n") //$NON-NLS-1$
142-
.append(library.getSentence());
143-
lib = new Library(category, library.getName(), libraryIndex.getName(), builder.toString());
144-
category.libraries.put(library.getName() + " (" + libraryIndex.getName() + ")", lib);
22+
public static class LibraryTree {
23+
24+
private TreeMap<String, Category> categories = new TreeMap<>();
25+
26+
public class Category implements Comparable<Category>, Node {
27+
private String name;
28+
protected TreeMap<String, Library> libraries = new TreeMap<>();
29+
30+
public Category(String name) {
31+
this.name = name;
32+
}
33+
34+
@Override
35+
public String getName() {
36+
return this.name;
37+
}
38+
39+
public Collection<Library> getLibraries() {
40+
return this.libraries.values();
41+
}
42+
43+
@Override
44+
public int compareTo(Category other) {
45+
return this.name.compareTo(other.name);
46+
}
47+
48+
@Override
49+
public boolean hasChildren() {
50+
return !this.libraries.isEmpty();
51+
}
52+
53+
@Override
54+
public Object[] getChildren() {
55+
return this.libraries.values().toArray();
56+
}
57+
58+
@Override
59+
public Object getParent() {
60+
return LibraryTree.this;
61+
}
62+
}
63+
64+
public class Library implements Comparable<Library>, Node {
65+
private String name;
66+
private String indexName;
67+
private Category category;
68+
protected TreeSet<VersionNumber> versions = new TreeSet<>();
69+
protected String version;
70+
private String tooltip;
71+
72+
public Library(Category category, String name, String indexName, String tooltip) {
73+
this.category = category;
74+
this.name = name;
75+
this.tooltip = tooltip;
76+
this.indexName = indexName;
77+
}
78+
79+
public Collection<VersionNumber> getVersions() {
80+
return this.versions;
81+
}
82+
83+
@Override
84+
public String getName() {
85+
return this.name;
86+
}
87+
88+
public String getTooltip() {
89+
return this.tooltip;
90+
}
91+
92+
public String getLatest() {
93+
return this.versions.last().toString();
94+
}
95+
96+
public String getVersion() {
97+
return this.version;
98+
}
99+
100+
public String getIndexName() {
101+
return this.indexName;
102+
}
103+
104+
public void setVersion(String version) {
105+
this.version = version;
106+
}
107+
108+
@Override
109+
public int compareTo(Library other) {
110+
return this.name.compareTo(other.name);
111+
}
112+
113+
@Override
114+
public boolean hasChildren() {
115+
return false;
116+
}
117+
118+
@Override
119+
public Object[] getChildren() {
120+
return null;
121+
}
122+
123+
@Override
124+
public Object getParent() {
125+
return this.category;
126+
}
127+
}
128+
129+
public LibraryTree() {
130+
for (LibraryIndex libraryIndex : Manager.getLibraryIndices()) {
131+
for (String categoryName : libraryIndex.getCategories()) {
132+
Category category = this.categories.get(categoryName);
133+
if (category == null) {
134+
category = new Category(categoryName);
135+
this.categories.put(category.getName(), category);
145136
}
146-
lib.versions.add(new VersionNumber(library.getVersion()));
147-
if (library.isInstalled()) {
148-
lib.version = library.getVersion();
137+
for (io.sloeber.core.managers.Library library : libraryIndex.getLibraries(categoryName)) {
138+
Library lib = category.libraries.get(library.getName() + " (" + libraryIndex.getName() + ")");
139+
if (lib == null) {
140+
StringBuilder builder = new StringBuilder("Architectures:") //$NON-NLS-1$
141+
.append(library.getArchitectures().toString()).append("\n\n") //$NON-NLS-1$
142+
.append(library.getSentence());
143+
lib = new Library(category, library.getName(), libraryIndex.getName(), builder.toString());
144+
category.libraries.put(library.getName() + " (" + libraryIndex.getName() + ")", lib);
145+
}
146+
lib.versions.add(new VersionNumber(library.getVersion()));
147+
if (library.isInstalled()) {
148+
lib.version = library.getVersion();
149+
}
149150
}
150151
}
151-
}
152-
}
153-
}
152+
}
153+
}
154+
155+
public Collection<Category> getCategories() {
156+
return this.categories.values();
157+
}
158+
159+
public Collection<Library> getAllLibraries() {
160+
Set<Library> all = new TreeSet<>();
161+
for (Category category : this.categories.values()) {
162+
all.addAll(category.getLibraries());
163+
}
164+
return all;
165+
}
166+
167+
private static LibraryIndex findLibraryIndex(String name) {
168+
for (LibraryIndex libraryIndex : Manager.getLibraryIndices()) {
169+
if (libraryIndex.getName().equals(name))
170+
return libraryIndex;
171+
}
172+
return null;
173+
}
174+
175+
public void reset() {
176+
for (Library library : this.getAllLibraries()) {
177+
LibraryIndex libraryIndex = findLibraryIndex(library.getIndexName());
178+
179+
if (libraryIndex != null) {
180+
io.sloeber.core.managers.Library installed = libraryIndex.getInstalledLibrary(library.getName());
181+
library.setVersion(installed != null ? installed.getVersion() : null);
182+
}
183+
}
184+
}
154185

155-
public Collection<Category> getCategories() {
156-
return this.categories.values();
157186
}
158187

159-
public Collection<Library> getAllLibraries() {
160-
Set<Library> all = new TreeSet<>();
161-
for (Category category : this.categories.values()) {
162-
all.addAll(category.getLibraries());
163-
}
164-
return all;
165-
}
188+
public static IStatus setLibraryTree(LibraryTree libs, IProgressMonitor monitor, MultiStatus status) {
189+
for (LibraryTree.Library lib : libs.getAllLibraries()) {
190+
LibraryIndex libraryIndex = findLibraryIndex(lib.getIndexName());
166191

167-
private static LibraryIndex findLibraryIndex(String name) {
168-
for (LibraryIndex libraryIndex : Manager.getLibraryIndices()) {
169-
if (libraryIndex.getName().equals(name))
170-
return libraryIndex;
171-
}
172-
return null;
173-
}
174-
175-
public void reset() {
176-
for (Library library : this.getAllLibraries()) {
177-
LibraryIndex libraryIndex = findLibraryIndex(library.getIndexName());
178-
179-
if (libraryIndex != null) {
180-
io.sloeber.core.managers.Library installed = libraryIndex.getInstalledLibrary(library.getName());
181-
library.setVersion(installed != null ? installed.getVersion() : null);
182-
}
183-
}
192+
if (libraryIndex != null) {
193+
io.sloeber.core.managers.Library toRemove = libraryIndex.getInstalledLibrary(lib.getName());
194+
if (toRemove != null && !toRemove.getVersion().equals(lib.getVersion())) {
195+
status.add(toRemove.remove(monitor));
196+
}
197+
io.sloeber.core.managers.Library toInstall = libraryIndex.getLibrary(lib.getName(), lib.getVersion());
198+
if (toInstall != null && !toInstall.isInstalled()) {
199+
status.add(toInstall.install(monitor));
200+
}
201+
}
202+
}
203+
return status;
184204
}
185205

186-
}
187-
188-
public static IStatus setLibraryTree(LibraryTree libs, IProgressMonitor monitor, MultiStatus status) {
189-
for (LibraryTree.Library lib : libs.getAllLibraries()) {
190-
LibraryIndex libraryIndex = findLibraryIndex(lib.getIndexName());
191-
192-
if (libraryIndex != null) {
193-
io.sloeber.core.managers.Library toRemove = libraryIndex.getInstalledLibrary(lib.getName());
194-
if (toRemove != null && !toRemove.getVersion().equals(lib.getVersion())) {
195-
status.add(toRemove.remove(monitor));
196-
}
197-
io.sloeber.core.managers.Library toInstall = libraryIndex.getLibrary(lib.getName(), lib.getVersion());
198-
if (toInstall != null && !toInstall.isInstalled()) {
199-
status.add(toInstall.install(monitor));
200-
}
201-
}
202-
}
203-
return status;
204-
}
205-
206-
private static LibraryIndex findLibraryIndex(String indexName) {
207-
for (LibraryIndex libraryIndex : Manager.getLibraryIndices()) {
208-
if (libraryIndex.getName().equals(indexName))
209-
return libraryIndex;
210-
}
206+
private static LibraryIndex findLibraryIndex(String indexName) {
207+
for (LibraryIndex libraryIndex : Manager.getLibraryIndices()) {
208+
if (libraryIndex.getName().equals(indexName))
209+
return libraryIndex;
210+
}
211211
return null;
212212
}
213213

214214
public static String getPrivateLibraryPathsString() {
215-
return InstancePreferences.getPrivateLibraryPathsString();
216-
}
215+
return InstancePreferences.getPrivateLibraryPathsString();
216+
}
217217

218218
}

0 commit comments

Comments
 (0)