Skip to content

Commit

Permalink
Add ConvertTo-JavaProperty
Browse files Browse the repository at this point in the history
Add function to format a property for Java
  • Loading branch information
Akaizoku committed Jan 20, 2020
1 parent 36170e8 commit 329a01c
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
1 change: 1 addition & 0 deletions PSTK.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ FunctionsToExport = @(
"Complete-RelativePath",
"Confirm-Prompt",
"Convert-FileEncoding",
"ConvertTo-JavaProperty",
"ConvertTo-NaturalSort",
"ConvertTo-PDF",
"Copy-OrderedHashtable",
Expand Down
70 changes: 70 additions & 0 deletions Public/ConvertTo-JavaProperty.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
function ConvertTo-JavaProperty {
<#
.SYNOPSIS
Convert to Java property
.DESCRIPTION
Format property key-value pair as Java property
.PARAMETER Property
The property parameter corresponds to the property key-value pair to format.
.PARAMETER Prefix
The optional prefix parameter corresponds to the prefix of the expected Java property. The default value is "D".
.INPUTS
System.Collections.Specialized.OrderedDictionary. You can pipe the property key-value pair to ConvertTo-JavaProperty.
.OUTPUTS
System.String. ConvertTo-JavaProperty returns the formatted Java property.
.NOTES
File name: ConvertTo-JavaProperty.ps1
Author: Florian Carrier
Creation date: 15/10/2019
Last modified: 16/01/2020
#>
[CmdletBinding ()]
Param(
[Parameter (
Position = 1,
Mandatory = $true,
HelpMessage = "Property key-value pair",
ValueFromPipeline = $true
)]
[ValidateNotNullOrEmpty()]
[Alias ("Properties")]
[System.Collections.Specialized.OrderedDictionary]
$Property,
[Parameter (
Position = 2,
Mandatory = $false,
HelpMessage = "Java property prefix"
)]
[String]
$Prefix = "D"
)
Begin {
# Get global preference variables
Get-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState
}
Process {
if ($Property.Count -gt 0) {
$JavaString = New-Object -TypeName "System.String" -ArgumentList ""
# Loop through properties (if multiple have been provided)
foreach ($SingleProperty in $Property.GetEnumerator()) {
# Add space between consecutive properties
if ($JavaString) {
$JavaString += " "
}
# Format property
$JavaString += "-" + $Prefix + '"' + $SingleProperty.Name + '"' + "=" + '"' + $SingleProperty.Value + '"'
}
# Return Java property string
return $JavaString
} else {
# If property is invalid
return $null
}
}
}

0 comments on commit 329a01c

Please sign in to comment.