Skip to content

Resolve numerous warnings - #92

Merged
amorison merged 17 commits into
masterfrom
am/warnings
Jul 27, 2026
Merged

Resolve numerous warnings#92
amorison merged 17 commits into
masterfrom
am/warnings

Conversation

@amorison

Copy link
Copy Markdown
Collaborator

This mainly focuses on type-related warnings, in particular reducing the amount of raw types and unchecked operations.

amorison added 16 commits July 13, 2026 18:15
When a function expects an `fn(Object... args)` set of arguments,
calling

- `fn(T[] array)` casts the array to an `Object[]`
- `fn(null)` is equivalent to `fn()`

for backward compatibility when varargs weren't a thing in Java and
functions expected an `Object[] args` instead. This however comes with a
warning due to the ambiguity with passing that `T[]` or `null` as a
single object that would be the only item in `args`. This commit resolves
those warnings.
This tightens type annotation to make them correct and eliminates some
unchecked conversion warnings.
This new type holds the information about each series, instead of
that information being stored in a `Map` with no type information.
This resolves numerous warnings regarding types.
This is far from ideal as this should be made generic over the key and
value type as well as leverage composition.

This commit is still useful in itself to avoid many warnings.
This avoids using a poorly typed API from jfree.
@amorison

Copy link
Copy Markdown
Collaborator Author

SimPaths tests pass with minor modifications: simpaths/SimPaths#479

@dav-sonn It would be great if you could have a look at these changes. They're mostly about limiting the use of raw types (i.e. unspecified generics, such as List instead of List<T>). simpaths/SimPaths#479 (not for merging, I use this for tests) shows the necessary changes to SimPaths in Parameters.java. Because MultiKeyCoefficientMap now inherits from MultiKeyMap<Object, Object> instead of the raw MultiKeyMap, some type information is surfaced when using it from SimPaths, removing the need for casting by hand the keys into MultiKey<> instances.

If the changes both in this PR and in the testing PR seem acceptable to you, I'll then create a release of jasmine and open a PR in SimPaths with the appropriate changes to Parameters.java.

@amorison
amorison marked this pull request as ready for review July 21, 2026 14:33
@amorison
amorison requested a review from dav-sonn July 21, 2026 14:33
@dav-sonn

Copy link
Copy Markdown
Contributor

SimPaths tests pass with minor modifications: simpaths/SimPaths#479

@dav-sonn It would be great if you could have a look at these changes. They're mostly about limiting the use of raw types (i.e. unspecified generics, such as List instead of List<T>). simpaths/SimPaths#479 (not for merging, I use this for tests) shows the necessary changes to SimPaths in Parameters.java. Because MultiKeyCoefficientMap now inherits from MultiKeyMap<Object, Object> instead of the raw MultiKeyMap, some type information is surfaced when using it from SimPaths, removing the need for casting by hand the keys into MultiKey<> instances.

If the changes both in this PR and in the testing PR seem acceptable to you, I'll then create a release of jasmine and open a PR in SimPaths with the appropriate changes to Parameters.java.

I'll take a look at it tomorrow. I will get back to you as soon as I'm done.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reduces compiler warnings (primarily raw types / unchecked casts) across the microsim statistics, regression, matching, GUI, and data layers by tightening generics usage and cleaning up a few legacy constructs.

Changes:

  • Parameterized several previously-raw APIs and implementations (e.g., discrete choice model interface + regression models, matching helpers, Swing models/components).
  • Replaced a number of explicit casts / raw iterations with inferred typing (var) and safer typed collections.
  • Refactored Weighted_HistogramDataset internal storage away from a raw List of maps to a typed record-backed structure.

Reviewed changes

