-
Notifications
You must be signed in to change notification settings - Fork 34
Remove repeat hyphen #474
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
Remove repeat hyphen #474
Conversation
@@ -65,6 +65,8 @@ protected void initBinder(WebDataBinder binder) { | |||
StringTrimmerEditor editor = new StringTrimmerEditor(false); | |||
binder.registerCustomEditor(String.class, "name", editor); | |||
binder.registerCustomEditor(String.class, "nameRu", editor); | |||
binder.registerCustomEditor(String.class, "name", new CustomCategoryNameEditor()); | |||
binder.registerCustomEditor(String.class, "nameRu", new CustomCategoryNameEditor()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to use the same instance of the editor for both fields? In other words, is the class thread-safe?
плюс не хватает интеграционных тестов |
Трэвис, помимо всего прочего, также жалуется на отсутствие хедера: https://github.com/php-coder/mystamps/wiki/check-license-header |
4e16819
to
613fe42
Compare
@@ -62,9 +62,9 @@ | |||
|
|||
@InitBinder("addCategoryForm") | |||
protected void initBinder(WebDataBinder binder) { | |||
StringTrimmerEditor editor = new StringTrimmerEditor(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Вот почему у тебя тесты падать начали -- ты зря удалил этот эдитор -- он для другого и нужен здесь.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Я добавил тримы непосредственно в реализацию кастомэдитора и все чеки прошли.
Возможно, я неверно трактовал эту проверку, но исходя из того что мы везде тримим пробелы, я решил это вынести.
И еще один момент, если мы оставим этот эдитор, то у нас не будет это все корректно работать , я пока не капнул почему, но моя догадка, что ЛУЧШЕ использовать только один эдитор.
Как ты считаешь ??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ни разу не имел дел с более чем одним валидатором, поэтому придется тебе экспериментировать и проверять что/как можно, а что нельзя. Если смотреть с точки зрения принципа единой ответственности (SRP), то лучше держать проверки отдельно -- и реюзать проще и логика не "слипается".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ну вот я и эксперементировал , и если делать два подряд - выполняется только последний......
Еще попробую покрутить, но пока такие результаты.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: Only one single registered custom editor per property path is supported.
(c) http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/validation/DataBinder.html#registerCustomEditor-java.lang.Class-java.lang.String-java.beans.PropertyEditor-
Тогда надо либо попробовать какие-либо конвертеры использовать, либо использовать паттерн декоратор (и вкладывать один в другой).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to re-implement StringTrimmerEditor
and don't re-use this class then we don't need this flags because we're not using them, right?
Then, implement our own editor that do a trimming and also replace hyphens. Hm. Not ideal, but we have tests after all, so we can refactor this any time.
And also add the comment why we're not using StringTrimmerEditor
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes , i will not use StringTrimEditor
class , but i need use boolean
.
I need it because we want separate functionality CustomEditor
.
If we have true
- trim String , if we have false
or empty
value - not trim String.
Do you agree ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're going to add flag that always will have value true
, right? As far I understand we'll use this converter for category and country names. For them we always need to trim the string, right?
And now I'm still don't understand why we need this flag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not exactly ))
Maybe i do , and you will see ... )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.
22760b2
to
8e3be2d
Compare
@@ -24,6 +24,8 @@ value.too-short = Value is less than allowable minimum of {min} characters | |||
value.too-long = Value is greater than allowable maximum of {max} characters | |||
value.invalid-length = Value length must be equals to {max} characters | |||
value.hyphen = Value must not start or end with hyphen | |||
value.hyphen_repeat_en = Value must not contain repetition of hyphen | |||
value.hyphen_repeat_ru = Value must not contain repetition of hyphen |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we need such duplication? Please, join them and remove language postfix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And let's rename it to repeating_hyphen
.
23a9bb8
to
5a546bf
Compare
It's a normal working process. Especially when we're discussed about how to achieve our goal. |
} | ||
|
||
if (text.contains(" ")) { | ||
text = text.replaceAll(REPEATING_SPACES_REGEXP, " "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIR replaceAll
will compile the regexp on every method's invocation. Let's use Pattern
and compile the regexp only once.
5a546bf
to
af6a087
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're closed to finishing this issue! :)
@@ -42,6 +42,9 @@ | |||
public static final String CATEGORY_NAME_EN_REGEXP = "[- a-zA-Z]+"; | |||
public static final String CATEGORY_NAME_RU_REGEXP = "[- а-яёА-ЯЁ]+"; | |||
public static final String CATEGORY_NAME_NO_HYPHEN_REGEXP = "[ \\p{L}]([- \\p{L}]+[ \\p{L}])*"; | |||
// CheckStyle: ignore LineLength for next 1 line | |||
@SuppressWarnings("PMD") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which exactly warning from PMD you're disabling? (Hint: git grep @SuppressWarnings
to find examples)
Also, if we're using @SuppressWarnings
we can suppress CheckStyle's warning too: @SuppressWarnings({"PMD.LongVariable", "checkstyle:linelength"})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where can i read about SuppressWarnings
??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know... I didn't write docs for that yet (tickets already exist).
} | ||
|
||
if (text.contains(" ")) { | ||
text = text.replaceAll(String.valueOf(REP_SPACES), " "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're missed the point: we don't want to use String.replaceAll
at all. Instead we should use Pattern
and Matcher
to do the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did it .
@RequiredArgsConstructor | ||
public class ReplaceRepeatingSpacesEditor extends PropertyEditorSupport { | ||
private static final String REPEATING_SPACES_REGEXP = "[ ]{2,}"; | ||
private static final Pattern REP_SPACES = Pattern.compile(REPEATING_SPACES_REGEXP); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename this member to REPEATING_SPACES
*/ | ||
@RequiredArgsConstructor | ||
public class ReplaceRepeatingSpacesEditor extends PropertyEditorSupport { | ||
private static final String REPEATING_SPACES_REGEXP = "[ ]{2,}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see why we need this as a separate constant. Inline this string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me know (by sending e-mail or leaving comment here) once you update this branch (because I don't receive notifications and have to check for any updated manually).
Ok , sorry for delay , i m on holiday ) |
@bodom91 No problem, I just wanted to say that I stopped polling this PR every day and now I'm waiting when you ping me. |
@bodom91 Have a great time there! |
070aa92
to
1edb4ed
Compare
You can check it. =) |
@bodom91 Ok, thank you! It's in my todo list for today. |
LGTM. Please, squash commits. |
// We can't use StringTrimmerEditor here because "only one single registered custom editor per property path is supported". | ||
ReplaceRepeatingSpacesEditor nameEditor = new ReplaceRepeatingSpacesEditor(true); | ||
binder.registerCustomEditor(String.class, "name", nameEditor); | ||
binder.registerCustomEditor(String.class, "nameRu", nameEditor); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, it would be good if you also will change the name from nameEditor
to editor
. I don't see a reason for such renaming.
1edb4ed
to
ae8a699
Compare
Merged in c8f2dca commit. Thank you for your patience and contribution! |
This change is