diff --git a/development/objects_collection.py b/development/objects_collection.py index c7526dc..642bb18 100644 --- a/development/objects_collection.py +++ b/development/objects_collection.py @@ -25,7 +25,7 @@ if __name__ == "__main__": album_1.merge(album_2) print() - print(album_1.artist_collection.data) + print(*(f"{a.title_string} ; {a.id}" for a in album_1.artist_collection.data), sep=" | ") print(id(album_1.artist_collection), id(album_2.artist_collection)) print(id(album_1.song_collection[0].main_artist_collection), id(album_2.song_collection[0].main_artist_collection)) \ No newline at end of file diff --git a/music_kraken/objects/collection.py b/music_kraken/objects/collection.py index c13a294..6b59ac9 100644 --- a/music_kraken/objects/collection.py +++ b/music_kraken/objects/collection.py @@ -76,106 +76,10 @@ class Collection(Generic[T]): del self._id_to_index_values[obj_id] - def _contained_in_self(self, __object: T) -> bool: - if __object.id in self._contains_ids: - return True - - for name, value in __object.indexing_values: - if value is None: - continue - if value == self._indexed_values[name]: - return True - return False - - def _contained_in_sub(self, __object: T, break_at_first: bool = True) -> List[Collection]: - """ - Gets the collection this object is found in, if it is found in any. - - :param __object: - :param break_at_first: - :return: - """ - results = [] - - if self._contained_in_self(__object): - return [self] - - for collection in self.children: - results.extend(collection._contained_in_sub(__object, break_at_first=break_at_first)) - - if break_at_first: - return results - - return results - - def _get_root_collections(self) -> List[Collection]: - if not len(self.parents): - return [self] - - root_collections = [] - for upper_collection in self.parents: - root_collections.extend(upper_collection._get_root_collections()) - return root_collections - @property - def _is_root(self) -> bool: + def is_root(self) -> bool: return len(self.parents) <= 0 - def _get_parents_of_multiple_contained_children(self, __object: T): - results = [] - if len(self.children) < 2 or self._contained_in_self(__object): - return results - - count = 0 - - for collection in self.children: - sub_results = collection._get_parents_of_multiple_contained_children(__object) - - if len(sub_results) > 0: - count += 1 - results.extend(sub_results) - - if count >= 2: - results.append(self) - - return results - - def merge_into_self(self, __object: T, from_map: bool = False): - """ - 1. find existing objects - 2. merge into existing object - 3. remap existing object - """ - if __object.id in self._contains_ids: - return - - existing_object: T = None - - for name, value in __object.indexing_values: - if value is None: - continue - - if value == self._indexed_values[name]: - existing_object = self._indexed_to_objects[value] - if existing_object.id == __object.id: - return None - - break - - if existing_object is None: - return None - - existing_object.merge(__object) - - # just a check if it really worked - if existing_object.id != __object.id: - raise ValueError("This should NEVER happen. Merging doesn't work.") - - self._map_element(existing_object, from_map=from_map) - - def contains(self, __object: T) -> bool: - return len(self._contained_in_sub(__object)) > 0 - def _find_object_in_self(self, __object: T) -> Optional[T]: for name, value in __object.indexing_values: if value == self._indexed_values[name]: diff --git a/music_kraken/objects/song.py b/music_kraken/objects/song.py index 93b39ba..2437112 100644 --- a/music_kraken/objects/song.py +++ b/music_kraken/objects/song.py @@ -93,7 +93,6 @@ class Song(Base): self.album_collection.append_object_to_attribute = { "song_collection": self, } - self.main_artist_collection.contain_given_in_attribute = { "main_album_collection": self.album_collection }