Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
FDelporte committed Jan 28, 2025
1 parent 52b9c51 commit da15858
Show file tree
Hide file tree
Showing 3 changed files with 193 additions and 193 deletions.
43 changes: 27 additions & 16 deletions pi4j-core/src/main/java/com/pi4j/context/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ public interface Context extends Describable, IOCreator, ProviderProvider, Initi
* Submits the given task for async execution
*
* @param task the task to execute asynchronously
*
* @return the task to cancel later
*/
Future<?> submitTask(Runnable task);
Expand All @@ -121,13 +120,11 @@ public interface Context extends Describable, IOCreator, ProviderProvider, Initi
Context shutdown() throws ShutdownException;

/**
*
* @return {@link Future} of {@link Context}
*/
Future<Context> asyncShutdown();

/**
*
* @return Flag indicating if the context has been shutdown
*/
boolean isShutdown();
Expand Down Expand Up @@ -215,7 +212,7 @@ default boolean hasPlatform(String id) throws PlatformNotFoundException {
* <p>platform.</p>
*
* @param platformClass a P object.
* @param <P> the platform type
* @param <P> the platform type
* @return a P object.
* @throws PlatformNotFoundException if platform specified by {@code platformClass} is not found.
*/
Expand All @@ -227,7 +224,7 @@ default <P extends Platform> P platform(Class<P> platformClass) throws PlatformN
* <p>platform.</p>
*
* @param platformClass a P object.
* @param <P> the platform type
* @param <P> the platform type
* @return a P object.
* @throws PlatformNotFoundException if platform specified by {@code platformClass} is not found.
*/
Expand All @@ -239,7 +236,7 @@ default <P extends Platform> P getPlatform(Class<P> platformClass) throws Platfo
* <p>Has platforms.</p>
*
* @param platformClass a P object.
* @return {@link boolean}
* @return boolean
* @throws PlatformNotFoundException if platform specified by {@code platformClass} is not found.
*/
default boolean hasPlatform(Class<? extends Platform> platformClass) throws PlatformNotFoundException {
Expand All @@ -250,18 +247,24 @@ default boolean hasPlatform(Class<? extends Platform> platformClass) throws Plat
// PROVIDER ACCESSOR METHODS
// ------------------------------------------------------------------------

/** {@inheritDoc} */
/**
* {@inheritDoc}
*/
default <T extends Provider> T provider(String providerId) throws ProviderNotFoundException {
return (T) providers().get(providerId);
}

/** {@inheritDoc} */
/**
* {@inheritDoc}
*/
default <T extends Provider> T provider(String providerId, Class<T> providerClass)
throws ProviderNotFoundException {
return (T) providers().get(providerId);
}

/** {@inheritDoc} */
/**
* {@inheritDoc}
*/
default boolean hasProvider(String providerId) {
try {
return providers().exists(providerId);
Expand All @@ -270,17 +273,23 @@ default boolean hasProvider(String providerId) {
}
}

/** {@inheritDoc} */
/**
* {@inheritDoc}
*/
default <T extends Provider> boolean hasProvider(IOType ioType) {
return providers().exists(ioType);
}

/** {@inheritDoc} */
/**
* {@inheritDoc}
*/
default <T extends Provider> boolean hasProvider(Class<T> providerClass) {
return providers().exists(providerClass);
}

/** {@inheritDoc} */
/**
* {@inheritDoc}
*/
default <T extends Provider> T provider(Class<T> providerClass)
throws ProviderNotFoundException, ProviderInterfaceException {
// return the default provider for this type from the default platform
Expand All @@ -295,7 +304,9 @@ default <T extends Provider> T provider(Class<T> providerClass)
throw new ProviderNotFoundException(providerClass);
}

/** {@inheritDoc} */
/**
* {@inheritDoc}
*/
default <T extends Provider> T provider(IOType ioType) throws ProviderNotFoundException {
// return the default provider for this type from the default platform
if (platform() != null && platform().hasProvider(ioType))
Expand Down Expand Up @@ -389,7 +400,7 @@ default <T extends IO> T create(String id) {
if (provider == null) {
// unable to resolve the IO type and thus unable to create I/O instance
throw new IOException("This IO instance [" + id +
"] could not be created because it does not define one of the following: 'PLATFORM', 'PROVIDER', or 'I/O TYPE'.");
"] could not be created because it does not define one of the following: 'PLATFORM', 'PROVIDER', or 'I/O TYPE'.");
}

// create IO instance using the provided ID and resolved inherited properties
Expand Down Expand Up @@ -423,8 +434,8 @@ default <T extends IO> T create(String id, IOType ioType) {
// validate IO type from resolved provider
if (!ioType.isType(provider.type())) {
throw new IOException("This IO instance [" + id +
"] could not be created because the resolved provider [" + providerId +
"] does not match the required I/O TYPE [" + ioType.name() + "]");
"] could not be created because the resolved provider [" + providerId +
"] does not match the required I/O TYPE [" + ioType.name() + "]");
}
}

Expand Down
Loading

0 comments on commit da15858

Please sign in to comment.