Skip to content

Jules WIP: Refactor constructors to static factory methods. #1460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

cpovirk
Copy link
Member

@cpovirk cpovirk commented Jun 5, 2025

No description provided.

… done so far and provide feedback for Jules to continue.
Made constructors private and introduced package-private static factory methods for the following classes:

- Transforming in com.google.common.truth.Correspondence
- ComparisonFailureWithFacts in com.google.common.truth.ComparisonFailureWithFacts (including GWT-specific version and reflective call site)
- ComparisonResult in com.google.common.truth.Subject
- MapInOrder in com.google.common.truth.MapSubject
- StoredException in com.google.common.truth.Correspondence

All internal constructor call sites within their respective parent classes have been updated to use the new factory methods.
This commit refactors a number of nested classes to use private constructors and package-private static factory methods.

The following classes were updated:
- FormattingDiffs in com.google.common.truth.Correspondence
- FromBinaryPredicate in com.google.common.truth.Correspondence
- HopcroftKarp in com.google.common.truth.GraphMatching
- IterableEntries in com.google.common.truth.MultimapSubject
- NonHashingMultiset in com.google.common.truth.SubjectUtils
- Pairer in com.google.common.truth.IterableSubject
- Pairing in com.google.common.truth.IterableSubject
- TolerantNumericEquality in com.google.common.truth.Correspondence
- ValueDifference in com.google.common.truth.MapSubject
- DoubleArrayAsIterable in com.google.common.truth.PrimitiveDoubleArraySubject
- DuplicateGroupedAndTyped in com.google.common.truth.SubjectUtils
- FloatArrayAsIterable in com.google.common.truth.PrimitiveFloatArraySubject
- LazyMessage in com.google.common.truth.LazyMessage (including external call sites)
- MultimapInOrder in com.google.common.truth.MultimapSubject
- TolerantDoubleComparison in com.google.common.truth.DoubleSubject
- TolerantFloatComparison in com.google.common.truth.FloatSubject
- TolerantIntegerComparison in com.google.common.truth.IntegerSubject
- TolerantLongComparison in com.google.common.truth.LongSubject
- Transforming in com.google.common.truth.Correspondence
- ComparisonFailureWithFacts in com.google.common.truth.ComparisonFailureWithFacts (including GWT-specific version and reflective call in Platform.java)
- ComparisonResult in com.google.common.truth.Subject
- MapInOrder in com.google.common.truth.MapSubject
- StoredException in com.google.common.truth.Correspondence
- UsingCorrespondence in com.google.common.truth.MapSubject
- UsingCorrespondence in com.google.common.truth.MultimapSubject

The constructors of these classes were made private, and package-private static factory methods (usually named 'create') were introduced to encapsulate object creation. All internal and relevant external call sites were updated to use these factory methods.

This change improves encapsulation and provides a clear entry point for instantiation, potentially allowing for future flexibility in object creation (e.g., caching, subclassing with different strategies) without altering the public API of the factory method.

Two classes, SortedMapAsNavigableMap and SortedSetAsNavigableSet, were skipped as they were confirmed to be obsolete. The UsingCorrespondence class within IterableSubject.java was also skipped as per your specific request.
@cpovirk cpovirk self-assigned this Jun 5, 2025
@cpovirk cpovirk added the P2 has an ETA label Jun 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 has an ETA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant