@Test public void statesShortTest() { DataPipe pipeToTransform = new DataPipe(); EquivalenceClassTransformer eqTransformer = new EquivalenceClassTransformer(); String[] statesShort = { "AL", "AK", "AS", "AZ", "AR", "CA", "CO", "CT", "DE", "DC", "FL", "GA", "GU", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MH", "MA", "MI", "FM", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "MP", "OH", "OK", "OR", "PW", "PA", "PR", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "VI", "WA", "WV", "WI", "WY"}; Assert.assertTrue("Missed state short name(s)!", EquivalenceClassTransformer.STATES_SHORT.length == 59); HashSet<String> statesShortLookUp = new HashSet<>(Arrays.asList(statesShort)); for (int i = 0; i < 500; i++) { pipeToTransform.getDataMap().put("TEST_statesShort", "%stateShort"); eqTransformer.transform(pipeToTransform); Assert.assertTrue("Wrong state short name(s)! Have '" + pipeToTransform.getDataMap().get("TEST_statesShort") + "'," + " but wait for one of '" + statesShortLookUp + "'...", statesShortLookUp.contains(pipeToTransform.getDataMap().get("TEST_statesShort"))); } }
@Override public void transform(DataPipe cr) { Map<String, String> map = cr.getDataMap(); for (Map.Entry<String, String> entry : map.entrySet()) { String value = entry.getValue(); if (value.startsWith("%")) { String macro; String expr; int param = value.indexOf("("); if (param != -1) { macro = value.substring(1, param); expr = value.substring(param + 1, value.length() - 1); } else { macro = value.substring(1); expr = ""; } StringBuilder b = new StringBuilder(); switch (macro) { case "regex": generateFromRegex(b, expr); break; case "alpha": alpha(b, Integer.valueOf(expr)); break; case "alphaWithSpaces": alphaWithSpaces(b, Integer.valueOf(expr)); break; case "number": String[] lengths = expr.split(","); int precision = Integer.valueOf(lengths[0]); int scale = 0; if (lengths.length == 2) { scale = Integer.valueOf(lengths[1]) < 0 ? 0 : Integer.valueOf(lengths[1]); } int wholeDigits = precision - scale < 0 ? 0 : precision - scale; if (wholeDigits == 0 && scale > 0) { b.append("0."); digitSequence(b, scale); } else if (wholeDigits > 0) { b.append(random.nextInt(9) + 1); digitSequence(b, wholeDigits - 1); if (scale > 0) { b.append("."); digitSequence(b, scale); } } break; case "digits": int length = Integer.valueOf(expr); digitSequence(b, length); break; case "ssn": ssn(b); break; case "zip": zip(b); break; case "phoneDomesticUSA": phoneDomesticUSA(b); break; case "phoneDomesticUSAWithExt": phoneDomesticUSAWithExt(b); break; case "currency": b.append(CURRENCY_CODES[random.nextInt(CURRENCY_CODES.length)]); break; case "state": case "stateLong": b.append(STATE_LONG[random.nextInt(STATE_LONG.length)]); break; case "stateShort": b.append(STATES_SHORT[random.nextInt(STATES_SHORT.length)]); break; case "country": case "countryLong": b.append(COUNTRIES[random.nextInt(COUNTRIES.length)]); break; case "symbolNASDAQ": b.append(SYMBOLS_NASDAQ[random.nextInt(SYMBOLS_NASDAQ.length)]); break; case "symbolNotNASDAQ": b.append(SYMBOLS_NOT_NASDAQ[random.nextInt(SYMBOLS_NOT_NASDAQ.length)]); break; case "securityNameNASDAQ": b.append(SECURITY_NAMES_NASDAQ[random.nextInt(SECURITY_NAMES_NASDAQ.length)]); break; case "securityNameNotNASDAQ": b.append(SECURITY_NAMES_NOT_NASDAQ[random.nextInt(SECURITY_NAMES_NOT_NASDAQ.length)]); break; default: b.append(value); break; } entry.setValue(b.toString()); } else if (value.startsWith("$")) { String variable, varValue; int param = value.indexOf("{"); if (param != -1) { variable = value.substring(param + 1, value.length() - 1); } else { variable = value.substring(1); } if (map.containsKey(variable)) { varValue = map.get(variable); } else { varValue = null; } entry.setValue(varValue); } } }
EquivalenceClassTransformer implements DataTransformer { @Override public void transform(DataPipe cr) { Map<String, String> map = cr.getDataMap(); for (Map.Entry<String, String> entry : map.entrySet()) { String value = entry.getValue(); if (value.startsWith("%")) { String macro; String expr; int param = value.indexOf("("); if (param != -1) { macro = value.substring(1, param); expr = value.substring(param + 1, value.length() - 1); } else { macro = value.substring(1); expr = ""; } StringBuilder b = new StringBuilder(); switch (macro) { case "regex": generateFromRegex(b, expr); break; case "alpha": alpha(b, Integer.valueOf(expr)); break; case "alphaWithSpaces": alphaWithSpaces(b, Integer.valueOf(expr)); break; case "number": String[] lengths = expr.split(","); int precision = Integer.valueOf(lengths[0]); int scale = 0; if (lengths.length == 2) { scale = Integer.valueOf(lengths[1]) < 0 ? 0 : Integer.valueOf(lengths[1]); } int wholeDigits = precision - scale < 0 ? 0 : precision - scale; if (wholeDigits == 0 && scale > 0) { b.append("0."); digitSequence(b, scale); } else if (wholeDigits > 0) { b.append(random.nextInt(9) + 1); digitSequence(b, wholeDigits - 1); if (scale > 0) { b.append("."); digitSequence(b, scale); } } break; case "digits": int length = Integer.valueOf(expr); digitSequence(b, length); break; case "ssn": ssn(b); break; case "zip": zip(b); break; case "phoneDomesticUSA": phoneDomesticUSA(b); break; case "phoneDomesticUSAWithExt": phoneDomesticUSAWithExt(b); break; case "currency": b.append(CURRENCY_CODES[random.nextInt(CURRENCY_CODES.length)]); break; case "state": case "stateLong": b.append(STATE_LONG[random.nextInt(STATE_LONG.length)]); break; case "stateShort": b.append(STATES_SHORT[random.nextInt(STATES_SHORT.length)]); break; case "country": case "countryLong": b.append(COUNTRIES[random.nextInt(COUNTRIES.length)]); break; case "symbolNASDAQ": b.append(SYMBOLS_NASDAQ[random.nextInt(SYMBOLS_NASDAQ.length)]); break; case "symbolNotNASDAQ": b.append(SYMBOLS_NOT_NASDAQ[random.nextInt(SYMBOLS_NOT_NASDAQ.length)]); break; case "securityNameNASDAQ": b.append(SECURITY_NAMES_NASDAQ[random.nextInt(SECURITY_NAMES_NASDAQ.length)]); break; case "securityNameNotNASDAQ": b.append(SECURITY_NAMES_NOT_NASDAQ[random.nextInt(SECURITY_NAMES_NOT_NASDAQ.length)]); break; default: b.append(value); break; } entry.setValue(b.toString()); } else if (value.startsWith("$")) { String variable, varValue; int param = value.indexOf("{"); if (param != -1) { variable = value.substring(param + 1, value.length() - 1); } else { variable = value.substring(1); } if (map.containsKey(variable)) { varValue = map.get(variable); } else { varValue = null; } entry.setValue(varValue); } } } }
EquivalenceClassTransformer implements DataTransformer { @Override public void transform(DataPipe cr) { Map<String, String> map = cr.getDataMap(); for (Map.Entry<String, String> entry : map.entrySet()) { String value = entry.getValue(); if (value.startsWith("%")) { String macro; String expr; int param = value.indexOf("("); if (param != -1) { macro = value.substring(1, param); expr = value.substring(param + 1, value.length() - 1); } else { macro = value.substring(1); expr = ""; } StringBuilder b = new StringBuilder(); switch (macro) { case "regex": generateFromRegex(b, expr); break; case "alpha": alpha(b, Integer.valueOf(expr)); break; case "alphaWithSpaces": alphaWithSpaces(b, Integer.valueOf(expr)); break; case "number": String[] lengths = expr.split(","); int precision = Integer.valueOf(lengths[0]); int scale = 0; if (lengths.length == 2) { scale = Integer.valueOf(lengths[1]) < 0 ? 0 : Integer.valueOf(lengths[1]); } int wholeDigits = precision - scale < 0 ? 0 : precision - scale; if (wholeDigits == 0 && scale > 0) { b.append("0."); digitSequence(b, scale); } else if (wholeDigits > 0) { b.append(random.nextInt(9) + 1); digitSequence(b, wholeDigits - 1); if (scale > 0) { b.append("."); digitSequence(b, scale); } } break; case "digits": int length = Integer.valueOf(expr); digitSequence(b, length); break; case "ssn": ssn(b); break; case "zip": zip(b); break; case "phoneDomesticUSA": phoneDomesticUSA(b); break; case "phoneDomesticUSAWithExt": phoneDomesticUSAWithExt(b); break; case "currency": b.append(CURRENCY_CODES[random.nextInt(CURRENCY_CODES.length)]); break; case "state": case "stateLong": b.append(STATE_LONG[random.nextInt(STATE_LONG.length)]); break; case "stateShort": b.append(STATES_SHORT[random.nextInt(STATES_SHORT.length)]); break; case "country": case "countryLong": b.append(COUNTRIES[random.nextInt(COUNTRIES.length)]); break; case "symbolNASDAQ": b.append(SYMBOLS_NASDAQ[random.nextInt(SYMBOLS_NASDAQ.length)]); break; case "symbolNotNASDAQ": b.append(SYMBOLS_NOT_NASDAQ[random.nextInt(SYMBOLS_NOT_NASDAQ.length)]); break; case "securityNameNASDAQ": b.append(SECURITY_NAMES_NASDAQ[random.nextInt(SECURITY_NAMES_NASDAQ.length)]); break; case "securityNameNotNASDAQ": b.append(SECURITY_NAMES_NOT_NASDAQ[random.nextInt(SECURITY_NAMES_NOT_NASDAQ.length)]); break; default: b.append(value); break; } entry.setValue(b.toString()); } else if (value.startsWith("$")) { String variable, varValue; int param = value.indexOf("{"); if (param != -1) { variable = value.substring(param + 1, value.length() - 1); } else { variable = value.substring(1); } if (map.containsKey(variable)) { varValue = map.get(variable); } else { varValue = null; } entry.setValue(varValue); } } } EquivalenceClassTransformer(); }
EquivalenceClassTransformer implements DataTransformer { @Override public void transform(DataPipe cr) { Map<String, String> map = cr.getDataMap(); for (Map.Entry<String, String> entry : map.entrySet()) { String value = entry.getValue(); if (value.startsWith("%")) { String macro; String expr; int param = value.indexOf("("); if (param != -1) { macro = value.substring(1, param); expr = value.substring(param + 1, value.length() - 1); } else { macro = value.substring(1); expr = ""; } StringBuilder b = new StringBuilder(); switch (macro) { case "regex": generateFromRegex(b, expr); break; case "alpha": alpha(b, Integer.valueOf(expr)); break; case "alphaWithSpaces": alphaWithSpaces(b, Integer.valueOf(expr)); break; case "number": String[] lengths = expr.split(","); int precision = Integer.valueOf(lengths[0]); int scale = 0; if (lengths.length == 2) { scale = Integer.valueOf(lengths[1]) < 0 ? 0 : Integer.valueOf(lengths[1]); } int wholeDigits = precision - scale < 0 ? 0 : precision - scale; if (wholeDigits == 0 && scale > 0) { b.append("0."); digitSequence(b, scale); } else if (wholeDigits > 0) { b.append(random.nextInt(9) + 1); digitSequence(b, wholeDigits - 1); if (scale > 0) { b.append("."); digitSequence(b, scale); } } break; case "digits": int length = Integer.valueOf(expr); digitSequence(b, length); break; case "ssn": ssn(b); break; case "zip": zip(b); break; case "phoneDomesticUSA": phoneDomesticUSA(b); break; case "phoneDomesticUSAWithExt": phoneDomesticUSAWithExt(b); break; case "currency": b.append(CURRENCY_CODES[random.nextInt(CURRENCY_CODES.length)]); break; case "state": case "stateLong": b.append(STATE_LONG[random.nextInt(STATE_LONG.length)]); break; case "stateShort": b.append(STATES_SHORT[random.nextInt(STATES_SHORT.length)]); break; case "country": case "countryLong": b.append(COUNTRIES[random.nextInt(COUNTRIES.length)]); break; case "symbolNASDAQ": b.append(SYMBOLS_NASDAQ[random.nextInt(SYMBOLS_NASDAQ.length)]); break; case "symbolNotNASDAQ": b.append(SYMBOLS_NOT_NASDAQ[random.nextInt(SYMBOLS_NOT_NASDAQ.length)]); break; case "securityNameNASDAQ": b.append(SECURITY_NAMES_NASDAQ[random.nextInt(SECURITY_NAMES_NASDAQ.length)]); break; case "securityNameNotNASDAQ": b.append(SECURITY_NAMES_NOT_NASDAQ[random.nextInt(SECURITY_NAMES_NOT_NASDAQ.length)]); break; default: b.append(value); break; } entry.setValue(b.toString()); } else if (value.startsWith("$")) { String variable, varValue; int param = value.indexOf("{"); if (param != -1) { variable = value.substring(param + 1, value.length() - 1); } else { variable = value.substring(1); } if (map.containsKey(variable)) { varValue = map.get(variable); } else { varValue = null; } entry.setValue(varValue); } } } EquivalenceClassTransformer(); @Override void transform(DataPipe cr); }
EquivalenceClassTransformer implements DataTransformer { @Override public void transform(DataPipe cr) { Map<String, String> map = cr.getDataMap(); for (Map.Entry<String, String> entry : map.entrySet()) { String value = entry.getValue(); if (value.startsWith("%")) { String macro; String expr; int param = value.indexOf("("); if (param != -1) { macro = value.substring(1, param); expr = value.substring(param + 1, value.length() - 1); } else { macro = value.substring(1); expr = ""; } StringBuilder b = new StringBuilder(); switch (macro) { case "regex": generateFromRegex(b, expr); break; case "alpha": alpha(b, Integer.valueOf(expr)); break; case "alphaWithSpaces": alphaWithSpaces(b, Integer.valueOf(expr)); break; case "number": String[] lengths = expr.split(","); int precision = Integer.valueOf(lengths[0]); int scale = 0; if (lengths.length == 2) { scale = Integer.valueOf(lengths[1]) < 0 ? 0 : Integer.valueOf(lengths[1]); } int wholeDigits = precision - scale < 0 ? 0 : precision - scale; if (wholeDigits == 0 && scale > 0) { b.append("0."); digitSequence(b, scale); } else if (wholeDigits > 0) { b.append(random.nextInt(9) + 1); digitSequence(b, wholeDigits - 1); if (scale > 0) { b.append("."); digitSequence(b, scale); } } break; case "digits": int length = Integer.valueOf(expr); digitSequence(b, length); break; case "ssn": ssn(b); break; case "zip": zip(b); break; case "phoneDomesticUSA": phoneDomesticUSA(b); break; case "phoneDomesticUSAWithExt": phoneDomesticUSAWithExt(b); break; case "currency": b.append(CURRENCY_CODES[random.nextInt(CURRENCY_CODES.length)]); break; case "state": case "stateLong": b.append(STATE_LONG[random.nextInt(STATE_LONG.length)]); break; case "stateShort": b.append(STATES_SHORT[random.nextInt(STATES_SHORT.length)]); break; case "country": case "countryLong": b.append(COUNTRIES[random.nextInt(COUNTRIES.length)]); break; case "symbolNASDAQ": b.append(SYMBOLS_NASDAQ[random.nextInt(SYMBOLS_NASDAQ.length)]); break; case "symbolNotNASDAQ": b.append(SYMBOLS_NOT_NASDAQ[random.nextInt(SYMBOLS_NOT_NASDAQ.length)]); break; case "securityNameNASDAQ": b.append(SECURITY_NAMES_NASDAQ[random.nextInt(SECURITY_NAMES_NASDAQ.length)]); break; case "securityNameNotNASDAQ": b.append(SECURITY_NAMES_NOT_NASDAQ[random.nextInt(SECURITY_NAMES_NOT_NASDAQ.length)]); break; default: b.append(value); break; } entry.setValue(b.toString()); } else if (value.startsWith("$")) { String variable, varValue; int param = value.indexOf("{"); if (param != -1) { variable = value.substring(param + 1, value.length() - 1); } else { variable = value.substring(1); } if (map.containsKey(variable)) { varValue = map.get(variable); } else { varValue = null; } entry.setValue(varValue); } } } EquivalenceClassTransformer(); @Override void transform(DataPipe cr); static final String[] CURRENCY_CODES; static final String[] STATE_LONG; static final String[] STATES_SHORT; static final Holiday[] HOLIDAYS; static final String[] COUNTRIES; static final int COUNT_NASDAQ_SECURITIES; static final String[] SYMBOLS_NASDAQ; static final String[] SECURITY_NAMES_NASDAQ; static final int COUNT_NOT_NASDAQ_SECURITIES; static final String[] SYMBOLS_NOT_NASDAQ; static final String[] SECURITY_NAMES_NOT_NASDAQ; }