From 702192036d414dab38ad4757bef0f2e8d9edf3ab Mon Sep 17 00:00:00 2001 From: "Ciobanu, Andrei-Nicolin (UK - EDC)" Date: Sat, 17 Jun 2017 12:50:47 +0300 Subject: [PATCH] Created version 0.1.0 --- bintray.gradle | 2 +- build.gradle | 5 ++-- .../mockneat/abstraction/MockUnitValue.java | 2 +- .../mockneat/types/enums/CreditCardType.java | 15 ++++++----- .../mockneat/types/enums/HostNameType.java | 17 +++++++------ .../mockneat/types/enums/IBANType.java | 8 ------ .../types/enums/MACAddressFormatType.java | 1 + .../mockneat/types/enums/UserNameType.java | 25 ++++++++++--------- .../mockneat/unit/objects/Factory.java | 2 +- .../mockneat/unit/objects/Probabilities.java | 2 -- .../mockneat/unit/objects/Shufflers.java | 2 +- .../andreinc/mockneat/unit/regex/Regex.java | 2 +- .../andreinc/mockneat/unit/text/Markovs.java | 2 +- .../andreinc/mockneat/unit/time/Months.java | 2 -- .../mockneat/unit/user/Passwords.java | 2 +- 15 files changed, 41 insertions(+), 48 deletions(-) diff --git a/bintray.gradle b/bintray.gradle index 02f02e0..6cc578b 100644 --- a/bintray.gradle +++ b/bintray.gradle @@ -1,6 +1,6 @@ apply plugin: 'com.jfrog.bintray' -version = '0.0.9' +version = '0.1.0' task sourcesJar(type: Jar) { classifier = 'sources' diff --git a/build.gradle b/build.gradle index 8fa2660..53c36a3 100644 --- a/build.gradle +++ b/build.gradle @@ -16,10 +16,10 @@ plugins { } apply plugin: 'java' -apply plugin: "net.ltgt.errorprone"clea +apply plugin: "net.ltgt.errorprone" group 'net.andreinc' -version '0.0.9' +version '0.1.0' sourceCompatibility = 1.8 @@ -38,7 +38,6 @@ dependencies { compile group: 'net.andreinc.aleph', name: 'aleph-formatter', version: '0.0.3' compile group: 'com.google.errorprone', name: 'error_prone_annotations', version: '2.0.19' - testCompile group: 'junit', name: 'junit', version: '4.4' testCompile group: 'commons-validator', name: 'commons-validator', version: '1.5.1' } diff --git a/src/main/java/net/andreinc/mockneat/abstraction/MockUnitValue.java b/src/main/java/net/andreinc/mockneat/abstraction/MockUnitValue.java index ea24897..5274b74 100644 --- a/src/main/java/net/andreinc/mockneat/abstraction/MockUnitValue.java +++ b/src/main/java/net/andreinc/mockneat/abstraction/MockUnitValue.java @@ -25,7 +25,7 @@ private MockUnitValue(MockUnit mockUnit) { this.mockUnit = mockUnit; } - public static final MockUnitValue unit(MockUnit unit) { + public static MockUnitValue unit(MockUnit unit) { return new MockUnitValue(unit); } diff --git a/src/main/java/net/andreinc/mockneat/types/enums/CreditCardType.java b/src/main/java/net/andreinc/mockneat/types/enums/CreditCardType.java index 25fdb4f..de4883d 100644 --- a/src/main/java/net/andreinc/mockneat/types/enums/CreditCardType.java +++ b/src/main/java/net/andreinc/mockneat/types/enums/CreditCardType.java @@ -18,11 +18,12 @@ */ -import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedList; import java.util.List; -import java.util.stream.Collectors; + +import static java.util.Collections.unmodifiableList; +import static java.util.stream.Collectors.toList; @SuppressWarnings("ImmutableEnumChecker") public enum CreditCardType { @@ -59,8 +60,10 @@ public enum CreditCardType { CreditCardType(Integer length, Integer... prefixes) { this.length = length; - List plist = Arrays.asList(prefixes); - this.prefixes = plist.stream().map(this::fromNumber).collect(Collectors.toList()); + this.prefixes = + unmodifiableList(Arrays.stream(prefixes) + .map(this::fromNumber) + .collect(toList())); } public List> getPrefixes() { @@ -69,13 +72,13 @@ public List> getPrefixes() { public Integer getLength() { return length; } - private ArrayList fromNumber(int num) { + private List fromNumber(int num) { List list = new LinkedList<>(); int tmp = num; while(tmp!=0) { list.add(0, tmp%10); tmp/=10; } - return new ArrayList<>(list); + return unmodifiableList(list); } } diff --git a/src/main/java/net/andreinc/mockneat/types/enums/HostNameType.java b/src/main/java/net/andreinc/mockneat/types/enums/HostNameType.java index 7d6d5df..3e780d4 100644 --- a/src/main/java/net/andreinc/mockneat/types/enums/HostNameType.java +++ b/src/main/java/net/andreinc/mockneat/types/enums/HostNameType.java @@ -22,11 +22,12 @@ import java.util.List; import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; @SuppressWarnings("ImmutableEnumChecker") public enum HostNameType { ADJECTIVE_NOUN( - asList( + unmodifiableList(asList( new Pair<>(DictType.EN_ADJECTIVE_1SYLL, DictType.EN_NOUN_1SYLL), new Pair<>(DictType.EN_ADJECTIVE_1SYLL, DictType.EN_NOUN_2SYLL), new Pair<>(DictType.EN_ADJECTIVE_1SYLL, DictType.EN_NOUN_3SYLL), @@ -38,11 +39,11 @@ public enum HostNameType { new Pair<>(DictType.EN_ADJECTIVE_3SYLL, DictType.EN_NOUN_1SYLL), new Pair<>(DictType.EN_ADJECTIVE_3SYLL, DictType.EN_NOUN_2SYLL), new Pair<>(DictType.EN_ADJECTIVE_3SYLL, DictType.EN_NOUN_3SYLL) - ) + )) ), ADVERB_VERB( - asList( + unmodifiableList(asList( new Pair<>(DictType.EN_ADVERB_1SYLL, DictType.EN_VERB_1SYLL), new Pair<>(DictType.EN_ADVERB_1SYLL, DictType.EN_VERB_2SYLL), new Pair<>(DictType.EN_ADVERB_1SYLL, DictType.EN_VERB_3SYLL), @@ -54,11 +55,11 @@ public enum HostNameType { new Pair<>(DictType.EN_ADVERB_3SYLL, DictType.EN_VERB_1SYLL), new Pair<>(DictType.EN_ADVERB_3SYLL, DictType.EN_VERB_2SYLL), new Pair<>(DictType.EN_ADVERB_3SYLL, DictType.EN_VERB_3SYLL) - ) + )) ), ADJECTIVE_FIRST_NAME( - asList( + unmodifiableList(asList( new Pair<>(DictType.EN_ADJECTIVE_1SYLL, DictType.FIRST_NAME_MALE_AMERICAN), new Pair<>(DictType.EN_ADJECTIVE_1SYLL, DictType.FIRST_NAME_FEMALE_AMERICAN), @@ -67,11 +68,11 @@ public enum HostNameType { new Pair<>(DictType.EN_ADJECTIVE_3SYLL, DictType.FIRST_NAME_MALE_AMERICAN), new Pair<>(DictType.EN_ADJECTIVE_3SYLL, DictType.FIRST_NAME_FEMALE_AMERICAN) - ) + )) ), NOUN_FIRST_NAME( - asList( + unmodifiableList(asList( new Pair<>(DictType.EN_NOUN_1SYLL, DictType.FIRST_NAME_MALE_AMERICAN), new Pair<>(DictType.EN_NOUN_2SYLL, DictType.FIRST_NAME_MALE_AMERICAN), new Pair<>(DictType.EN_NOUN_3SYLL, DictType.FIRST_NAME_MALE_AMERICAN), @@ -79,7 +80,7 @@ public enum HostNameType { new Pair<>(DictType.EN_NOUN_1SYLL, DictType.FIRST_NAME_FEMALE_AMERICAN), new Pair<>(DictType.EN_NOUN_2SYLL, DictType.FIRST_NAME_FEMALE_AMERICAN), new Pair<>(DictType.EN_NOUN_3SYLL, DictType.FIRST_NAME_FEMALE_AMERICAN) - ) + )) ); private final List> dictCombos; diff --git a/src/main/java/net/andreinc/mockneat/types/enums/IBANType.java b/src/main/java/net/andreinc/mockneat/types/enums/IBANType.java index a1db464..e67a4c1 100644 --- a/src/main/java/net/andreinc/mockneat/types/enums/IBANType.java +++ b/src/main/java/net/andreinc/mockneat/types/enums/IBANType.java @@ -234,7 +234,6 @@ public enum IBANType { private final int length; private final String prefix; private final List> bban; - private String checkDigits = null; IBANType(int length, String prefix, Pair... charsGroup) { this.length = length; @@ -242,13 +241,6 @@ public enum IBANType { this.bban = asList(charsGroup); } - IBANType(int length, String checkDigits, String prefix, Pair... charsGroup) { - this.length = length; - this.checkDigits = checkDigits; - this.prefix = prefix; - this.bban = asList(charsGroup); - } - public int getLength() { return length; } diff --git a/src/main/java/net/andreinc/mockneat/types/enums/MACAddressFormatType.java b/src/main/java/net/andreinc/mockneat/types/enums/MACAddressFormatType.java index bdd8932..bc2dd5c 100644 --- a/src/main/java/net/andreinc/mockneat/types/enums/MACAddressFormatType.java +++ b/src/main/java/net/andreinc/mockneat/types/enums/MACAddressFormatType.java @@ -22,6 +22,7 @@ @SuppressWarnings("ImmutableEnumChecker") public enum MACAddressFormatType { + DASH_EVERY_2_DIGITS(MACAddressFormatType::line2Digits), COLON_EVERY_2_DIGITS(MACAddressFormatType::colon2Digits), DOT_EVERY_2_DIGITS(MACAddressFormatType::point2Digits), diff --git a/src/main/java/net/andreinc/mockneat/types/enums/UserNameType.java b/src/main/java/net/andreinc/mockneat/types/enums/UserNameType.java index 446494b..faab2bc 100644 --- a/src/main/java/net/andreinc/mockneat/types/enums/UserNameType.java +++ b/src/main/java/net/andreinc/mockneat/types/enums/UserNameType.java @@ -22,50 +22,51 @@ import java.util.List; import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; @SuppressWarnings("ImmutableEnumChecker") public enum UserNameType { ADJECTIVE_NOUN( - asList( + unmodifiableList(asList( new Pair<>(DictType.EN_ADJECTIVE_1SYLL, DictType.EN_NOUN_1SYLL), new Pair<>(DictType.EN_ADJECTIVE_1SYLL, DictType.EN_NOUN_2SYLL), new Pair<>(DictType.EN_ADJECTIVE_2SYLL, DictType.EN_NOUN_1SYLL) - ) + )) ), ADVERB_VERB( - asList( + unmodifiableList(asList( new Pair<>(DictType.EN_ADVERB_1SYLL, DictType.EN_VERB_1SYLL), new Pair<>(DictType.EN_ADVERB_2SYLL, DictType.EN_VERB_1SYLL), new Pair<>(DictType.EN_ADVERB_1SYLL, DictType.EN_VERB_2SYLL) - ) + )) ), ADJECTIVE_FIRST_NAME( - asList( + unmodifiableList(asList( new Pair<>(DictType.EN_ADJECTIVE_1SYLL, DictType.FIRST_NAME_MALE_AMERICAN), new Pair<>(DictType.EN_ADJECTIVE_1SYLL, DictType.FIRST_NAME_FEMALE_AMERICAN) - ) + )) ), ADJECTIVE_LAST_NAME( - asList( + unmodifiableList(asList( new Pair<>(DictType.EN_ADJECTIVE_1SYLL, DictType.LAST_NAME_AMERICAN), new Pair<>(DictType.EN_ADJECTIVE_2SYLL, DictType.LAST_NAME_AMERICAN) - ) + )) ), ADJECTIVE_FIRST_NAME_MALE( - asList( + unmodifiableList(asList( new Pair<>(DictType.EN_ADJECTIVE_1SYLL, DictType.FIRST_NAME_MALE_AMERICAN) - ) + )) ), ADJECTIVE_FIRST_NAME_FEMALE( - asList( + unmodifiableList(asList( new Pair<>(DictType.EN_ADJECTIVE_1SYLL, DictType.FIRST_NAME_FEMALE_AMERICAN) - ) + )) ); private final List> dictCombos; diff --git a/src/main/java/net/andreinc/mockneat/unit/objects/Factory.java b/src/main/java/net/andreinc/mockneat/unit/objects/Factory.java index 393e3f8..f2c76f4 100644 --- a/src/main/java/net/andreinc/mockneat/unit/objects/Factory.java +++ b/src/main/java/net/andreinc/mockneat/unit/objects/Factory.java @@ -66,7 +66,7 @@ public Supplier supplier() { isTrue(JAVA_FIELD_REGEX.matcher(method).matches(), template(JAVA_METHOD_REGEX_MATCH, "method", method).fmt()); final Object[] args = new Object[params.length]; return () -> { - T result = null; + T result; try { range(0, params.length).forEach(i -> args[i] = MockUnitUtils.mockOrObject(params[i])); result = (T) invokeExactStaticMethod(factoryClass, method, args); diff --git a/src/main/java/net/andreinc/mockneat/unit/objects/Probabilities.java b/src/main/java/net/andreinc/mockneat/unit/objects/Probabilities.java index 3d23d2c..ad71a2d 100644 --- a/src/main/java/net/andreinc/mockneat/unit/objects/Probabilities.java +++ b/src/main/java/net/andreinc/mockneat/unit/objects/Probabilities.java @@ -35,13 +35,11 @@ public class Probabilities extends MockUnitBase implements MockUnit { - private final Class cls; private final List> probs = new ArrayList<>(); private final MockUnitDouble mud; public Probabilities(MockNeat mockNeat, Class cls) { super(mockNeat); - this.cls = cls; this.mud = mockNeat.doubles().range(0, 1.0); } diff --git a/src/main/java/net/andreinc/mockneat/unit/objects/Shufflers.java b/src/main/java/net/andreinc/mockneat/unit/objects/Shufflers.java index 392fe7b..a059926 100644 --- a/src/main/java/net/andreinc/mockneat/unit/objects/Shufflers.java +++ b/src/main/java/net/andreinc/mockneat/unit/objects/Shufflers.java @@ -38,7 +38,7 @@ public MockUnit array(T[] source) { notNull(source, "source"); Supplier supplier = () -> { T[] result = source.clone(); - T tmp = null; + T tmp; for(int j, i = 0; i < result.length - 2; ++i) { j = mockNeat.ints().range(i, result.length).val(); tmp = result[i]; diff --git a/src/main/java/net/andreinc/mockneat/unit/regex/Regex.java b/src/main/java/net/andreinc/mockneat/unit/regex/Regex.java index 5820aa2..afd20ca 100644 --- a/src/main/java/net/andreinc/mockneat/unit/regex/Regex.java +++ b/src/main/java/net/andreinc/mockneat/unit/regex/Regex.java @@ -27,7 +27,7 @@ public class Regex implements MockUnitString { - private String regex; + private final String regex; public Regex(String regex) { this.regex = regex; diff --git a/src/main/java/net/andreinc/mockneat/unit/text/Markovs.java b/src/main/java/net/andreinc/mockneat/unit/text/Markovs.java index 5c17429..ae19e7f 100644 --- a/src/main/java/net/andreinc/mockneat/unit/text/Markovs.java +++ b/src/main/java/net/andreinc/mockneat/unit/text/Markovs.java @@ -75,7 +75,7 @@ public MockUnitString types(MarkovChainType... types) { public MockUnitString type(MarkovChainType type) { notNull(type, "type"); Supplier supp = () -> { - MarkovUnit unit = null; + MarkovUnit unit; try { unit = get(type); return unit.generateText(size); diff --git a/src/main/java/net/andreinc/mockneat/unit/time/Months.java b/src/main/java/net/andreinc/mockneat/unit/time/Months.java index 15c69f7..1a690a8 100644 --- a/src/main/java/net/andreinc/mockneat/unit/time/Months.java +++ b/src/main/java/net/andreinc/mockneat/unit/time/Months.java @@ -26,8 +26,6 @@ import static net.andreinc.mockneat.utils.ValidationUtils.*; -; - public class Months extends MockUnitBase implements MockUnitMonth { public Months(MockNeat mockNeat) { diff --git a/src/main/java/net/andreinc/mockneat/unit/user/Passwords.java b/src/main/java/net/andreinc/mockneat/unit/user/Passwords.java index 51e2500..4ca9f2b 100644 --- a/src/main/java/net/andreinc/mockneat/unit/user/Passwords.java +++ b/src/main/java/net/andreinc/mockneat/unit/user/Passwords.java @@ -131,7 +131,7 @@ private String nextStrongPassword() { int passLength = mockNeat.ints().range(minLength, maxLength).val(); StringBuilder buff = new StringBuilder(); List cAlph; - List> lists = asList(new List[]{SPECIAL_CHARACTERS, DIGITS, LETTERS}); + List> lists = asList(SPECIAL_CHARACTERS, DIGITS, LETTERS); while (passLength-- > 1) { cAlph = mockNeat.from(lists).val(); buff.append(mockNeat.from(cAlph).val());