-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2: Integrate Health with the SPI to demonstrate how to add a new system
Task-Url: #2
- Loading branch information
Showing
15 changed files
with
467 additions
and
29 deletions.
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
63 changes: 63 additions & 0 deletions
63
health/health/src/main/java/tech/uom/domain/health/spi/HealthServiceProvider.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 @@ | ||
/* | ||
* Domain Specific Units of Measurement Extensions | ||
* Copyright (c) 2018, Units of Measurement | ||
* | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, | ||
* are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
* and the following disclaimer in the documentation and/or other materials provided with the distribution. | ||
* | ||
* 3. Neither the name of Unit-API, Units of Measurement nor the names of their contributors may be used to endorse or promote products | ||
* derived from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | ||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, | ||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package tech.uom.domain.health.spi; | ||
|
||
import static tech.uom.domain.health.spi.ServiceConstants.*; | ||
|
||
import javax.measure.spi.ServiceProvider; | ||
import javax.measure.spi.SystemOfUnitsService; | ||
|
||
import jakarta.inject.Named; | ||
import tech.units.indriya.spi.AbstractServiceProvider; | ||
|
||
/** | ||
* This class implements the {@link ServiceProvider} interface and hereby uses | ||
* the JDK {@link java.util.ServiceLoader} to load the services required. | ||
* | ||
* @author Werner Keil | ||
* @version 0.3 | ||
*/ | ||
@Named(NAME) | ||
public class HealthServiceProvider extends AbstractServiceProvider { | ||
|
||
public int getPriority() { | ||
return PRIO; | ||
} | ||
|
||
@Override | ||
public SystemOfUnitsService getSystemOfUnitsService() { | ||
return new HealthSystemService(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return NAME; | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
health/health/src/main/java/tech/uom/domain/health/spi/HealthSystemService.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,79 @@ | ||
/* | ||
* Domain Specific Units of Measurement Extensions | ||
* Copyright (c) 2018-2021, Units of Measurement | ||
* | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, | ||
* are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
* and the following disclaimer in the documentation and/or other materials provided with the distribution. | ||
* | ||
* 3. Neither the name of Unit-API, Units of Measurement nor the names of their contributors may be used to endorse or promote products | ||
* derived from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | ||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, | ||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package tech.uom.domain.health.spi; | ||
|
||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import javax.measure.spi.SystemOfUnits; | ||
import javax.measure.spi.SystemOfUnitsService; | ||
|
||
import tech.uom.domain.health.unit.Health; | ||
import tech.uom.lib.common.function.IntPrioritySupplier; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Werner Keil</a> | ||
* @version 0.9, January 05, 2021 | ||
*/ | ||
public class HealthSystemService implements SystemOfUnitsService, IntPrioritySupplier { | ||
private static final int PRIO = 20; | ||
private static final String DEFAULT_SYSTEM_NAME = Health.getInstance().getName(); | ||
private final Map<String, SystemOfUnits> souMap = new HashMap<>(); | ||
private final Map<String, String> aliases = new HashMap<>(); | ||
|
||
public HealthSystemService() { | ||
souMap.put(Health.getInstance().getName(), Health.getInstance()); | ||
aliases.put("Digital Imaging", DEFAULT_SYSTEM_NAME); | ||
} | ||
|
||
public Collection<SystemOfUnits> getAvailableSystemsOfUnits() { | ||
return souMap.values(); | ||
} | ||
|
||
@Override | ||
public SystemOfUnits getSystemOfUnits() { | ||
return getSystemOfUnits(Health.getInstance().getName()); | ||
} | ||
|
||
@Override | ||
public SystemOfUnits getSystemOfUnits(String name) { | ||
String alias = aliases.get(name); | ||
if (alias != null && alias.length() > 0) { | ||
return souMap.get(alias); | ||
} | ||
return souMap.get(name); | ||
} | ||
|
||
@Override | ||
public int getPriority() { | ||
return PRIO; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
health/health/src/main/java/tech/uom/domain/health/spi/ServiceConstants.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,39 @@ | ||
/* | ||
* Domain Specific Units of Measurement Extensions | ||
* Copyright (c) 2018-2021, Units of Measurement | ||
* | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, | ||
* are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
* and the following disclaimer in the documentation and/or other materials provided with the distribution. | ||
* | ||
* 3. Neither the name of Unit-API, Units of Measurement nor the names of their contributors may be used to endorse or promote products | ||
* derived from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | ||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, | ||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package tech.uom.domain.health.spi; | ||
|
||
class ServiceConstants { | ||
/** Name of the service provider | ||
*/ | ||
static final String NAME = "Health"; | ||
/** This priority is set to <CODE>12000</CODE>. | ||
*/ | ||
static final int PRIO = 12000; | ||
} |
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
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
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
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
Oops, something went wrong.