mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
Added helper functions for Arrays and Hashtables
This commit is contained in:
parent
3e98e659bb
commit
298ad37c83
3 changed files with 58 additions and 0 deletions
24
lib/core/tools/Add-IcingaHashtableItem.psm1
Normal file
24
lib/core/tools/Add-IcingaHashtableItem.psm1
Normal file
|
|
@ -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;
|
||||
}
|
||||
19
lib/core/tools/Pop-IcingaArrayListItem.psm1
Normal file
19
lib/core/tools/Pop-IcingaArrayListItem.psm1
Normal file
|
|
@ -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;
|
||||
}
|
||||
15
lib/core/tools/Remove-IcingaHashtableItem.psm1
Normal file
15
lib/core/tools/Remove-IcingaHashtableItem.psm1
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
function Remove-IcingaHashtableItem()
|
||||
{
|
||||
param(
|
||||
$Hashtable,
|
||||
$Key
|
||||
);
|
||||
|
||||
if ($null -eq $Hashtable) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($Hashtable.ContainsKey($Key)) {
|
||||
$Hashtable.Remove($Key);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue