Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chinese Locale Support #80

Merged
merged 9 commits into from Apr 11, 2017
Merged

Chinese Locale Support #80

merged 9 commits into from Apr 11, 2017

Conversation

Lhfcws
Copy link

@Lhfcws Lhfcws commented Mar 2, 2017

  1. Add zh locale support
  2. Add simple url generator in NetworkProducer
  3. fix DateProducerSpec "should generate date between years #fromYear - #toYear", unpass test because the expect result is not correct

lhfcws added 2 commits March 2, 2017 15:20
2. Add simple url generator in NetworkProducer
…#toYear"

 unpass because the expect result is not correct
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 5a630c2 on Lhfcws:master into ** on Codearte:master**.

@Lhfcws
Copy link
Author

Lhfcws commented Mar 2, 2017

Related issue #78

Copy link
Contributor

@OlgaMaciaszek OlgaMaciaszek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Lhfcws Thank you very much for your contribution. It looks all right, but there are some changes that should be added. Please have a look at the comments.

@@ -115,7 +115,18 @@ public static Fairy create(Provider<DataMaster> dataMaster, Locale locale) {
}

private static FairyModule getFairyModuleForLocale(DataMaster dataMaster, Locale locale, Random random) {
LanguageCode code = LanguageCode.valueOf(locale.getLanguage().toUpperCase());
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the comment is unnecessary. You can add yourself in the file authors' list if you like.
+1 for the functionality.

@@ -67,8 +68,27 @@ private void generateDomain() {
if (domain != null) {
return;
}
domain = TextUtils.stripAccents(StringUtils.strip(StringUtils.deleteWhitespace(name.toLowerCase()), ".").replace("/", ""))
+ "." + dataMaster.getRandomValue(DOMAIN);
// domain = TextUtils.stripAccents(StringUtils.strip(StringUtils.deleteWhitespace(name.toLowerCase()), ".").replace("/", ""))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be actually better to switch CompanyProvider to an interface and add the phonetic conversion. Would you like to provide the conversion mechanism? If you wouldn't like to work on it right now, we could go with a default mechanism. Please let me know. In any case, please remove the commented out code. If we are going to leave the default mechanism, I think it should be simplified, what about just verifying if it has non-latin characters and if yes, generating a random domain?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've considered the CompanyProvider problem. I just have no idea that changing your default mechanism is proper or not. And if CompanyProvider is changed to Interface, maybe the other providers like PersonProvider should also be changed to keep a uniform design.

I can work on it in 2 or 3 days.

And I think it is better to keep generating a fixed url for each different company if possible. Maybe some people generate pair of company and url relying on this mechanism, but it may not be a big deal.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe migration to Java 8 and a default method in that interface would be useful to reduce amount of changes in other providers?

Copy link
Author

@Lhfcws Lhfcws Mar 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, this feature is a little bit like Scala trait. It's convenient for code design. But I wonder if there may be a compatibility problem in different Java versions. There're some features in Java8 that cannot be supported in JRE-7, and I'm not sure if this one is included.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works only with Java 8. However, 2 years ago we started a discussion (#23) to drop support for Java 7 and it seems to be a good argument to do that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OlgaMaciaszek @mariuszs Any objections?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.0 I've already commited Java7 Interface version.

return (char)(65 + r - 10);
}

private String getChars(int padding) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to be rather the number of chars to return than a padding. Consider renaming the parameter.

@@ -0,0 +1,70 @@
package io.codearte.jfairy.producer.person.locale.zh;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you extract the Chinese characters to constants?

/**
* Total length of Chinese ID
*/
private static final int ID_LENGTH = 15;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ID_LENGTH is never used. Can this be removed?

@@ -0,0 +1,105 @@
package io.codearte.jfairy.producer.company.locale.zh;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change your local variables such as s, r, etc., to have more miningful names.

* Add a simple url generator
* @return
*/
public String url() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if it should be added here. Do you have a usecase for this? Maybe we could just add a method in the CompanyProvider that will use the domain field to generate urls just by prefixing it with https://?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In some cases I need to generate random url for each user, and the original company urls is not enough. I assumed this is a very common demand and I couldn't find a generator in JFairy except company url. And as what I mentioned above, I believe that each company with a fixed url is better.

/**
* Codes of China provinces
*/
private static final String[] PROV_LIST = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the same list that is already used in ZhVATIdentificationNumberProvider? If yes, please extract it somewhere and share between these classes.

/**
* Codes of China provinces
*/
private static final String[] PROV_LIST = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change your local variables such as s, r, etc., to have more miningful names.

/**
* Total length of Chinese ID
*/
private static final int ID_LENGTH = 18;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ID_LENGTH is never used. Can this be removed?

lhfcws added 4 commits March 10, 2017 10:31
2. add https option to NetworkProducer.url(boolean isHttps)
3. move common shared constants of zh locale to ZhFairyUtil
4. move comments in Bootstrap.getFairyModuleForLocale to outside as a function's annotations
…ncrete class into DefaultXXProvider

7. FairyModule .configure add implement for guice install-build
8. Fix some test cases after the interface modification
9. Zh locale use ZhCompanyProvider independently
@Lhfcws
Copy link
Author

Lhfcws commented Mar 10, 2017

@OlgaMaciaszek I've made some modification according to your reviews, including switching the providers of Person/Company/IBAN into Interfaces.

@OlgaMaciaszek
Copy link
Contributor

@Lhfcws thank you very much. I will review your new changes tomorrow. The reason we are hesitant when it comes to switching to Java 8 (although we do miss the features a lot, me at least) is that we have some Android users and it seems the support for Java 8 might not yet be stable. We will definitely make a switch once we see no problems for Android.

@Lhfcws
Copy link
Author

Lhfcws commented Mar 27, 2017

Hi @OlgaMaciaszek . What's the progress of this PR now?

Copy link
Contributor

@OlgaMaciaszek OlgaMaciaszek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Lhfcws . It looks really good now :). There just a few very minor changes to add and we will be able to merge. Please have a look at the comments.

@Override
public void generateDomain() {
if (domain != null) {
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this does not affect the latin languages, I think, it should be moved to CompanyProvider.java as the default implementation. Like this, it will be possible to keep the original Company provider, call super.configure() from ZhFairyModule and keep the FairyModule fields private.


private char getChar() {
int rndNum = baseProducer.randomBetween(0, 35);
if (rndNum < 10)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plase add {} to improve readability.

domainChars[i] = (char) (c + 97);
}

String domain = String.valueOf(domainChars);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add {} to improve readability.

*/
public class ZhFairyUtil {

/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add a private default constructor to make sure this class is only used to call static methods.

lhfcws added 3 commits April 10, 2017 17:06
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 291c793 on Lhfcws:master into ** on Codearte:master**.

@Lhfcws
Copy link
Author

Lhfcws commented Apr 10, 2017

Got it. Done.

@OlgaMaciaszek OlgaMaciaszek merged commit 50e6a55 into Devskiller:master Apr 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants