Address with multiple lines
rajib76 opened this issue · 3 comments
Hi,
I am trying to create an address with multiple address lines. Is there a built-in function to do this. Below is what I am trying to generate. If this is not available, I will try to see if I can add a function to generate address lines
AddressID : XXXXX
AddressLine1:xxxxxxxxxxxx
AdressLine2:xxxxxxxxxxxx
City:
State:
Pin:
I've written the following code as a baseline for what you want.
You can find the full documentation at www.mockneat.com. You can customise your address generation as you want, but this should be the baseline.
import net.andreinc.mockneat.MockNeat;
import net.andreinc.mockneat.types.enums.StringFormatType;
import net.andreinc.mockneat.unit.objects.Froms;
import java.util.List;
import static net.andreinc.mockneat.types.enums.StringFormatType.CAPITALIZED;
import static net.andreinc.mockneat.unit.address.Cities.cities;
import static net.andreinc.mockneat.unit.address.USStates.usStates;
import static net.andreinc.mockneat.unit.objects.From.fromStrings;
import static net.andreinc.mockneat.unit.seq.IntSeq.intSeq;
import static net.andreinc.mockneat.unit.text.Formatter.fmt;
import static net.andreinc.mockneat.unit.text.Words.words;
import static net.andreinc.mockneat.unit.types.Ints.ints;
public class AddressGenerator {
public static void main(String[] args) {
String template =
"AddressID : #{id} \n" +
"AddressLine1: #{l1}\n" +
"AdressLine2: #{l2} \n" +
"City: #{city} \n" +
"State: #{state} \n" +
"Pin: #{pin} \n";
List<String> addresses =
fmt(template)
.param("id", intSeq().increment(10))
.param("l1",
fmt("#{pref} #{word1} #{word2}")
.param("pref", fromStrings(new String[]{"Blvd.", "Str."}))
.param("word1", words().adjectives().format(CAPITALIZED))
.param("word2", words().nouns().format(CAPITALIZED))
)
.param("l2",
fmt("No. #{nr1}")
.param("nr1", ints().range(1, 100))
)
.param("city", cities().us())
.param("state", usStates())
.param("pin", ints().range(1000, 9999))
.list(10).get();
addresses.forEach(System.out::println);
}
}
The above code should be able to generate 10 Addresses in your specific format.
I don't see any reason to implement a "real" address generator at the library level, all because addresses don't have a standard format.
With a little bit of effort we can basically generate any address we want.
Thank you for trying the library. If you need any other help tell me.
Thanks a lot