31 lines
885 B
Python
31 lines
885 B
Python
from typing import List, Set
|
|
|
|
|
|
class CategoryManager:
|
|
def __init__(self):
|
|
self._categories: Set[str] = set()
|
|
|
|
@property
|
|
def categories(self) -> List[str]:
|
|
return sorted(list(self._categories))
|
|
|
|
def add_category(self, category: str) -> bool:
|
|
if not category or category in self._categories:
|
|
return False
|
|
self._categories.add(category)
|
|
return True
|
|
|
|
def remove_category(self, category: str) -> bool:
|
|
if category not in self._categories:
|
|
return False
|
|
self._categories.remove(category)
|
|
return True
|
|
|
|
def has_category(self, category: str) -> bool:
|
|
return category in self._categories
|
|
|
|
def load_from_data(self, categories: List[str]):
|
|
self._categories = set(categories)
|
|
|
|
def to_list(self) -> List[str]:
|
|
return self.categories |