use of net.andreinc.mockneat.abstraction.MockUnitString in project mockneat by nomemory.
the class MockUnitExamplesString method main.
public static void main(String[] args) {
MockNeat mock = MockNeat.threadLocal();
// APPEND
String[] cityAppend = mock.cities().capitals().append("-001").array(10).val();
System.out.println(AlephFormatter.template("#{cities}", "cities", cityAppend).fmt());
// ARRAY
String[] someDays = mock.days().display().array(10).val();
System.out.println(AlephFormatter.template("#{days}", "days", someDays).fmt());
// BASE64
List<String> names = mock.names().first().format(CAPITALIZED).list(5).val();
System.out.println(names);
List<String> base64names = mock.seq(names).mapToString().base64().list(5).val();
System.out.println(base64names);
// ESCAPE CSV
String[] notFriendlyCsv = { "\"" /* OTHERS */
};
String friendlyCSV = mock.from(notFriendlyCsv).mapToString().escapeCsv().val();
System.out.println(friendlyCSV);
// ESCAPE ECMA SCRIPT
MockUnitString jsCode = () -> () -> "function myFunction() {\n" + " document.getElementById(\"demo1\").innerHTML = \"Hello Dolly!\";\n" + " document.getElementById(\"demo2\").innerHTML = \"How are you?\";\n" + "}";
String escaped = jsCode.escapeEcmaScript().val();
System.out.println(escaped);
}
use of net.andreinc.mockneat.abstraction.MockUnitString in project mockneat by nomemory.
the class HrSchema method streeNameGenerator.
/**
* Returns an arbitrary street name.
* @return
*/
private static final MockUnitString streeNameGenerator() {
// A reference to the mock add associated with the current thread;
MockNeat m = MockNeat.threadLocal();
// Returns a random string from the 'STREET_SUFFIX' list;
// Eg: "Str"
MockUnitString streetNameSuffix = m.fromStrings(STREET_SUFFIX);
// Returns a potential street name
// - Streets names have 55% chances of containing two words;
// - Street names have 45% chances of containing one word;
// The single word is always a noun (1 syllable, 2 syllables or 3 syllables)
// The first word if exists is an adjective (1 syllable or 2 syllables)
MockUnitString streetNameGenerator = m.fmt("#{word1}#{word2}").param("word1", m.probabilites(String.class).add(0.55, m.dicts().types(EN_ADJECTIVE_1SYLL, EN_ADJECTIVE_2SYLL)).add(0.45, "").mapToString(s -> s.equals("") ? s : s + " ").format(CAPITALIZED)).param("word2", m.dicts().types(EN_NOUN_1SYLL, EN_NOUN_2SYLL, EN_NOUN_3SYLL).format(CAPITALIZED));
// - Last section is the suffix as obtained above
return m.fmt("#{no} #{name} #{suffix}").param("no", m.ints().range(1, 10000)).param("name", streetNameGenerator).param("suffix", streetNameSuffix);
}
use of net.andreinc.mockneat.abstraction.MockUnitString in project mockneat by nomemory.
the class CSVsTest method testLine.
@Test
public void testLine() {
MockUnitString ms1 = M.fromStrings(new String[] { "ABC\"," });
String line = M.csvs().column(ms1).column("A,a").val();
Assert.assertEquals("\"ABC\"\",\",\"A,a\"", line);
}
use of net.andreinc.mockneat.abstraction.MockUnitString in project mockneat by nomemory.
the class Cars method supplier.
@Override
public Supplier<String> supplier() {
MockUnitString nameGenerator = mockNeat.probabilites(String.class).add(0.2, mockNeat.space().types(PLANETS, GALAXIES, MOONS, CONSTELLATIONS, STARS).format(CAPITALIZED)).add(0.1, mockNeat.names().firstAndMale()).add(0.1, mockNeat.names().last()).add(0.3, mockNeat.creatures()).add(0.3, mockNeat.names().firstAndFemale()).mapToString();
MockUnitString prefixGenerator = mockNeat.fmt("#{L}#{D}").param("L", mockNeat.chars().letters().mapToString().format(CAPITALIZED)).param("D", mockNeat.ints().range(0, 999).mapToString());
MockUnitString modelNameGenerator = mockNeat.probabilites(String.class).add(0.3, prefixGenerator).add(0.7, nameGenerator).mapToString();
return mockNeat.fmt("#{brand} #{model}").param("brand", brands()).param("model", modelNameGenerator).supplier();
}
use of net.andreinc.mockneat.abstraction.MockUnitString in project mockneat by nomemory.
the class Shufflers method string.
public MockUnitString string(String source) {
notNull(source, "source");
Supplier<String> supplier = () -> {
char[] chars = source.toCharArray();
char c;
for (int j, i = 0; i < chars.length; ++i) {
j = mockNeat.ints().range(i, chars.length).val();
c = chars[i];
chars[i] = chars[j];
chars[j] = c;
}
return new String(chars);
};
return () -> supplier;
}
Aggregations