From b0055ad0a833b21d255f6e6bf0a74553ca30291d Mon Sep 17 00:00:00 2001 From: David Legg Date: Tue, 12 Dec 2023 09:50:49 -0800 Subject: [PATCH] Remove 'Mutable' from resource constructor names --- .../contrib/streamline/modeling/Demo.java | 26 +++++++++---------- .../modeling/discrete/DiscreteResources.java | 8 +++--- .../polynomial/PolynomialResources.java | 6 ++--- .../streamline_demo/ApproximationModel.java | 4 +-- .../jpl/aerie/streamline_demo/DataModel.java | 16 ++++++------ .../streamline_demo/ErrorTestingModel.java | 14 +++++----- 6 files changed, 37 insertions(+), 37 deletions(-) diff --git a/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/modeling/Demo.java b/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/modeling/Demo.java index 4dc6f72e36..12da74f904 100644 --- a/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/modeling/Demo.java +++ b/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/modeling/Demo.java @@ -32,7 +32,7 @@ import static gov.nasa.jpl.aerie.contrib.streamline.modeling.discrete.DiscreteEffects.toggle; import static gov.nasa.jpl.aerie.contrib.streamline.modeling.discrete.DiscreteEffects.using; import static gov.nasa.jpl.aerie.contrib.streamline.modeling.discrete.DiscreteResources.assertThat; -import static gov.nasa.jpl.aerie.contrib.streamline.modeling.discrete.DiscreteResources.discreteMutableResource; +import static gov.nasa.jpl.aerie.contrib.streamline.modeling.discrete.DiscreteResources.discreteResource; import static gov.nasa.jpl.aerie.contrib.streamline.modeling.discrete.monads.DiscreteResourceMonad.map; import static gov.nasa.jpl.aerie.contrib.streamline.modeling.polynomial.PolynomialEffects.consume; import static gov.nasa.jpl.aerie.contrib.streamline.modeling.polynomial.PolynomialResources.asPolynomial; @@ -42,7 +42,7 @@ import static gov.nasa.jpl.aerie.contrib.streamline.modeling.polynomial.PolynomialResources.integrate; import static gov.nasa.jpl.aerie.contrib.streamline.modeling.polynomial.PolynomialResources.lessThan; import static gov.nasa.jpl.aerie.contrib.streamline.modeling.polynomial.PolynomialResources.lessThan$; -import static gov.nasa.jpl.aerie.contrib.streamline.modeling.polynomial.PolynomialResources.polynomialMutableResource; +import static gov.nasa.jpl.aerie.contrib.streamline.modeling.polynomial.PolynomialResources.polynomialResource; import static gov.nasa.jpl.aerie.contrib.streamline.modeling.polynomial.PolynomialResources.unitAware; import static gov.nasa.jpl.aerie.contrib.streamline.unit_aware.Quantities.quantity; import static gov.nasa.jpl.aerie.contrib.streamline.unit_aware.StandardUnits.*; @@ -54,15 +54,15 @@ public final class Demo { // Unit-naive version of a model, to demonstrate some core concepts: // Consumable, continuous: - MutableResource fuel_kg = PolynomialResources.polynomialMutableResource(20.0); + MutableResource fuel_kg = PolynomialResources.polynomialResource(20.0); // Non-consumable, discrete: - MutableResource> power_w = discreteMutableResource(120.0); + MutableResource> power_w = discreteResource(120.0); // Atomic non-consumable: - MutableResource> rwaControl = DiscreteResources.discreteMutableResource(1); + MutableResource> rwaControl = DiscreteResources.discreteResource(1); // Settable / enum state: - MutableResource> enumSwitch = DiscreteResources.discreteMutableResource(OnOff.ON); + MutableResource> enumSwitch = DiscreteResources.discreteResource(OnOff.ON); // Toggle / flag: - MutableResource> boolSwitch = DiscreteResources.discreteMutableResource(true); + MutableResource> boolSwitch = DiscreteResources.discreteResource(true); // Derived states: Resource> derivedEnumSwitch = map(boolSwitch, b -> b ? OnOff.ON : OnOff.OFF); @@ -97,10 +97,10 @@ public final class Demo { // Consumable, continuous: // CellResource fuel_kg = polynomialCellResource(20.0); UnitAware> fuel = unitAware( - PolynomialResources.polynomialMutableResource(20.0), KILOGRAM); + PolynomialResources.polynomialResource(20.0), KILOGRAM); // Non-consumable, discrete: UnitAware>> power = DiscreteResources.unitAware( - discreteMutableResource(120.0), WATT); + discreteResource(120.0), WATT); UnitAware> batterySOC = integrate(asUnitAwarePolynomial(power), quantity(100, JOULE)); UnitAware>> clampedPower = DiscreteResources.unitAware(map(power.value(WATT), p -> p < 0 ? 0 : p), WATT); @@ -124,8 +124,8 @@ public final class Demo { // Example of using unstructured resources + approximation to represent functions that aren't // easily represented by analytic derivations - Resource p = PolynomialResources.polynomialMutableResource(1, 2, 3); - Resource q = PolynomialResources.polynomialMutableResource(6, 5, 4); + Resource p = PolynomialResources.polynomialResource(1, 2, 3); + Resource q = PolynomialResources.polynomialResource(6, 5, 4); Resource> quotient = UnstructuredResourceApplicative.map(asUnstructured(p), asUnstructured(q), (p$, q$) -> p$ / q$); Resource approxQuotient = approximate(quotient, secantApproximation(IntervalFunctions.>byBoundingError( 1e-6, Duration.SECOND, Duration.HOUR.times(24), errorByOptimization()))); @@ -161,8 +161,8 @@ public final class Demo { // Example of a locking state: - MutableResource> importantHardware = DiscreteResources.discreteMutableResource(42); - MutableResource>> importantHardwareLock = DiscreteResources.discreteMutableResource(Optional.empty()); + MutableResource> importantHardware = DiscreteResources.discreteResource(42); + MutableResource>> importantHardwareLock = DiscreteResources.discreteResource(Optional.empty()); Resource> importantHardwareLockAssertion = assertThat( "Important hardware does not change state while locked", map(importantHardwareLock, importantHardware, (lock, state) -> lock.map(state::equals).orElse(true))); diff --git a/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/modeling/discrete/DiscreteResources.java b/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/modeling/discrete/DiscreteResources.java index d88df64798..bc13f99814 100644 --- a/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/modeling/discrete/DiscreteResources.java +++ b/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/modeling/discrete/DiscreteResources.java @@ -48,18 +48,18 @@ public static Resource> constant(T value) { } // General discrete cell resource constructor - public static MutableResource> discreteMutableResource(T initialValue) { + public static MutableResource> discreteResource(T initialValue) { return resource(discrete(initialValue)); } // Annoyingly, we need to repeat the specialization for integer resources, so that // discreteMutableResource(42) doesn't become a double resource, due to the next overload - public static MutableResource> discreteMutableResource(int initialValue) { + public static MutableResource> discreteResource(int initialValue) { return resource(discrete(initialValue)); } // specialized constructor for doubles, because they require a toleranced equality comparison - public static MutableResource> discreteMutableResource(double initialValue) { + public static MutableResource> discreteResource(double initialValue) { return resource(discrete(initialValue), autoEffects(testing( (CommutativityTestInput> input) -> DoubleUtils.areEqualResults( input.original().extract(), @@ -111,7 +111,7 @@ public static Resource> cache(Resource> resource, Bi * Sample valueSupplier once every samplePeriod. */ public static > Resource> sampled(Supplier valueSupplier, Resource samplePeriod) { - var result = discreteMutableResource(valueSupplier.get()); + var result = discreteResource(valueSupplier.get()); every(() -> currentValue(samplePeriod, Duration.MAX_VALUE), () -> set(result, valueSupplier.get())); return result; diff --git a/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/modeling/polynomial/PolynomialResources.java b/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/modeling/polynomial/PolynomialResources.java index f1658da4ba..9f533a707a 100644 --- a/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/modeling/polynomial/PolynomialResources.java +++ b/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/modeling/polynomial/PolynomialResources.java @@ -71,11 +71,11 @@ public static UnitAware> constant(UnitAware quantit return result; } - public static MutableResource polynomialMutableResource(double... initialCoefficients) { - return polynomialMutableResource(polynomial(initialCoefficients)); + public static MutableResource polynomialResource(double... initialCoefficients) { + return polynomialResource(polynomial(initialCoefficients)); } - public static MutableResource polynomialMutableResource(Polynomial initialDynamics) { + public static MutableResource polynomialResource(Polynomial initialDynamics) { return resource(initialDynamics, autoEffects(testing( (CommutativityTestInput input) -> { Polynomial original = input.original(); diff --git a/examples/streamline-demo/src/main/java/gov/nasa/jpl/aerie/streamline_demo/ApproximationModel.java b/examples/streamline-demo/src/main/java/gov/nasa/jpl/aerie/streamline_demo/ApproximationModel.java index 17e81f9122..b7355f0b35 100644 --- a/examples/streamline-demo/src/main/java/gov/nasa/jpl/aerie/streamline_demo/ApproximationModel.java +++ b/examples/streamline-demo/src/main/java/gov/nasa/jpl/aerie/streamline_demo/ApproximationModel.java @@ -47,8 +47,8 @@ public class ApproximationModel { public ApproximationModel(final Registrar registrar, final Configuration config) { final double tolerance = config.approximationTolerance; - polynomial = polynomialMutableResource(1); - divisor = polynomialMutableResource(1); + polynomial = polynomialResource(1); + divisor = polynomialResource(1); assumedLinear = assumeLinear(polynomial); defaultApproximation = approximateAsLinear(polynomial, tolerance); diff --git a/examples/streamline-demo/src/main/java/gov/nasa/jpl/aerie/streamline_demo/DataModel.java b/examples/streamline-demo/src/main/java/gov/nasa/jpl/aerie/streamline_demo/DataModel.java index c63624993a..d4b6d98822 100644 --- a/examples/streamline-demo/src/main/java/gov/nasa/jpl/aerie/streamline_demo/DataModel.java +++ b/examples/streamline-demo/src/main/java/gov/nasa/jpl/aerie/streamline_demo/DataModel.java @@ -24,14 +24,14 @@ import static gov.nasa.jpl.aerie.contrib.streamline.modeling.polynomial.PolynomialResources.greaterThanOrEquals; import static gov.nasa.jpl.aerie.contrib.streamline.modeling.polynomial.PolynomialResources.lessThanOrEquals; import static gov.nasa.jpl.aerie.contrib.streamline.modeling.polynomial.PolynomialResources.max; -import static gov.nasa.jpl.aerie.contrib.streamline.modeling.polynomial.PolynomialResources.polynomialMutableResource; +import static gov.nasa.jpl.aerie.contrib.streamline.modeling.polynomial.PolynomialResources.polynomialResource; import static gov.nasa.jpl.aerie.contrib.streamline.modeling.polynomial.PolynomialResources.subtract; public class DataModel { - public MutableResource desiredRateA = PolynomialResources.polynomialMutableResource(0); - public MutableResource desiredRateB = PolynomialResources.polynomialMutableResource(0); - public MutableResource desiredRateC = PolynomialResources.polynomialMutableResource(0); - public MutableResource upperBoundOnTotalVolume = PolynomialResources.polynomialMutableResource(10); + public MutableResource desiredRateA = PolynomialResources.polynomialResource(0); + public MutableResource desiredRateB = PolynomialResources.polynomialResource(0); + public MutableResource desiredRateC = PolynomialResources.polynomialResource(0); + public MutableResource upperBoundOnTotalVolume = PolynomialResources.polynomialResource(10); public Resource actualRateA, actualRateB, actualRateC; public MutableResource volumeA, volumeB, volumeC; @@ -51,9 +51,9 @@ public DataModel(final Registrar registrar, final Configuration config) { this.actualRateC = rateC.resource(); // Use a simple feedback loop on volumes to do the integration and clamping. - this.volumeA = PolynomialResources.polynomialMutableResource(0); - this.volumeB = PolynomialResources.polynomialMutableResource(0); - this.volumeC = PolynomialResources.polynomialMutableResource(0); + this.volumeA = PolynomialResources.polynomialResource(0); + this.volumeB = PolynomialResources.polynomialResource(0); + this.volumeC = PolynomialResources.polynomialResource(0); var clampedVolumeA = clamp(this.volumeA, constant(0), upperBoundOnTotalVolume); var volumeB_ub = subtract(upperBoundOnTotalVolume, clampedVolumeA); var clampedVolumeB = clamp(this.volumeB, constant(0), volumeB_ub); diff --git a/examples/streamline-demo/src/main/java/gov/nasa/jpl/aerie/streamline_demo/ErrorTestingModel.java b/examples/streamline-demo/src/main/java/gov/nasa/jpl/aerie/streamline_demo/ErrorTestingModel.java index 1d1637101e..f06aa4986f 100644 --- a/examples/streamline-demo/src/main/java/gov/nasa/jpl/aerie/streamline_demo/ErrorTestingModel.java +++ b/examples/streamline-demo/src/main/java/gov/nasa/jpl/aerie/streamline_demo/ErrorTestingModel.java @@ -10,25 +10,25 @@ import gov.nasa.jpl.aerie.contrib.streamline.modeling.polynomial.Polynomial; import gov.nasa.jpl.aerie.contrib.streamline.modeling.polynomial.PolynomialResources; -import static gov.nasa.jpl.aerie.contrib.streamline.modeling.discrete.DiscreteResources.discreteMutableResource; +import static gov.nasa.jpl.aerie.contrib.streamline.modeling.discrete.DiscreteResources.discreteResource; import static gov.nasa.jpl.aerie.contrib.streamline.modeling.discrete.monads.DiscreteResourceMonad.map; import static gov.nasa.jpl.aerie.contrib.streamline.modeling.polynomial.PolynomialResources.asPolynomial; import static gov.nasa.jpl.aerie.contrib.streamline.modeling.polynomial.PolynomialResources.clamp; import static gov.nasa.jpl.aerie.contrib.streamline.modeling.polynomial.PolynomialResources.constant; import static gov.nasa.jpl.aerie.contrib.streamline.modeling.polynomial.PolynomialResources.multiply; -import static gov.nasa.jpl.aerie.contrib.streamline.modeling.polynomial.PolynomialResources.polynomialMutableResource; +import static gov.nasa.jpl.aerie.contrib.streamline.modeling.polynomial.PolynomialResources.polynomialResource; public class ErrorTestingModel { - public MutableResource> bool = DiscreteResources.discreteMutableResource(true); - public MutableResource> counter = DiscreteResources.discreteMutableResource(5); - public MutableResource continuous = PolynomialResources.polynomialMutableResource(1); + public MutableResource> bool = DiscreteResources.discreteResource(true); + public MutableResource> counter = DiscreteResources.discreteResource(5); + public MutableResource continuous = PolynomialResources.polynomialResource(1); public Resource derived = multiply( continuous, asPolynomial(map(counter, c -> (double) c)), asPolynomial(map(bool, $ -> $ ? 1.0 : -1.0))); - public MutableResource upperBound = PolynomialResources.polynomialMutableResource(5); - public MutableResource lowerBound = PolynomialResources.polynomialMutableResource(-5); + public MutableResource upperBound = PolynomialResources.polynomialResource(5); + public MutableResource lowerBound = PolynomialResources.polynomialResource(-5); public Resource clamped = clamp(constant(10), lowerBound, upperBound); public ErrorTestingModel(final Registrar registrar, final Configuration config) {