-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use a predefined dictionary for jar sizes
- Loading branch information
1 parent
7fb4b51
commit ea99953
Showing
2 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/engines/ | ||
/models/ | ||
|
||
# maven specific files | ||
# maven specific files | ||
/target/ | ||
|
||
# eclipse specific files | ||
|
63 changes: 63 additions & 0 deletions
63
src/main/java/io/bioimage/modelrunner/versionmanagement/JarInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package io.bioimage.modelrunner.versionmanagement; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.util.Map; | ||
|
||
public class JarInfo { | ||
|
||
// Static instance for the Singleton | ||
private static JarInfo instance; | ||
|
||
// Map to store the parsed JSON data | ||
private Map<String, Long> urlData; | ||
|
||
private static URL FILE_PATH = JarInfo.class.getClassLoader().getResource("jar_sizes.json"); | ||
|
||
// Private constructor to restrict instantiation | ||
private JarInfo() throws IOException { | ||
loadJsonData(); | ||
} | ||
|
||
/** | ||
* Public method to initialize or get the singleton instance. | ||
* | ||
* @return The single instance of {@link JarInfo} | ||
* @throws IOException If the file cannot be loaded | ||
*/ | ||
public static JarInfo getInstance() throws IOException { | ||
if (instance == null) { | ||
instance = new JarInfo(); | ||
} | ||
return instance; | ||
} | ||
|
||
/** | ||
* Public method to access the URL data | ||
* | ||
* @return Map containing the URL and their respective sizes | ||
*/ | ||
public Map<String, Long> getUrlData() { | ||
return urlData; | ||
} | ||
|
||
/** | ||
* Method to retrieve the size for a specific URL | ||
* | ||
* @param url The URL to look up | ||
* @return The size associated with the URL, or null if not found | ||
*/ | ||
public Long getSizeForUrl(String url) { | ||
return urlData.get(url); | ||
} | ||
|
||
// Private method to load and parse the JSON data | ||
@SuppressWarnings("unchecked") | ||
private void loadJsonData() throws IOException { | ||
ObjectMapper objectMapper = new ObjectMapper(); | ||
urlData = objectMapper.readValue(FILE_PATH, Map.class); | ||
} | ||
} | ||
|