Skip to content

Commit

Permalink
(#981) Renamed Before to PrefixOf, After to SuffixOf
Browse files Browse the repository at this point in the history
  • Loading branch information
igor committed Feb 2, 2019
1 parent 5780c4d commit 3abfb4c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*
* @since 1.0
*/
public final class Before extends TextEnvelope {
public final class PrefixOf extends TextEnvelope {

/**
* Ctor.
Expand All @@ -41,16 +41,16 @@ public final class Before extends TextEnvelope {
*/
@SuppressWarnings({"PMD.CallSuperInConstructor",
"PMD.ConstructorOnlyInitializesOrCallOtherConstructors"})
public Before(final String text, final String boundary) {
public PrefixOf(final String text, final String boundary) {
super((Scalar<String>) () -> {
final String before;
final String prefix;
final int idx = text.indexOf(boundary);
if (idx >= 0) {
before = text.substring(0, idx);
prefix = text.substring(0, idx);
} else {
before = text;
prefix = text;
}
return before;
return prefix;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@
* <p>There is no thread-safety guarantee.
*
* @since 1.0
* @todo #981:30min Update qulice version(min. 0.18.10) and remove
* constructor suppress warnings which existence of is
* not needed, but is a bug in currently used version
*/
public final class After extends TextEnvelope {
public final class SuffixOf extends TextEnvelope {

/**
* Ctor.
Expand All @@ -44,16 +41,16 @@ public final class After extends TextEnvelope {
*/
@SuppressWarnings({"PMD.CallSuperInConstructor",
"PMD.ConstructorOnlyInitializesOrCallOtherConstructors"})
public After(final String text, final String boundary) {
public SuffixOf(final String text, final String boundary) {
super((Scalar<String>) () -> {
final String after;
final String suffix;
final int idx = text.indexOf(boundary);
if (idx >= 0) {
after = text.substring(idx + boundary.length());
suffix = text.substring(idx + boundary.length());
} else {
after = "";
suffix = "";
}
return after;
return suffix;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
import org.llorllale.cactoos.matchers.TextIs;

/**
* Test case for {@link Before}.
* Test case for {@link PrefixOf}.
*
* @since 1.0
*/
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
public final class BeforeTest {
public final class PrefixOfTest {

/**
* Ensures that Before is returning given string if
Expand All @@ -43,7 +43,7 @@ public final class BeforeTest {
public void returnsInputIfThereIsNoBoundary() {
new Assertion<>(
"Given strings are not equal",
() -> new Before("Cactoos", "bnd"),
() -> new PrefixOf("Cactoos", "bnd"),
new TextIs("Cactoos")
).affirm();
}
Expand All @@ -56,7 +56,7 @@ public void returnsInputIfThereIsNoBoundary() {
public void returnsEmptyIfStringIsBoundary() {
new Assertion<>(
"Given string is not empty",
() -> new Before("Boundary", "Boundary"),
() -> new PrefixOf("Boundary", "Boundary"),
new TextIs("")
).affirm();
}
Expand All @@ -69,7 +69,7 @@ public void returnsEmptyIfStringIsBoundary() {
public void returnsBeforeBoundaryString() {
new Assertion<>(
"Given strings are not equal",
() -> new Before("Anti-pattern", "-pattern"),
() -> new PrefixOf("Anti-pattern", "-pattern"),
new TextIs("Anti")
).affirm();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
import org.llorllale.cactoos.matchers.TextIs;

/**
* Test case for {@link After}.
* Test case for {@link SuffixOf}.
*
* @since 1.0
*/
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
public final class AfterTest {
public final class SuffixOfTest {

/**
* Ensures that After is returning empty string if
Expand All @@ -43,7 +43,7 @@ public final class AfterTest {
public void returnsEmptyIfThereIsNoBoundary() {
new Assertion<>(
"Given string is not empty",
() -> new After("Cactoos with description", "after"),
() -> new SuffixOf("Cactoos with description", "after"),
new TextIs("")
).affirm();
}
Expand All @@ -56,7 +56,7 @@ public void returnsEmptyIfThereIsNoBoundary() {
public void returnsEmptyIfStringIsBoundary() {
new Assertion<>(
"Given string is not empty",
() -> new After("Boundary", "Boundary"),
() -> new SuffixOf("Boundary", "Boundary"),
new TextIs("")
).affirm();
}
Expand All @@ -69,7 +69,7 @@ public void returnsEmptyIfStringIsBoundary() {
public void returnsAfterBoundaryString() {
new Assertion<>(
"Given strings are not equal",
() -> new After("Anti-pattern", "Anti-"),
() -> new SuffixOf("Anti-pattern", "Anti-"),
new TextIs("pattern")
).affirm();
}
Expand Down

1 comment on commit 3abfb4c

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 3abfb4c Feb 2, 2019

Choose a reason for hiding this comment

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

I wasn't able to retrieve PDD puzzles from the code base and submit them to GitHub. If you think that it's a bug on our side, please submit it to yegor256/0pdd:

set -x && set -e && set -o pipefail && cd /tmp/0pdd20190201-4-12i8uyd/yegor256/cactoos && git config --local core.autocrlf false && git reset origin/master --hard --quiet && git clean --force -d && git fetch --quiet && git checkout master && git rebase --abort || true && git rebase --autostash...

Please, copy and paste this stack trace to GitHub:

Exec::Error
set -x && set -e && set -o pipefail && cd /tmp/0pdd20190201-4-12i8uyd/yegor256/cactoos && git config --local core.autocrlf false && git reset origin/master --hard --quiet && git clean --force -d && git fetch --quiet && git checkout master && git rebase --abort || true && git rebase --autostash --strategy-option=theirs origin/master [1]:
bash: warning: setlocale: LC_ALL: cannot change locale (UTF-8)
+ set -e
+ set -o pipefail
+ cd /tmp/0pdd20190201-4-12i8uyd/yegor256/cactoos
+ git config --local core.autocrlf false
+ git reset origin/master --hard --quiet
+ git clean --force -d
+ git fetch --quiet
+ git checkout master
Previous HEAD position was 7e9d788... (#1052) LoggingInputStream.read() of empty stream should return -1
Switched to branch 'master'
+ git rebase --abort
+ git rebase --autostash --strategy-option=theirs origin/master
fatal: Could not parse object 'b9fd3e6532b687c9f646c2729e715152514d791b^'
Unknown exit code (128) from command: git-merge-recursive b9fd3e6532b687c9f646c2729e715152514d791b^ -- HEAD b9fd3e6532b687c9f646c2729e715152514d791b

Your branch and 'origin/master' have diverged,
and have 1 and 1693 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)
First, rewinding head to replay your work on top of it...

/app/objects/exec.rb:60:in `block (2 levels) in run'
/app/vendor/ruby-2.6.0/lib/ruby/2.6.0/open3.rb:219:in `popen_run'
/app/vendor/ruby-2.6.0/lib/ruby/2.6.0/open3.rb:101:in `popen3'
/app/objects/exec.rb:54:in `block in run'
/app/vendor/ruby-2.6.0/lib/ruby/2.6.0/timeout.rb:93:in `block in timeout'
/app/vendor/ruby-2.6.0/lib/ruby/2.6.0/timeout.rb:33:in `block in catch'
/app/vendor/ruby-2.6.0/lib/ruby/2.6.0/timeout.rb:33:in `catch'
/app/vendor/ruby-2.6.0/lib/ruby/2.6.0/timeout.rb:33:in `catch'
/app/vendor/ruby-2.6.0/lib/ruby/2.6.0/timeout.rb:108:in `timeout'
/app/objects/exec.rb:53:in `run'
/app/objects/git_repo.rb:110:in `pull'
/app/objects/git_repo.rb:75:in `push'
/app/objects/job.rb:36:in `proceed'
/app/objects/job_starred.rb:33:in `proceed'
/app/objects/job_recorded.rb:32:in `proceed'
/app/objects/job_emailed.rb:35:in `proceed'
/app/objects/job_commiterrors.rb:36:in `proceed'
/app/objects/job_detached.rb:48:in `exclusive'
/app/objects/job_detached.rb:36:in `block in proceed'
/app/objects/job_detached.rb:36:in `fork'
/app/objects/job_detached.rb:36:in `proceed'
/app/0pdd.rb:354:in `block in <top (required)>'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1635:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1635:in `block in compile!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:992:in `block (3 levels) in route!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1011:in `route_eval'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:992:in `block (2 levels) in route!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1040:in `block in process_route'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1038:in `catch'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1038:in `process_route'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:990:in `block in route!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:989:in `each'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:989:in `route!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1097:in `block in dispatch!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1076:in `block in invoke'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1076:in `catch'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1076:in `invoke'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1094:in `dispatch!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:924:in `block in call!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1076:in `block in invoke'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1076:in `catch'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1076:in `invoke'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:924:in `call!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:913:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-protection-2.0.4/lib/rack/protection/xss_header.rb:18:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-protection-2.0.4/lib/rack/protection/path_traversal.rb:16:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-protection-2.0.4/lib/rack/protection/json_csrf.rb:26:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-protection-2.0.4/lib/rack/protection/base.rb:50:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-protection-2.0.4/lib/rack/protection/base.rb:50:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-protection-2.0.4/lib/rack/protection/frame_options.rb:31:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-2.0.6/lib/rack/logger.rb:15:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-2.0.6/lib/rack/common_logger.rb:33:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:231:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:224:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-2.0.6/lib/rack/head.rb:12:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-2.0.6/lib/rack/method_override.rb:22:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:194:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1957:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1502:in `block in call'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1729:in `synchronize'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1502:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-2.0.6/lib/rack/handler/webrick.rb:86:in `service'
/app/vendor/ruby-2.6.0/lib/ruby/2.6.0/webrick/httpserver.rb:140:in `service'
/app/vendor/ruby-2.6.0/lib/ruby/2.6.0/webrick/httpserver.rb:96:in `run'
/app/vendor/ruby-2.6.0/lib/ruby/2.6.0/webrick/server.rb:307:in `block in start_thread'

Please sign in to comment.