Skip to content
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

Generated equals and hash #72

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/Famix-Queries/FQAbstractQuery.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,12 @@ FQAbstractQuery >> & anotherQuery [

{ #category : #comparing }
FQAbstractQuery >> = anObject [
"Answer whether the receiver and anObject represent the same object."

^ self class == anObject class and: [
self hasSameParametersAs: anObject ]
self == anObject ifTrue: [ ^ true ].
self class = anObject class ifFalse: [ ^ false ].
^ self name = anObject name and: [
self children asArray = anObject children asArray ]
]

{ #category : #composition }
Expand Down Expand Up @@ -95,6 +98,7 @@ FQAbstractQuery >> canBeNegated [

{ #category : #accessing }
FQAbstractQuery >> children [

^ children
]

Expand Down Expand Up @@ -138,8 +142,9 @@ FQAbstractQuery >> hasSameParametersAs: aQuery [

{ #category : #comparing }
FQAbstractQuery >> hash [
"Answer an integer value that is related to the identity of the receiver."

^ (name hash bitXor: result hash) bitXor: children hash
^ name hash bitXor: children hash
]

{ #category : #initialization }
Expand Down
2 changes: 1 addition & 1 deletion src/Famix-Queries/FQComplementQuery.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ FQComplementQuery >> displayOn: aStream [
{ #category : #accessing }
FQComplementQuery >> hasSameParametersAs: aQuery [

^ aQuery queryToNegate hasSameParametersAs: queryToNegate
^ aQuery queryToNegate = queryToNegate
]

{ #category : #comparing }
Expand Down
2 changes: 1 addition & 1 deletion src/Famix-Queries/FQNAryQuery.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ FQNAryQuery >> hasSameParametersAs: aQuery [
self subqueries
with: aQuery subqueries
do: [ :parent :comparedParent |
(parent hasSameParametersAs: comparedParent)
(parent = comparedParent)
ifFalse: [ ^ false ] ].
^ true
]
Expand Down
14 changes: 12 additions & 2 deletions src/Famix-Queries/FQNavigationQuery.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ FQNavigationQuery class >> outgoing [
yourself
]

{ #category : #comparing }
FQNavigationQuery >> = anObject [
"Answer whether the receiver and anObject represent the same object."

^ super = anObject and: [
directionStrategy = anObject directionStrategy and: [
associationStrategy = anObject associationStrategy ] ]
]

{ #category : #'adding - removing' }
FQNavigationQuery >> addAssociation: anAssociation [
(self associationsIsValid: anAssociation)
Expand Down Expand Up @@ -220,9 +229,10 @@ FQNavigationQuery >> hasSameParametersAs: aQuery [

{ #category : #comparing }
FQNavigationQuery >> hash [
"Answer an integer value that is related to the identity of the receiver."

^ (super hash bitXor: directionStrategy hash) bitXor:
associationStrategy hash
^ super hash bitXor:
(directionStrategy hash bitXor: associationStrategy hash)
]

{ #category : #initialization }
Expand Down
21 changes: 21 additions & 0 deletions src/Famix-Queries/FQNullQuery.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ Class {
#category : #'Famix-Queries-Core'
}

{ #category : #comparing }
FQNullQuery >> = anObject [
"Answer whether the receiver and anObject represent the same object."

self == anObject ifTrue: [ ^ true ].
self class = anObject class ifFalse: [ ^ false ].
^ true
]

{ #category : #printing }
FQNullQuery >> buildDefaultName [

^ self defaultName
]

{ #category : #running }
FQNullQuery >> computeResult [

Expand All @@ -31,6 +46,12 @@ FQNullQuery >> hasSameParametersAs: aQuery [
^ self class == aQuery class
]

{ #category : #comparing }
FQNullQuery >> hash [

^ self name hash
]

{ #category : #testing }
FQNullQuery >> isValid [

Expand Down
11 changes: 10 additions & 1 deletion src/Famix-Queries/FQNumericQuery.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ FQNumericQuery class >> type [
^ FM3Number
]

{ #category : #comparing }
FQNumericQuery >> = anObject [
"Answer whether the receiver and anObject represent the same object."

^ super = anObject and: [
valueToCompare = anObject valueToCompare and: [
comparator = anObject comparator ] ]
]

{ #category : #comparing }
FQNumericQuery >> hasSameParametersAs: aQuery [
^ (super hasSameParametersAs: aQuery)
Expand All @@ -84,7 +93,7 @@ FQNumericQuery >> hasSameParametersAs: aQuery [
{ #category : #comparing }
FQNumericQuery >> hash [

^ (super hash bitXor: valueToCompare hash) bitXor: comparator hash
^ super hash bitXor: (valueToCompare hash bitXor: comparator hash)
]

{ #category : #testing }
Expand Down
9 changes: 9 additions & 0 deletions src/Famix-Queries/FQPropertyQuery.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ FQPropertyQuery class >> type [
^ self subclassResponsibility
]

{ #category : #comparing }
FQPropertyQuery >> = anObject [
"Answer whether the receiver and anObject represent the same object."

^ super = anObject and: [ property = anObject property ]
]

{ #category : #running }
FQPropertyQuery >> applyComparatorOnEntityProperty: entityProperty [
"default is to compare the #property of an entity to the #valueToCompare of the query"
Expand Down Expand Up @@ -146,6 +153,7 @@ FQPropertyQuery >> displayOn: aStream with: aString [

{ #category : #testing }
FQPropertyQuery >> hasComparisonParameters [

^ true
]

Expand All @@ -156,6 +164,7 @@ FQPropertyQuery >> hasSameParametersAs: aQuery [

{ #category : #comparing }
FQPropertyQuery >> hash [
"Answer an integer value that is related to the identity of the receiver."

^ super hash bitXor: property hash
]
Expand Down
8 changes: 8 additions & 0 deletions src/Famix-Queries/FQRelationQuery.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ FQRelationQuery class >> name: aFamixType [
yourself
]

{ #category : #comparing }
FQRelationQuery >> = anObject [
"Answer whether the receiver and anObject represent the same object."

^ super = anObject and: [ relationName = anObject relationName ]
]

{ #category : #'available parameters' }
FQRelationQuery >> availableRelationNames [

Expand Down Expand Up @@ -96,6 +103,7 @@ FQRelationQuery >> hasSameParametersAs: aQuery [

{ #category : #comparing }
FQRelationQuery >> hash [
"Answer an integer value that is related to the identity of the receiver."

^ super hash bitXor: relationName hash
]
Expand Down
21 changes: 18 additions & 3 deletions src/Famix-Queries/FQResultSizeQuery.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ FQResultSizeQuery class >> label [
^ 'Result Size Query'
]

{ #category : #comparing }
FQResultSizeQuery >> = anObject [
"Answer whether the receiver and anObject represent the same object."

self == anObject ifTrue: [ ^ true ].
self class = anObject class ifFalse: [ ^ false ].
^ comparator = anObject comparator and: [
innerQuery = anObject innerQuery and: [
valueToCompare = anObject valueToCompare ] ]
]

{ #category : #default }
FQResultSizeQuery >> beDefaultForParent [

Expand Down Expand Up @@ -77,16 +88,20 @@ FQResultSizeQuery >> displayOn: aStream with: aString [
{ #category : #comparing }
FQResultSizeQuery >> hasSameParametersAs: aQuery [

^ (innerQuery hasSameParametersAs: aQuery innerQuery) and: [
^ (innerQuery
ifNil: [ aQuery innerQuery isNil ]
ifNotNil: [ innerQuery = aQuery innerQuery ]) and: [
comparator = aQuery comparator and:
valueToCompare = aQuery valueToCompare ]
]

{ #category : #comparing }
FQResultSizeQuery >> hash [
"Answer an integer value that is related to the identity of the receiver."

^ ((super hash bitXor: innerQuery hash) bitXor: comparator hash)
bitXor: valueToCompare hash
^ super hash bitXor:
(comparator hash bitXor:
(valueToCompare hash bitXor: innerQuery hash))
]

{ #category : #accessing }
Expand Down
6 changes: 0 additions & 6 deletions src/Famix-Queries/FQRootQuery.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ FQRootQuery >> hasSameParametersAs: aQuery [
^ true
]

{ #category : #comparing }
FQRootQuery >> hash [

^ super hash bitXor: input hash
]

{ #category : #initialization }
FQRootQuery >> initialize [

Expand Down
15 changes: 13 additions & 2 deletions src/Famix-Queries/FQScopeQuery.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ FQScopeQuery class >> upTo: aScope [
yourself
]

{ #category : #comparing }
FQScopeQuery >> = anObject [
"Answer whether the receiver and anObject represent the same object."

^ super = anObject and: [
recursive = anObject recursive and: [
scope = anObject scope and: [
direction = anObject directionStrategy ] ] ]
]

{ #category : #'available parameters' }
FQScopeQuery >> availableScopes [
self flag: #FQTest.
Expand Down Expand Up @@ -171,9 +181,10 @@ FQScopeQuery >> hasSameParametersAs: aQuery [

{ #category : #comparing }
FQScopeQuery >> hash [
"Answer an integer value that is related to the identity of the receiver."

^ ((super hash bitXor: scope hash) bitXor: direction hash) bitXor:
recursive hash
^ super hash bitXor:
(recursive hash bitXor: (scope hash bitXor: direction hash))
]

{ #category : #initialization }
Expand Down
8 changes: 8 additions & 0 deletions src/Famix-Queries/FQScriptQuery.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ FQScriptQuery class >> script: aBlock [
yourself
]

{ #category : #comparing }
FQScriptQuery >> = anObject [
"Answer whether the receiver and anObject represent the same object."

^ super = anObject and: [ script = anObject script ]
]

{ #category : #printing }
FQScriptQuery >> displayOn: aStream with: aString [
^ aStream << aString << Character space << self defaultName
Expand All @@ -31,6 +38,7 @@ FQScriptQuery >> hasSameParametersAs: aQuery [

{ #category : #comparing }
FQScriptQuery >> hash [
"Answer an integer value that is related to the identity of the receiver."

^ super hash bitXor: script hash
]
Expand Down
11 changes: 10 additions & 1 deletion src/Famix-Queries/FQStringQuery.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ FQStringQuery class >> type [
^ FM3String
]

{ #category : #comparing }
FQStringQuery >> = anObject [
"Answer whether the receiver and anObject represent the same object."

^ super = anObject and: [
valueToCompare = anObject valueToCompare and: [
comparator = anObject comparator ] ]
]

{ #category : #comparing }
FQStringQuery >> hasSameParametersAs: aQuery [
^ (super hasSameParametersAs: aQuery)
Expand All @@ -85,7 +94,7 @@ FQStringQuery >> hasSameParametersAs: aQuery [
{ #category : #comparing }
FQStringQuery >> hash [

^ (super hash bitXor: valueToCompare hash) bitXor: comparator hash
^ super hash bitXor: (valueToCompare hash bitXor: comparator hash)
]

{ #category : #testing }
Expand Down
8 changes: 8 additions & 0 deletions src/Famix-Queries/FQTaggedEntityQuery.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ FQTaggedEntityQuery class >> tagNamed: aTagName [
yourself
]

{ #category : #comparing }
FQTaggedEntityQuery >> = anObject [
"Answer whether the receiver and anObject represent the same object."

^ super = anObject and: [ tagName = anObject tagName ]
]

{ #category : #'available parameters' }
FQTaggedEntityQuery >> availableTagNames [

Expand Down Expand Up @@ -104,6 +111,7 @@ FQTaggedEntityQuery >> hasSameParametersAs: aQuery [

{ #category : #comparing }
FQTaggedEntityQuery >> hash [
"Answer an integer value that is related to the identity of the receiver."

^ super hash bitXor: tagName hash
]
Expand Down
8 changes: 8 additions & 0 deletions src/Famix-Queries/FQTypeQuery.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ FQTypeQuery class >> types: aCollectionOfTypes [
yourself
]

{ #category : #comparing }
FQTypeQuery >> = anObject [
"Answer whether the receiver and anObject represent the same object."

^ super = anObject and: [ types = anObject types ]
]

{ #category : #'adding - removing' }
FQTypeQuery >> addType: aType [
(self types includes: aType)
Expand Down Expand Up @@ -127,6 +134,7 @@ FQTypeQuery >> hasSameParametersAs: aQuery [

{ #category : #comparing }
FQTypeQuery >> hash [
"Answer an integer value that is related to the identity of the receiver."

^ super hash bitXor: types hash
]
Expand Down
Loading