diff --git a/lib/core/tools/Add-IcingaHashtableItem.psm1 b/lib/core/tools/Add-IcingaHashtableItem.psm1 new file mode 100644 index 0000000..49a2b0e --- /dev/null +++ b/lib/core/tools/Add-IcingaHashtableItem.psm1 @@ -0,0 +1,24 @@ +function Add-IcingaHashtableItem() +{ + param( + $Hashtable, + $Key, + $Value, + [switch]$Override + ); + + if ($null -eq $Hashtable) { + return $FALSE; + } + + if ($Hashtable.ContainsKey($Key) -eq $FALSE) { + $Hashtable.Add($Key, $Value); + return $TRUE; + } else { + if ($Override) { + $Hashtable[$Key] = $Value; + return $TRUE; + } + } + return $FALSE; +} diff --git a/lib/core/tools/Pop-IcingaArrayListItem.psm1 b/lib/core/tools/Pop-IcingaArrayListItem.psm1 new file mode 100644 index 0000000..b6ed815 --- /dev/null +++ b/lib/core/tools/Pop-IcingaArrayListItem.psm1 @@ -0,0 +1,19 @@ +function Pop-IcingaArrayListItem() +{ + param( + [System.Collections.ArrayList]$Array + ); + + if ($null -eq $Array) { + return $null; + } + + if ($Array.Count -eq 0) { + return $null; + } + + $Content = $Array[0]; + $Array.RemoveAt(0); + + return $Content; +} diff --git a/lib/core/tools/Remove-IcingaHashtableItem.psm1 b/lib/core/tools/Remove-IcingaHashtableItem.psm1 new file mode 100644 index 0000000..8be4987 --- /dev/null +++ b/lib/core/tools/Remove-IcingaHashtableItem.psm1 @@ -0,0 +1,15 @@ +function Remove-IcingaHashtableItem() +{ + param( + $Hashtable, + $Key + ); + + if ($null -eq $Hashtable) { + return; + } + + if ($Hashtable.ContainsKey($Key)) { + $Hashtable.Remove($Key); + } +}