Skip to content

Commit

Permalink
Merge pull request #418 from wujiang1900/make-units-extendable
Browse files Browse the repository at this point in the history
Change addUnit methods to protected and add one more addUnit method
  • Loading branch information
keilw authored Jun 14, 2024
2 parents 67e5e69 + 3612f8e commit 7a33470
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/main/java/tech/units/indriya/unit/Units.java
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ public static Units getInstance() {
* the string to use as name
* @return <code>unit</code>.
*/
private static <U extends Unit<?>> U addUnit(U unit, String name) {
protected static <U extends Unit<?>> U addUnit(U unit, String name) {
if (name != null && unit instanceof AbstractUnit) {
return Helper.addUnit(INSTANCE.units, unit, name);
} else {
Expand All @@ -642,7 +642,7 @@ private static <U extends Unit<?>> U addUnit(U unit, String name) {
* @param unit the unit being added.
* @return <code>unit</code>.
*/
private static <U extends Unit<?>> U addUnit(U unit) {
protected static <U extends Unit<?>> U addUnit(U unit) {
INSTANCE.units.add(unit);
return unit;
}
Expand All @@ -655,7 +655,7 @@ private static <U extends Unit<?>> U addUnit(U unit) {
* @param type the quantity type.
* @return <code>unit</code>.
*/
private static <U extends AbstractUnit<?>> U addUnit(U unit, String name, Class<? extends Quantity<?>> type) {
protected static <U extends AbstractUnit<?>> U addUnit(U unit, String name, Class<? extends Quantity<?>> type) {
Helper.addUnit(INSTANCE.units, unit, name);
INSTANCE.quantityToUnit.put(type, unit);
return unit;
Expand All @@ -668,9 +668,13 @@ private static <U extends AbstractUnit<?>> U addUnit(U unit, String name, Class<
* @param type the quantity type.
* @return <code>unit</code>.
*/
private static <U extends AbstractUnit<?>> U addUnit(U unit, Class<? extends Quantity<?>> type) {
protected static <U extends AbstractUnit<?>> U addUnit(U unit, Class<? extends Quantity<?>> type) {
INSTANCE.units.add(unit);
INSTANCE.quantityToUnit.put(type, unit);
return unit;
}

protected static <U extends AbstractUnit<?>> U addUnit(U unit, String name, String symbol) {
return Helper.addUnit(INSTANCE.units, unit, name, symbol);
}
}

0 comments on commit 7a33470

Please sign in to comment.