Created
September 16, 2020 03:46
-
-
Save jamesasu/721f0ebbb2b33e0b50eb142ebff09424 to your computer and use it in GitHub Desktop.
Helper functions that can be used a tMap to merge multiple address lines into a single line.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package routines; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.List; | |
import java.util.Random; | |
public class MyHelper { | |
/** | |
* mergeAddressLines: return String. | |
* | |
* | |
* {talendTypes} String | |
* | |
* {Category} User Defined | |
* | |
* {param} string(", ") input: The string that separates the lines. | |
* {param} string("1 Wickham St") input: A variable number of arguments for the Address Lines to be merged. | |
* | |
* {example} mergeAddressLines() # "PO Box 1167". | |
*/ | |
public static String mergeAddressLines(String separator, String... lines) { | |
if (lines.length <= 0) return ""; | |
List<String> concat = new ArrayList<String>(); | |
for (String line : lines) { | |
if (line != null) { | |
line = line.trim(); | |
if (line.length() > 0) { | |
concat.add(line); | |
} | |
} | |
} | |
if (concat.size() == 0) return ""; | |
return String.join(separator, concat); | |
} | |
/** | |
* generateBadAddresses: return String or null. | |
* | |
* | |
* {talendTypes} String | |
* | |
* {Category} User Defined | |
* | |
* {example} generateBadAddresses() # "PO Box 1167 null null". | |
*/ | |
public static String generateBadAddresses() { | |
List<String> testAddresses = new ArrayList<String>(); | |
testAddresses.add("PO Box 1167"); | |
testAddresses.add("1/1 Wickham St"); | |
testAddresses.add(null); | |
testAddresses.add("1 Pilkington Street"); | |
testAddresses.add("5 Lyons ct"); | |
testAddresses.add("17 Tasman Circuit"); | |
testAddresses.add(" "); | |
Random rand = new Random(); | |
return testAddresses.get(rand.nextInt(testAddresses.size())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment