Skip to content

Commit

Permalink
Added new features
Browse files Browse the repository at this point in the history
  • Loading branch information
nomemory committed Apr 14, 2021
1 parent bcb7ba8 commit d927326
Show file tree
Hide file tree
Showing 14 changed files with 375 additions and 4 deletions.
10 changes: 9 additions & 1 deletion VERSIONS
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
Version 0.4.8
-------------
- Added new MockUnit: addresses()
- Added new MockUnit: cities().capitalsAfrica()
- Added new MockUnit: cities().capitalsAsia()
- Added new MockUnit: cities().capitalsAmerica()
- Added new MockUnit: cities().capitalsAustraliaAndOceania()

Version 0.4.7
--------------
- Added logos for the library
- Added new functionality to the SQLTable class:
- Deleting rows;
- Overloaded the update functions to simplify the API
- Overloaded the update functions to simplify the API.

Version 0.4.6
-------------
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/net/andreinc/mockneat/MockNeat.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.andreinc.mockneat.abstraction.*;
import net.andreinc.mockneat.types.enums.DictType;
import net.andreinc.mockneat.types.enums.RandomType;
import net.andreinc.mockneat.unit.address.Addresses;
import net.andreinc.mockneat.unit.address.Cities;
import net.andreinc.mockneat.unit.address.Countries;
import net.andreinc.mockneat.unit.address.USStates;
Expand Down Expand Up @@ -43,6 +44,7 @@ public class MockNeat {

private final Actors rActors;
private final Actresses rActresses;
private final Addresses rAddresses;
private final Bools rBools;
private final Cars rCars;
private final Celebrities rCelebrities;
Expand Down Expand Up @@ -96,6 +98,7 @@ public MockNeat(final RandomType randomTypeType) {

this.rActors = new Actors(this);
this.rActresses = new Actresses(this);
this.rAddresses = new Addresses(this);
this.rBools = new Bools(this);
this.rCars = new Cars(this);
this.rCCS = new CreditCards(this);
Expand Down Expand Up @@ -192,6 +195,15 @@ public Actresses actresses() {
return this.rActresses;
}

/**
* <p>Returns a {@code Addresses} object that can be used to generate arbitrary address lines</p>
*
* @return a re-usable {@code Addresses} instance. This class implements {@code MockUnitString}
*/
public Addresses addresses() {
return this.rAddresses;
}

/**
* <p>Returns a {@code Bools} object that can be used to generate arbitrary {@code Boolean} values.</p>
*
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/net/andreinc/mockneat/types/enums/DictType.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public enum DictType {
CITIES_US("cities/cities-us"),
CITIES_CAPITALS("cities/cities-capitals"),
CITIES_CAPITALS_EUROPE("cities/cities-capitals-europe"),
CITIES_CAPITALS_AFRICA("cities/cities-capitals-africa"),
CITIES_CAPITALS_ASIA("cities/cities-capitals-asia"),
CITIES_CAPITALS_AMERICA("cities/cities-capitals-america"),
CITIES_CAPITALS_AUSTRALIA_AND_OCEANIA("cities/cities-capitals-australia-and-oceania"),

// CARS
CARS_BRANDS("car-brands"),
Expand Down
76 changes: 76 additions & 0 deletions src/main/java/net/andreinc/mockneat/unit/address/Addresses.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package net.andreinc.mockneat.unit.address;

import net.andreinc.mockneat.MockNeat;
import net.andreinc.mockneat.abstraction.MockUnitBase;
import net.andreinc.mockneat.abstraction.MockUnitString;

import java.util.function.Supplier;

import static net.andreinc.mockneat.types.enums.StringFormatType.CAPITALIZED;

public class Addresses extends MockUnitBase implements MockUnitString {

private static String[] SUFFIXES = new String[]{
"Ave",
"Avenue",
"St",
"Street",
"Blvd",
"Rd",
"Road",
"Hill"
};

private static String[] PREFIXES = new String[]{
"Line",
"Suite",
"Apartment",
"Ap"
};

public static Addresses addresses() {
return MockNeat.threadLocal().addresses();
}

public Addresses(MockNeat mockNeat) {
super(mockNeat);
}

/**
* <p>Returns a {@code MockUnitString} that can be used to generate the address lines</p>
*
* @return A new {@code MockUnitString}.
*/
@Override
public Supplier<String> supplier() {
return mockNeat.fmt("#{line1} #{line2}")
.param("line1", line1())
.param("line2", line2())
.supplier();
}

/**
* <p>Returns a {@code MockUnitString} that can be used to generate the first address line with the format:</p>
* <p>number noun suffix (Ave, Avenue, Street, etc.)</p>
*
* @return A new {@code MockUnitString}.
*/
public MockUnitString line1() {
return mockNeat.fmt("#{num} #{noun} #{end}")
.param("num", mockNeat.ints().range(10, 20000))
.param("noun", mockNeat.words().nouns().format(CAPITALIZED))
.param("end", mockNeat.from(SUFFIXES));
}

/**
* <p>Returns a {@code MockUnitString} that can be used to generate the second address line with the format:</p>
* <p>prefix (Line, Suite, Apartment) number</p>
*
* @return A new {@code MockUnitString}.
*/
public MockUnitString line2() {
return mockNeat.fmt("#{prefix} #{number}")
.param("prefix", mockNeat.from(PREFIXES))
.param("number", mockNeat.ints().range(1, 1000));
}
}
45 changes: 44 additions & 1 deletion src/main/java/net/andreinc/mockneat/unit/address/Cities.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,50 @@ public MockUnitString capitalsEurope() {
.supplier();
}

/**
* Returns a {@code MockUnitString} that can be used to generate capital city names from Africa (Eg.: "Mogadishu")
*
* @return A new {@code MockUnitString}
*/
public MockUnitString capitalsAfrica() {
return () -> mockNeat.dicts()
.type(DictType.CITIES_CAPITALS_AFRICA)
.supplier();
}

/**
* Returns a {@code MockUnitString} that can be used to generate capital city names from Asia
*
* @return A new {@code MockUnitString}
*/
public MockUnitString capitalsAsia() {
return () -> mockNeat.dicts()
.type(DictType.CITIES_CAPITALS_ASIA)
.supplier();
}

/**
* Returns a {@code MockUnitString} that can be used to generate capital city names from America
*
* @return A new {@code MockUnitString}
*/
public MockUnitString capitalsAmerica() {
return () -> mockNeat.dicts()
.type(DictType.CITIES_CAPITALS_AMERICA)
.supplier();
}

/**
* Returns a {@code MockUnitString} that can be used to generate Australia and Oceania capitals
*
* @return A new {@code MockUnitString}.
*/
public MockUnitString capitalsAustraliaAndOceania() {
return () -> mockNeat.dicts()
.type(DictType.CITIES_CAPITALS_AUSTRALIA_AND_OCEANIA)
.supplier();
}

/**
* Returns a {@code MockUnitString} that can be used to generate US city names. (Eg.: "New York")
*
Expand All @@ -69,5 +113,4 @@ public MockUnitString us() {
.type(DictType.CITIES_US)
.supplier();
}

}
2 changes: 1 addition & 1 deletion src/main/java/net/andreinc/mockneat/unit/regex/Regex.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public class Regex implements MockUnitString {

/**
* <p>Returns a new {@code Regex} object that can be used to generate arbitrary text bassed on a certain regex pattern.</p>
* <p>Returns a new {@code Regex} object that can be used to generate arbitrary text based on a certain regex pattern.</p>
*
* @param regex The regex pattern that the generated string needs to comply.
* @return A new {@code Regex} object. The {@code Regex} class implements {@code MockUnitString}.
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/dicts/american-presidents
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ George H. W. Bush
William J. Clinton
George W. Bush
Barack Obama
Donald J. Trump
Donald J. Trump
Joe R. Biden
59 changes: 59 additions & 0 deletions src/main/resources/dicts/cities/cities-capitals-africa
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
Abuja
Accra
Addis Ababa
Algiers
Antananarivo
Asmara
Bamako
Bangui
Banjul
Bissau
Brazzaville
Bujumbura
Cairo
Cape Town
Bloemfontein
Pretoria
Conakry
Dakar
Dodoma
Dar es Salaam
Djibouti
El Aaiún
Freetown
Gaborone
Harare
Juba
Kampala
Khartoum
Kigali
Kinshasa
Libreville
Lilongwe
Mbabane
Lobamba
Lomé
Luanda
Lusaka
Malabo
Maputo
Maseru
Mogadishu
Monrovia
Moroni
Nairobi
N'Djamena
Niamey
Nouakchott
Ouagadougou
Port Louis
Porto-Novo
Cotonou
Praia
Rabat
Tripoli
Tunis
Victoria
Windhoek
Yamoussoukro
Yaoundé
36 changes: 36 additions & 0 deletions src/main/resources/dicts/cities/cities-capitals-america
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Asunción
Basseterre
Belmopan
Bogotá
Brasilia
Bridgetown
Buenos Aires
Caracas
Castries
Georgetown
Guatemala City
Havana
Kingston
Kingstown
La Paz
Sucre
Lima
Managua
México
Montevideo
Nassau
Ottawa
Panamá
Paramaribo
Port au Prince
Port of Spain
Quito
Roseau
Saint George's
Saint John's
San José
San Salvador
Santiago
Santo Domingo
Tegucigalpa
Washington
49 changes: 49 additions & 0 deletions src/main/resources/dicts/cities/cities-capitals-asia
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
Abu Dhabi
Amman
Ankara
Ashgabat
Nur-Sultan
Baghdad
Baku
Bandar
Bangkok
Beijing
Beirut
Bishkek
Colombo
Kotte
Damascus
Dhaka
Dili
Doha
Dushanbe
Hanoi
Islamabad
Jakarta
Jerusalem
Kabul
Kathmandu
Kuala Lumpur
Kuwait-City
Lhasa
Malé
Manama
Manila
Muscat
Naypyidaw
New Delhi
Phnom Penh
P'yongyang
Riyadh
Sanaa
Seoul
Singapore
Taipei
Tashkent
T'bilisi
Tehran
Thimphu
Tokyo
Ulaanbaatar
Vientiane
Yerevan
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Adamstown
Alofi
Apia
Avarua
Canberra
Hagåtña
Funafuti
Honiara
Majuro
Ngerulmud
Nouméa
Nuku'alofa
Pago Pago
Palikir
Papeete
Port Moresby
Port Vila
Saipan
Suva
Wellington
Loading

0 comments on commit d927326

Please sign in to comment.