mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 19:04:49 +00:00
Added throw exception
This commit is contained in:
@@ -84,22 +84,12 @@ public class ResourceManager {
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T extends BaseResource> T get(String name) {
|
||||
ResourceMeta<T> asset = (ResourceMeta<T>) assets.get(name);
|
||||
if (asset == null) return null;
|
||||
if (asset == null) {
|
||||
throw new TypeNotPresentException(name, new RuntimeException(String.format("Type %s not present", name))); // TODO: Create own exception, BAM
|
||||
}
|
||||
return asset.getResource();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the resource of a given name, cast to the expected type.
|
||||
*
|
||||
* @param name the asset name
|
||||
* @param <T> the expected resource type
|
||||
* @return the resource, or null if not found
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T extends BaseResource> T get(Class<T> type, String name) {
|
||||
return type.cast(assets.get(name).getResource());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all assets of a specific resource type.
|
||||
*
|
||||
@@ -134,26 +124,6 @@ public class ResourceManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve an asset by its name.
|
||||
*
|
||||
* @param name the asset name
|
||||
* @return the asset, or null if not found
|
||||
*/
|
||||
public static ResourceMeta<? extends BaseResource> getByName(String name) {
|
||||
return assets.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to find an asset by name, returning an {@link Optional}.
|
||||
*
|
||||
* @param name the asset name
|
||||
* @return an Optional containing the asset if found
|
||||
*/
|
||||
public static Optional<ResourceMeta<? extends BaseResource>> findByName(String name) {
|
||||
return Optional.ofNullable(assets.get(name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new asset to the manager.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user