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

Added Capitalized #1465

Merged
merged 7 commits into from
Oct 4, 2020
Merged

Added Capitalized #1465

merged 7 commits into from
Oct 4, 2020

Conversation

kokodyn
Copy link
Contributor

@kokodyn kokodyn commented Sep 18, 2020

Added EO version of StringUtils.capitalize

I hope for your understanding, this is my first pull request to open source project.
Signed-off-by: kokodyn [email protected]

Added EO version of StringUtils.capitalize

Signed-off-by: kokodyn <[email protected]>
Copy link
Contributor

@andreoss andreoss left a comment

Choose a reason for hiding this comment

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

@kokodyn Please see my comments.
@victornoel There's no issue attached to this PR, should we create one?

super(
new TextOf(
() -> {
String capitalized = text.asString();
Copy link
Contributor

Choose a reason for hiding this comment

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

@kokodyn Let's remove mutable variable from here. I guess Ternary can be used

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done but I am not fully convinced to using Ternary. It seems be more complicated than previous version.

@Test
public void capitalizeEmptyText() {
new Assertion<>(
"Can't capitalize an empty text",
Copy link
Contributor

Choose a reason for hiding this comment

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

@kokodyn I suggest must instead of cannot

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I prefer to use "Can't" because as I see it it used commonly in other tests in similar context.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@kokodyn please let's use must as it is the default we use in cactoos (there are still examples where can't is used but this should be changed bit by bit)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

*
* @since 0.46
*/
public class Capitalized extends TextEnvelope {
Copy link
Contributor

Choose a reason for hiding this comment

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

@kokodyn May be we should name it Title instead?
Should it make all non-first characters lower-cased?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will create ticket for "Capitalized" issue and we can discuss further,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I created issue for this:
#1466

*
* @since 0.46
*/
public class Capitalized extends TextEnvelope {
Copy link
Contributor

Choose a reason for hiding this comment

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

@kokodyn The class should be final

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

*/
package org.cactoos.text;

import org.junit.Test;
Copy link
Contributor

Choose a reason for hiding this comment

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

@kokodyn Please use Junit 5 and make class final, but not public

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I hope I did it in proper way, I need to update path to @test annotation to allow Eclipse to handle it.

/**
* Text starting with upper case character.
*/
private static final String UPPER_CASE = "Abc";
Copy link
Contributor

Choose a reason for hiding this comment

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

@kokodyn I believe this constant is not necessary. If it causes Qulice complain, it would be better to suppress that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@codecov-commenter
Copy link

codecov-commenter commented Sep 18, 2020

Codecov Report

Merging #1465 into master will increase coverage by 0.06%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #1465      +/-   ##
============================================
+ Coverage     89.28%   89.34%   +0.06%     
+ Complexity     1661     1629      -32     
============================================
  Files           278      277       -1     
  Lines          3965     3904      -61     
  Branches        209      209              
============================================
- Hits           3540     3488      -52     
+ Misses          392      383       -9     
  Partials         33       33              
Impacted Files Coverage Δ Complexity Δ
src/main/java/org/cactoos/text/Capitalized.java 100.00% <100.00%> (ø) 5.00 <5.00> (?)
src/main/java/org/cactoos/scalar/Solid.java 90.00% <0.00%> (-10.00%) 3.00% <0.00%> (-1.00%)
src/main/java/org/cactoos/map/Synced.java 28.57% <0.00%> (-8.93%) 3.00% <0.00%> (-1.00%)
src/main/java/org/cactoos/map/MapEnvelope.java 91.66% <0.00%> (-6.12%) 15.00% <0.00%> (-15.00%)
src/main/java/org/cactoos/map/MapOf.java 100.00% <0.00%> (ø) 10.00% <0.00%> (-1.00%)
src/main/java/org/cactoos/map/Merged.java 100.00% <0.00%> (ø) 2.00% <0.00%> (ø%)
src/main/java/org/cactoos/map/Grouped.java 100.00% <0.00%> (ø) 1.00% <0.00%> (-1.00%)
src/main/java/org/cactoos/map/Solid.java
src/main/java/org/cactoos/map/Sticky.java

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update af979de...09b9113. Read the comment docs.

Copy link
Contributor

@andreoss andreoss left a comment

Choose a reason for hiding this comment

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

@kokodyn There's more

@@ -68,8 +65,8 @@ public void capitalizeSingleUpperCaseText() {
public void capitalizeTextStartingWithUpperCaseCharacter() {
Copy link
Contributor

Choose a reason for hiding this comment

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

@kokodyn public is not necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

super(
new TextOf(
() -> {
final Func<String, String> capitalize = cap -> {
Copy link
Contributor

Choose a reason for hiding this comment

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

@kokodyn
I believe it should be more like:

super(new Ternary<>(new IsBlank(text), () -> text, new Ternary<>(new StartsWith(...), ...);

Also, Func<String, String> should be a Text but without extra checks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. Not sure what does it mean "without extra checks". Please look at my proposition in newest commit.

Copy link
Contributor

Choose a reason for hiding this comment

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

@kokodyn It looks complicated.
Why it cannot be like that?

                new Ternary<Text>(
                    new IsBlank(text),
                    text,
                    new Joined(
                        "",
                        new Upper(new Sub(text, 0, 1)),
                        new Sub(text, 1)
                    )
                )

May be imperative approach was better here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@andreoss While working on that PR I realized that there is a difference between Upper and TitleCase:
https://stackoverflow.com/questions/31770995/difference-between-uppercase-and-titlecase

Copy link
Collaborator

Choose a reason for hiding this comment

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

@kokodyn I agree with @andreoss, why not use the much simpler example he proposes?

  • no need for testing if the first character is already title case or not, let's just do it as in @andreoss example above
  • let's use Upper for now
  • let's add a @todo to the class so that we add Titled and replace Upper in this class.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@kokodyn that's acceptable, but please take note that the purpose of cactoos is to be a sandbox area for experimenting with Zerocracy, on top of implementing this library. Hence in the future it would be best to follow the proper workflow which advocates for using @todos as a way to decompose work. Once from time to time, it is ok to not follow this, but this should remain the general nominal way of working here.

Copy link
Contributor Author

@kokodyn kokodyn Sep 27, 2020

Choose a reason for hiding this comment

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

@victornoel
i added @todo comment to with information what should be replaced in future.
I would like to have it proper working(and later replaced using by "EO Titled" ) instead of using Lower.
As I said before this is tricky difference beetwen Lower and Titled.
For instance:
Title case: Dž ->https://www.compart.com/en/unicode/U+01C5
Lower case: dž -> https://www.compart.com/en/unicode/U+01C6
Upper case: DŽ -> https://www.compart.com/en/unicode/U+01C4

However, if you are sure that Lower should be used please let me know.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@kokodyn I thought we were talking about Upper vs Titled, no? What I propose is to tackle this issue incrementally, so first we make it work with Upper because it's good enough, and then with the todo we explore how to have Capitalized use titled characters.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@kokodyn anywa, see my last comment about the current code, maybe we can just use title case as-is right now without introducing any new class.

Copy link
Contributor Author

@kokodyn kokodyn Sep 27, 2020

Choose a reason for hiding this comment

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

@victornoel Yes we can use tittle case without introducing any more class.

Copy link
Collaborator

@victornoel victornoel left a comment

Choose a reason for hiding this comment

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

@kokodyn here are some comments :) all of this seems a bit complex for now, let's see if we can simplify it bit by bit!

);
return
new Ternary<Text>(
() -> new StartsWith(cap, titled).value(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

@kokodyn I believe you can use directly StartsWith instead of passing it as a lambda since it implements Scalar<Boolean>.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines 58 to 64
final Text titled = new TextOf(
Character.toChars(
Character.toTitleCase(
cap.asString().codePointAt(0)
)
)
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

@kokodyn there is something strange with indentation here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@victornoel I hope now it looks better.

src/main/java/org/cactoos/text/Capitalized.java Outdated Show resolved Hide resolved
};
return new Ternary<Text>(
text,
t -> new IsBlank(t).value(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

@kokodyn here too you can directly pass IsBlank instead of a lambda

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@victornoel victornoel mentioned this pull request Sep 27, 2020
new TextOf(
Character.toChars(
Character.toTitleCase(
new Sub(text, 0, 1).asString().codePointAt(0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

@kokodyn I believe you can directly write new TextOf(Character.toTitleCase(text.asString().codePointAt(0))) no?

Copy link
Contributor Author

@kokodyn kokodyn Sep 27, 2020

Choose a reason for hiding this comment

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

@victornoel
Good point!
new TextOf(Character.toChars(Character.toTitleCase(text.asString().codePointAt(0))))
I believe this is the easiest version

Signed-off-by: kokodyn <[email protected]>
@victornoel
Copy link
Collaborator

@kokodyn I feel like we arrived to a good result :)

@andreoss could you take a last look to see if I haven't overlooked anything? thx

@victornoel
Copy link
Collaborator

@andreoss could you finish the review?

)
),
new Sub(text, 1)
)
Copy link
Contributor

Choose a reason for hiding this comment

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

@kokodyn The indentation looks odd here. And at 70 as well.
You can also use lambda without return here.

@andreoss
Copy link
Contributor

andreoss commented Oct 3, 2020

@victornoel Everything but the indentation looks good.

@victornoel
Copy link
Collaborator

@andreoss thx, I will merge as-is since it is not critical and I will most certainly touch this same code when solving #1460 :)

@victornoel
Copy link
Collaborator

@rultor merge

@victornoel
Copy link
Collaborator

@kokodyn thx for your patience

@rultor
Copy link
Collaborator

rultor commented Oct 4, 2020

@rultor merge

@victornoel OK, I'll try to merge now. You can check the progress of the merge here

@rultor rultor merged commit 36dd67b into yegor256:master Oct 4, 2020
@rultor
Copy link
Collaborator

rultor commented Oct 4, 2020

@rultor merge

@victornoel Done! FYI, the full log is here (took me 9min)

@0crat 0crat added the qa label Oct 4, 2020
@0crat
Copy link
Collaborator

0crat commented Oct 4, 2020

Code review was too long (15 days), architects (@victornoel) were penalized, see §55

@0crat
Copy link
Collaborator

0crat commented Oct 4, 2020

@sereshqua/z please review this job completed by @andreoss/z, as in §30; the job will be fully closed and all payments will be made when the quality review is completed

@0crat 0crat removed the 0crat/scope label Oct 4, 2020
@sereshqua
Copy link

@kokodyn please make sure you start all your comments with the name of the user they are referred to, see

@sereshqua
Copy link

@0crat quality acceptable

@kokodyn
Copy link
Contributor Author

kokodyn commented Oct 6, 2020

@victornoel @andreoss @sereshqua
Thanks for participate, comments etc.
i will try to make better PR more and more.
BR,
kokodyn

@kokodyn kokodyn deleted the CAPITALIZED branch October 7, 2020 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants