Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/package/.pages
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
nav:
- ...
- stringutils: stringutils.md
- booleanutils: booleanutils.md

title: Package Documentation
1 change: 1 addition & 0 deletions docs/package/booleanutils.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: pycommons.lang.booleanutils
3 changes: 2 additions & 1 deletion pycommons/lang/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from importlib_metadata import PackageNotFoundError, version

from .arrayutils import ArrayUtils
from .booleanutils import BooleanUtils
from .charutils import CharUtils
from .stringutils import StringUtils

Expand All @@ -13,7 +14,7 @@
"__version__",
"ArrayUtils",
"CharUtils",
"StringUtils",
"BooleanUtils",
]

__author__ = "Shashank Sharma"
Expand Down
15 changes: 14 additions & 1 deletion pycommons/lang/arrayutils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
from typing import Sized, Optional
from typing import Sized, Optional, TypeVar

from pycommons.base.utils import ObjectUtils

from pycommons.lang.exception.exceptionutils import ExceptionUtils

_E = TypeVar("_E", Exception, RuntimeError)


class ArrayUtils:
Expand All @@ -13,3 +19,10 @@ def is_empty(cls, arr: Optional[Sized]) -> bool:
@classmethod
def is_not_empty(cls, arr: Optional[Sized]) -> bool:
return not cls.is_empty(arr)

@classmethod
def require_not_empty(cls, arr: Optional[Sized], e: Optional[_E] = None) -> None:
if cls.is_empty(arr):
ExceptionUtils.raise_error(
ObjectUtils.default_if_none(e, ValueError("Sized object cannot be empty"))
)
Loading