@@ -27,7 +27,7 @@ private fun String.remove(type: String): String {
27
27
* @property uri retrieve this URI as a string
28
28
* @property id representation of this uri as an id
29
29
*/
30
- sealed class SpotifyUri (input : String , type : String ) {
30
+ sealed class SpotifyUri (input : String , type : UriType ) {
31
31
val uri: String
32
32
val id: String
33
33
@@ -37,8 +37,8 @@ sealed class SpotifyUri(input: String, type: String) {
37
37
this .uri = input
38
38
this .id = input
39
39
} else {
40
- this .uri = it.add(type)
41
- this .id = it.remove(type)
40
+ this .uri = it.add(type.toString() )
41
+ this .id = it.remove(type.toString() )
42
42
}
43
43
}
44
44
}
@@ -53,34 +53,49 @@ sealed class SpotifyUri(input: String, type: String) {
53
53
result = 31 * result + id.hashCode()
54
54
return result
55
55
}
56
+
57
+ enum class UriType (private val typeStr : String ) {
58
+ ALBUM (" album" ),
59
+ ARTIST (" artist" ),
60
+ TRACK (" track" ),
61
+ USER (" user" ),
62
+ PLAYLIST (" playlist" ),
63
+ LOCAL_TRACK (" local" );
64
+
65
+ override fun toString () = typeStr
66
+ }
67
+
68
+ companion object {
69
+ fun isUriType (uri : String , type : UriType ) = uri.matchType(type.toString()) != null
70
+ }
56
71
}
57
72
58
73
/* *
59
74
* Represents a Spotify **Album** URI, parsed from either a Spotify ID or taken from an endpoint.
60
75
*/
61
- class AlbumURI (input : String ) : SpotifyUri(input, " album " )
76
+ class AlbumURI (input : String ) : SpotifyUri(input, UriType . ALBUM )
62
77
63
78
/* *
64
79
* Represents a Spotify **Artist** URI, parsed from either a Spotify ID or taken from an endpoint.
65
80
*/
66
- class ArtistURI (input : String ) : SpotifyUri(input, " artist " )
81
+ class ArtistURI (input : String ) : SpotifyUri(input, UriType . ARTIST )
67
82
68
83
/* *
69
84
* Represents a Spotify **Track** URI, parsed from either a Spotify ID or taken from an endpoint.
70
85
*/
71
- class TrackURI (input : String ) : SpotifyUri(input, " track " )
86
+ class TrackURI (input : String ) : SpotifyUri(input, UriType . TRACK )
72
87
73
88
/* *
74
89
* Represents a Spotify **User** URI, parsed from either a Spotify ID or taken from an endpoint.
75
90
*/
76
- class UserURI (input : String ) : SpotifyUri(input, " user " )
91
+ class UserURI (input : String ) : SpotifyUri(input, UriType . USER )
77
92
78
93
/* *
79
94
* Represents a Spotify **Playlist** URI, parsed from either a Spotify ID or taken from an endpoint.
80
95
*/
81
- class PlaylistURI (input : String ) : SpotifyUri(input, " playlist " )
96
+ class PlaylistURI (input : String ) : SpotifyUri(input, UriType . PLAYLIST )
82
97
83
98
/* *
84
99
* Represents a Spotify **local track** URI
85
100
*/
86
- class LocalTrackURI (input : String ) : SpotifyUri(input, " local " )
101
+ class LocalTrackURI (input : String ) : SpotifyUri(input, UriType . LOCAL_TRACK )
0 commit comments