-
Notifications
You must be signed in to change notification settings - Fork 171
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
Added Capitalized #1465
Conversation
Added EO version of StringUtils.capitalize Signed-off-by: kokodyn <[email protected]>
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.
@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(); |
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.
@kokodyn Let's remove mutable variable from here. I guess Ternary
can be used
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.
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", |
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.
@kokodyn I suggest must
instead of cannot
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 prefer to use "Can't" because as I see it it used commonly in other tests in similar context.
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.
@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)
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.
done
* | ||
* @since 0.46 | ||
*/ | ||
public class Capitalized extends TextEnvelope { |
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.
@kokodyn May be we should name it Title
instead?
Should it make all non-first characters lower-cased?
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 will create ticket for "Capitalized" issue and we can discuss further,
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 created issue for this:
#1466
* | ||
* @since 0.46 | ||
*/ | ||
public class Capitalized extends TextEnvelope { |
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.
@kokodyn The class should be final
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.
done
*/ | ||
package org.cactoos.text; | ||
|
||
import org.junit.Test; |
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.
@kokodyn Please use Junit 5
and make class final
, but not public
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 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"; |
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.
@kokodyn I believe this constant is not necessary. If it causes Qulice complain, it would be better to suppress that.
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.
done
Signed-off-by: kokodyn <[email protected]>
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
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.
@kokodyn There's more
@@ -68,8 +65,8 @@ public void capitalizeSingleUpperCaseText() { | |||
public void capitalizeTextStartingWithUpperCaseCharacter() { |
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.
@kokodyn public
is not necessary
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.
done
super( | ||
new TextOf( | ||
() -> { | ||
final Func<String, String> capitalize = cap -> { |
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.
@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
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. Not sure what does it mean "without extra checks". Please look at my proposition in newest commit.
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.
@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.
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.
@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
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.
@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 addTitled
and replaceUpper
in this class.
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.
@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 @todo
s 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.
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.
@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.
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.
@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.
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.
@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.
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.
@victornoel Yes we can use tittle case without introducing any more class.
Signed-off-by: kokodyn <[email protected]>
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.
@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(), |
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.
@kokodyn I believe you can use directly StartsWith
instead of passing it as a lambda since it implements Scalar<Boolean>
.
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.
@victornoel done
final Text titled = new TextOf( | ||
Character.toChars( | ||
Character.toTitleCase( | ||
cap.asString().codePointAt(0) | ||
) | ||
) | ||
); |
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.
@kokodyn there is something strange with indentation here
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.
@victornoel I hope now it looks better.
}; | ||
return new Ternary<Text>( | ||
text, | ||
t -> new IsBlank(t).value(), |
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.
@kokodyn here too you can directly pass IsBlank
instead of a lambda
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.
@victornoel done
Signed-off-by: kokodyn <[email protected]>
Signed-off-by: kokodyn <[email protected]>
Signed-off-by: kokodyn <[email protected]>
new TextOf( | ||
Character.toChars( | ||
Character.toTitleCase( | ||
new Sub(text, 0, 1).asString().codePointAt(0) |
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.
@kokodyn I believe you can directly write new TextOf(Character.toTitleCase(text.asString().codePointAt(0)))
no?
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.
@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]>
@andreoss could you finish the review? |
) | ||
), | ||
new Sub(text, 1) | ||
) |
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.
@kokodyn The indentation looks odd here. And at 70 as well.
You can also use lambda without return
here.
@victornoel Everything but the indentation looks good. |
@rultor merge |
@kokodyn thx for your patience |
@victornoel OK, I'll try to merge now. You can check the progress of the merge here |
@victornoel Done! FYI, the full log is here (took me 9min) |
Code review was too long (15 days), architects (@victornoel) were penalized, see §55 |
@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 quality acceptable |
@victornoel @andreoss @sereshqua |
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]