Copilot reviewed 59 out of 59 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/main/java/microsim/statistics/weighted/Weighted_CrossSection.java Removes stray commented-out duplicate package declaration.
src/main/java/microsim/statistics/weighted/IWeightedLongArraySource.java Removes stray commented-out duplicate package declaration.
src/main/java/microsim/statistics/weighted/IWeightedIntArraySource.java Removes stray commented-out duplicate package declaration.
src/main/java/microsim/statistics/weighted/IWeightedFloatArraySource.java Removes stray commented-out duplicate package declaration.
src/main/java/microsim/statistics/weighted/IWeightedDoubleArraySource.java Removes stray commented-out duplicate package declaration.
src/main/java/microsim/statistics/TimeSeries.java Removes unnecessary cast when returning a typed Series.
src/main/java/microsim/statistics/regression/RegressionUtils.java Reduces raw types/casts in MultiKeyCoefficientMap iteration; one comment block got mangled.
src/main/java/microsim/statistics/regression/OrderedRegression.java Implements generic IDiscreteChoiceModel<E1> and tightens probability APIs to E1.
src/main/java/microsim/statistics/regression/MultinomialRegression.java Implements generic IDiscreteChoiceModel<E1> and removes raw collections/casts.
src/main/java/microsim/statistics/regression/LinearRegression.java Removes raw iterator usage/casts via generic iteration and var.
src/main/java/microsim/statistics/regression/IDiscreteChoiceModel.java Makes the discrete choice interface generic over the event enum type.
src/main/java/microsim/statistics/regression/GeneralisedOrderedRegression.java Implements generic IDiscreteChoiceModel<E1> and removes raw collections/casts.
src/main/java/microsim/statistics/regression/BinomialRegression.java Implements generic IDiscreteChoiceModel<E1> and removes raw collections/casts.
src/main/java/microsim/statistics/reflectors/StringInvoker.java Replaces reflective invocation varargs null with no-arg invocation.
src/main/java/microsim/statistics/reflectors/LongInvoker.java Replaces reflective invocation varargs null with no-arg invocation.
src/main/java/microsim/statistics/reflectors/IntegerInvoker.java Replaces reflective invocation varargs null with no-arg invocation.
src/main/java/microsim/statistics/reflectors/FloatInvoker.java Replaces reflective invocation varargs null with no-arg invocation.
src/main/java/microsim/statistics/reflectors/DoubleInvoker.java Replaces reflective invocation varargs null with no-arg invocation.
src/main/java/microsim/space/SparseObjectSpace.java Removes redundant cast when reading a typed map entry key.
src/main/java/microsim/reflection/StringValueExtractor.java Replaces reflective invocation varargs null with no-arg invocation.
src/main/java/microsim/reflection/LongValueExtractor.java Replaces reflective invocation varargs null with no-arg invocation.
src/main/java/microsim/reflection/IntegerValueExtractor.java Replaces reflective invocation varargs null with no-arg invocation.
src/main/java/microsim/reflection/FloatValueExtractor.java Replaces reflective invocation varargs null with no-arg invocation.
src/main/java/microsim/reflection/DoubleValueExtractor.java Replaces reflective invocation varargs null with no-arg invocation.
src/main/java/microsim/matching/SimpleMatching.java Partially generifies singleton storage; adds suppression for raw singleton getter.
src/main/java/microsim/matching/IterativeSimpleMatching.java Partially generifies singleton storage; adds suppression for raw singleton getter.
src/main/java/microsim/matching/IterativeRandomMatching.java Partially generifies singleton storage; adds suppression for raw singleton getter and removes unused import.
src/main/java/microsim/matching/IterativeMatchingAlgorithm.java Removes stray commented-out duplicate package declaration.
src/main/java/microsim/matching/GlobalMatchingPairComparator.java Parameterizes comparator to avoid raw GlobalMatchingPair usage.
src/main/java/microsim/matching/GlobalMatching.java Removes raw candidate list usage/casts by using GlobalMatchingPair<T> end-to-end.
src/main/java/microsim/gui/utils/ImageGenerator.java Removes unnecessary cast in getOutput call.
src/main/java/microsim/gui/space/LayerObjectGridDrawer.java Removes redundant cast to int from IntegerInvoker.getInt().
src/main/java/microsim/gui/space/LayeredSurfaceProperties.java Parameterizes Swing components and simplifies iteration over layers.
src/main/java/microsim/gui/space/LayeredSurfacePanel.java Removes raw list casts and redundant numeric casts in coordinate math.
src/main/java/microsim/gui/space/LayeredSurfaceFrame.java Removes legacy commented UML dependency block.
src/main/java/microsim/gui/space/CellObjectChooser.java Parameterizes JList to avoid raw type warnings.
src/main/java/microsim/gui/shell/parameter/ParameterFrame.java Removes unused imports.
src/main/java/microsim/gui/shell/MicrosimShell.java Removes unused import.
src/main/java/microsim/gui/probe/ProbeFrame.java Parameterizes Swing components; simplifies panel refresh loop.
src/main/java/microsim/gui/probe/MethodsDataModel.java Parameterizes ListModel and removes redundant casts in method access/invocation.
src/main/java/microsim/gui/probe/MethodParameterDataModel.java Tightens reflective constructor signature typing (Class<?>[]).
src/main/java/microsim/gui/plot/Weighted_PyramidPlotter.java Removes unused legacy comment block and redundant casts on sources.
src/main/java/microsim/gui/plot/Weighted_PyramidDataset.java Parameterizes dataset keys to remove raw List/Comparable warnings.
src/main/java/microsim/gui/plot/Weighted_HistogramSimulationPlotter.java Removes stray commented-out duplicate package declaration and redundant casts.
src/main/java/microsim/gui/plot/Weighted_HistogramDataset.java Refactors internal series storage to typed HistEntry record and typed lists.
src/main/java/microsim/gui/plot/ScatterplotSimulationPlotterRefreshable.java Removes unused import and clears series via typed dataset accessors.
src/main/java/microsim/gui/plot/IndividualBarSimulationPlotter.java Removes unused import.
src/main/java/microsim/gui/plot/HistogramSimulationPlotter.java Removes redundant casts when pulling typed sources.
src/main/java/microsim/gui/plot/CollectionBarSimulationPlotter.java Removes redundant casts when pulling typed sources.
src/main/java/microsim/gui/colormap/TripleRangeColorMap.java Removes redundant (int) casts in integer arithmetic.
src/main/java/microsim/gui/colormap/DoubleRangeColorMap.java Removes redundant (int) casts in integer arithmetic.
src/main/java/microsim/event/SingleTargetEvent.java Uses no-arg reflective lookup/invoke (instead of passing null).
src/main/java/microsim/event/EventQueue.java Removes legacy commented UML dependency block.
src/main/java/microsim/event/CollectionTargetEvent.java Uses no-arg reflective lookup/invoke (instead of passing null).
src/main/java/microsim/engine/SimulationEngine.java Removes legacy commented UML dependency block; minor typing cleanup in arrays/varargs.
src/main/java/microsim/data/MultiKeyCoefficientMap.java Parameterizes MultiKeyMap inheritance and tightens MultiKey generic usage.
src/main/java/microsim/data/ExperimentManager.java Fixes static access warnings by referencing Experiment.inputFolder explicitly.
src/main/java/microsim/data/db/DatabaseUtils.java Parameterizes property map to avoid raw Map warnings.
src/main/java/microsim/alignment/multiple/LogitScalingAlignment.java Removes unused imports.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +54 to +55
record HistEntry(Comparable<?> key, List<Weighted_HistogramBin> bins, int numValues, double binWidth) {
}
Comment on lines +782 to +789
//// for(int i = 0; i < tNames.length; i++) { /
/// if(subStrings[0].equals(tNames[i])) { / covarianceEvents.add(subStrings[0]);
/// //Only check that first substring of / key before the 'regular expression'
/// "_" character is an event name. Thus if / LowEdu and HighEdu are events, and
/// the covariance matrix contains keys / LowEdu_age and HighEdu_age, this will
/// be satisfied, but not if the keys are / age_LowEdu and age_HighEdu. This is
/// to prevent confusion over what is the / event name and the covariate name. /
/// } / }
@dav-sonn

Copy link
Copy Markdown
Contributor

SimPaths tests pass with minor modifications: simpaths/SimPaths#479
@dav-sonn It would be great if you could have a look at these changes. They're mostly about limiting the use of raw types (i.e. unspecified generics, such as List instead of List<T>). simpaths/SimPaths#479 (not for merging, I use this for tests) shows the necessary changes to SimPaths in Parameters.java. Because MultiKeyCoefficientMap now inherits from MultiKeyMap<Object, Object> instead of the raw MultiKeyMap, some type information is surfaced when using it from SimPaths, removing the need for casting by hand the keys into MultiKey<> instances.
If the changes both in this PR and in the testing PR seem acceptable to you, I'll then create a release of jasmine and open a PR in SimPaths with the appropriate changes to Parameters.java.

I'll take a look at it tomorrow. I will get back to you as soon as I'm done.

I reviewed the PR, and from what I can tell, the changes look good. I also asked Copilot to review it if you want to take a quick look. Otherwise, feel free to merge it.

@amorison
amorison merged commit 0bc26c6 into master Jul 27, 2026
3 checks passed
@amorison
amorison deleted the am/warnings branch July 27, 2026 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants