Skip to content

Commit

Permalink
Merge pull request #13 from Profpatsch/use-auto-derived-equals
Browse files Browse the repository at this point in the history
Use kotlin auto-derived equals
  • Loading branch information
Profpatsch authored Dec 21, 2024
2 parents 6f6d224 + 3405892 commit d6769f0
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 100 deletions.
10 changes: 0 additions & 10 deletions new-player/src/main/java/net/newpipe/newplayer/data/Stream.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,4 @@ data class Stream(
val audioStreamTrack: List<AudioStreamTrack>
get() = streamTracks.filterIsInstance<AudioStreamTrack>()

override fun equals(other: Any?) = other is Stream && other.hashCode() == this.hashCode()

override fun hashCode(): Int {
var result = item.hashCode()
result = 31 * result + streamUri.hashCode()
result = 31 * result + streamTracks.hashCode()
result = 31 * result + (mimeType?.hashCode() ?: 0)
return result
}

}
23 changes: 0 additions & 23 deletions new-player/src/main/java/net/newpipe/newplayer/data/StreamTrack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,6 @@ data class VideoStreamTrack(

override fun toLongIdentifierString() = "$fileFormat ${toShortIdentifierString()}"

override fun equals(other: Any?) =
other is VideoStreamTrack
&& other.hashCode() == this.hashCode()

override fun hashCode(): Int {
var result = width
result = 31 * result + height
result = 31 * result + frameRate
result = 31 * result + fileFormat.hashCode()
return result
}

override fun compareTo(other: StreamTrack) =
if (other is VideoStreamTrack) {
val diff = width * height - other.width * other.height
Expand Down Expand Up @@ -101,17 +89,6 @@ data class AudioStreamTrack(
-1
}

override fun equals(other: Any?) =
other is AudioStreamTrack
&& other.hashCode() == this.hashCode()

override fun hashCode(): Int {
var result = bitrate
result = 31 * result + language.hashCode()
result = 31 * result + fileFormat.hashCode()
return result
}

override fun toString() = """
AudioStreamTrack {
bitrate = $bitrate
Expand Down
11 changes: 0 additions & 11 deletions new-player/src/main/java/net/newpipe/newplayer/data/VideoSize.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,6 @@ internal data class VideoSize(

override fun compareTo(other: VideoSize) = width * height - other.width * other.height

override fun equals(other: Any?) =
when (other) {
is VideoSize ->
other.width == this.width && other.height == this.height && pixelWidthHeightRatio == other.pixelWidthHeightRatio

else -> false
}

override fun hashCode() =
width + height * 999999 + (pixelWidthHeightRatio*10000).toInt()

fun getRatio() =
(width * pixelWidthHeightRatio) / height

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ internal interface SeekerDimensions {
@Immutable

/** @hide */
internal class DefaultSeekerDimensions(
internal data class DefaultSeekerDimensions(
val trackHeight: Dp,
val progressHeight: Dp,
val gap: Dp,
Expand All @@ -234,36 +234,12 @@ internal class DefaultSeekerDimensions(
override fun thumbRadius(): State<Dp> {
return rememberUpdatedState(thumbRadius)
}

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other == null || this::class != other::class) return false

other as DefaultSeekerDimensions

if (trackHeight != other.trackHeight) return false
if (progressHeight != other.progressHeight) return false
if (gap != other.gap) return false
if (thumbRadius != other.thumbRadius) return false

return true
}

override fun hashCode(): Int {
var result = trackHeight.hashCode()

result = 31 * result + progressHeight.hashCode()
result = 31 * result + gap.hashCode()
result = 31 * result + thumbRadius.hashCode()

return result
}
}

@Immutable

/** @hide */
internal class DefaultSeekerColor(
internal data class DefaultSeekerColor(
val progressColor: Color,
val trackColor: Color,
val disabledTrackColor: Color,
Expand Down Expand Up @@ -299,34 +275,4 @@ internal class DefaultSeekerColor(
readAheadColor
)
}

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other == null || this::class != other::class) return false

other as DefaultSeekerColor

if (progressColor != other.progressColor) return false
if (trackColor != other.trackColor) return false
if (disabledTrackColor != other.disabledTrackColor) return false
if (disabledProgressColor != other.disabledProgressColor) return false
if (thumbColor != other.thumbColor) return false
if (disabledThumbColor != other.disabledThumbColor) return false
if (readAheadColor != other.readAheadColor) return false

return true
}

override fun hashCode(): Int {
var result = progressColor.hashCode()

result = 31 * result + trackColor.hashCode()
result = 31 * result + disabledTrackColor.hashCode()
result = 31 * result + disabledProgressColor.hashCode()
result = 31 * result + thumbColor.hashCode()
result = 31 * result + disabledThumbColor.hashCode()
result = 31 * result + readAheadColor.hashCode()

return result
}
}

0 comments on commit d6769f0

Please sign in to comment.