Skip to content

Commit

Permalink
Replacing var with fold call
Browse files Browse the repository at this point in the history
  • Loading branch information
devin-petersohn committed Apr 10, 2017
1 parent 6855c05 commit af70a8d
Showing 1 changed file with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -560,12 +560,30 @@ case class ReferenceRegion(
}

override def hashCode: Int = {
var result = 37
result = 41 * result + (if (referenceName != null) referenceName.hashCode else 0)
result = 41 * result + start.hashCode
result = 41 * result + end.hashCode
result = 41 * result + (if (strand != null) strand.ordinal() else 0)
result
// add 37 here because this is the start of the hashCode
val nameHashCode = 37 + {
if (referenceName != null) {
referenceName.hashCode
} else {
0
}
}
val strandHashCode =
if (strand != null) {
strand.ordinal()
} else {
0
}

val listOfHashCodes = List(nameHashCode, start.hashCode, end.hashCode, strandHashCode)

listOfHashCodes.foldLeft(1)((b, a) => {
if (b > 1) {
b * 41 + a
} else {
a
}
})
}
}

Expand Down

0 comments on commit af70a8d

Please sign in to comment.