Skip to content

Commit

Permalink
Merge branch 'master' into 939
Browse files Browse the repository at this point in the history
  • Loading branch information
igor committed Feb 8, 2019
2 parents 3f50e1e + 773f8e5 commit 6969dcf
Show file tree
Hide file tree
Showing 36 changed files with 816 additions and 411 deletions.
6 changes: 5 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
Many thanks for your contribution, we truly appreciate it. We will appreciate it even more, if you make sure that you can say "YES" to each point in this short checklist:

- You made a small amount of changes (less than 100 lines, less than 10 files)
- You made changes related to only one bug (create separate PRs for separate problems)
- You made changes related to only one bug (create separate PRs for separate problems, or leave puzzles)
- You are ready to defend your changes (there will be a code review)
- You don't touch what you don't understand
- You ran the build locally and it passed
- Title begins with the issue's number, then a short title
- Description begins with the issue's number, then enumerates the changes - summarized - in bulletpoints
- Description does not contain GitHub keywords (https://help.github.com/articles/closing-issues-using-keywords/).
- You ran the build locally and it passed (see .travis.yml for all checks performed on PRs)
- Your commit messages comply with our rules (see .gitlint)

Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cache:
script:
- set -e
- pdd --file=/dev/null
- git log --not master --pretty=%B | gitlint
- git log --since="2019-02-01" --no-merges --pretty=%B | gitlint
- mvn clean site -Psite --errors --batch-mode
- mvn clean install -Pqulice --errors --batch-mode
install:
Expand Down
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,33 @@ Collection<String> filtered = new ListOf<>(
);
```

To flatten one iterable:
```java
new Joined<>(
new Mapped<>(
iter -> new IterableOf<>(
new CollectionOf<>(iter).toArray(new Integer[]{})
),
new IterableOf<>(new IterableOf<>(1, 2, 3, 4, 5, 6))
)
); // Iterable<Integer>
```

To flatten and join several iterables:
```java
new Joined<>(
new Mapped<>(
iter -> new IterableOf<>(
new CollectionOf<>(iter).toArray(new Integer[]{})
),
new Joined<>(
new IterableOf<>(new IterableOf<>(1, 2, 3)),
new IterableOf<>(new IterableOf<>(4, 5, 6))
)
)
); // Iterable<Integer>
```

To iterate a collection:

```java
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ The MIT License (MIT)
<parent>
<groupId>com.jcabi</groupId>
<artifactId>parent</artifactId>
<version>0.49.2</version>
<version>0.49.4</version>
</parent>
<groupId>org.cactoos</groupId>
<artifactId>cactoos</artifactId>
Expand All @@ -44,7 +44,7 @@ The MIT License (MIT)
<licenses>
<license>
<name>MIT</name>
<url>https://www.cactoos.org/LICENSE.txt</url>
<url>https://raw.githubusercontent.com/yegor256/cactoos/master/LICENSE.txt</url>
<distribution>site</distribution>
</license>
</licenses>
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/cactoos/func/IoCheckedBiProc.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
* @param <X> Type of input
* @param <Y> Type of input
* @since 0.22
* @todo #886:30min Avoid usage of null value in exec(first, second),
* which is against our design principles.
* This look like a duplication of functionality from IoCheckedBiFunc.
* Perhaphs, we do not need this class?
* Please take a look on #918 for more details.
*/
public final class IoCheckedBiProc<X, Y> implements BiProc<X, Y> {

Expand Down
35 changes: 0 additions & 35 deletions src/main/java/org/cactoos/func/Retry.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
package org.cactoos.func;

import org.cactoos.Func;
import org.cactoos.Proc;

/**
* Func that will try a few times before throwing an exception.
Expand All @@ -34,11 +33,6 @@
* @param <X> Type of input
* @param <Y> Type of output
* @since 0.8
* @todo #861:30min Avoid usage of null value in ctor(Proc),
* ctor(Proc, int), ctor(Proc, Func(Integer, Boolean)) which is against
* design principles.
* Perhaps in creating RetryProc?
* Please take a look on #551 and #843 for more details.
*/
public final class Retry<X, Y> implements Func<X, Y> {

Expand All @@ -52,35 +46,6 @@ public final class Retry<X, Y> implements Func<X, Y> {
*/
private final Func<Integer, Boolean> exit;

/**
* Ctor.
* @param proc Func original
* @since 0.12
*/
public Retry(final Proc<X> proc) {
this(new FuncOf<>(proc, null));
}

/**
* Ctor.
* @param proc Func original
* @param attempts Maximum number of attempts
* @since 0.12
*/
public Retry(final Proc<X> proc, final int attempts) {
this(new FuncOf<>(proc, null), attempts);
}

/**
* Ctor.
* @param proc Func original
* @param ext Exit condition, returns TRUE if there is no more reason to try
* @since 0.12
*/
public Retry(final Proc<X> proc, final Func<Integer, Boolean> ext) {
this(new FuncOf<>(proc, null), ext);
}

/**
* Ctor.
* @param fnc Func original
Expand Down
18 changes: 14 additions & 4 deletions src/main/java/org/cactoos/io/Joined.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,25 @@ public final class Joined implements Input {
*/
private final Iterable<Input> inputs;

/**
* Ctor.
* @param ipts Iterable of inputs
*/
public Joined(final Iterable<Input> ipts) {
this.inputs = ipts;
}

/**
* Ctor.
* @param first First input
* @param rest The rest
* @param rest The other inputs
*/
public Joined(final Input first, final Input... rest) {
this.inputs = new org.cactoos.iterable.Joined<>(
first,
new IterableOf<>(rest)
this(
new org.cactoos.iterable.Joined<>(
first,
new IterableOf<>(rest)
)
);
}

Expand Down
9 changes: 7 additions & 2 deletions src/main/java/org/cactoos/io/LoggingInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,13 @@ public LoggingInputStream(
@Override
public int read() throws IOException {
final byte[] buf = new byte[1];
this.read(buf);
return Byte.toUnsignedInt(buf[0]);
final int size;
if (this.read(buf) == -1) {
size = -1;
} else {
size = Byte.toUnsignedInt(buf[0]);
}
return size;
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/cactoos/text/Abbreviated.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
* <p>There is no thread-safety guarantee.
*
* @since 0.29
* @todo #897:30min Continue refactoring all classes implementing Text to extend
* TextEnvelope - asString() should be removed and implementation from
* TextEnvelope should be used.
* @todo #897:30min All classes implementing Text need to be refactored
* to extend TextEnvelope - asString() should be removed and implementation
* from TextEnvelope should be used.
*/
public final class Abbreviated implements Text {

Expand Down
18 changes: 4 additions & 14 deletions src/main/java/org/cactoos/text/ComparableText.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,21 @@
*
* @since 0.27
*/
public final class ComparableText implements Text, Comparable<Text> {

/**
* The origin.
*/
private final Text text;
public final class ComparableText extends TextEnvelope
implements Comparable<Text> {

/**
* Ctor.
* @param text The text
*/
public ComparableText(final Text text) {
this.text = text;
super(text);
}

@Override
public int compareTo(final Text other) {
return new UncheckedScalar<>(
() -> this.text.asString().compareTo(other.asString())
() -> this.asString().compareTo(other.asString())
).value();
}

@Override
public String asString() throws Exception {
return this.text.asString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,31 @@
*
* @since 0.1
*/
public final class LowerText extends TextEnvelope {
public final class Lowered extends TextEnvelope {

/**
* Ctor.
* @param text The text
*/
public LowerText(final String text) {
public Lowered(final String text) {
this(new TextOf(text));
}

/**
* Ctor.
* @param text The text
*/
public LowerText(final Text text) {
public Lowered(final Text text) {
this(text, Locale.ENGLISH);
}

/**
* Ctor.
* @param text The text
* @param lang Locale
* @param locale The locale
*/
public LowerText(final Text text, final Locale lang) {
super((Scalar<String>) () -> text.asString().toLowerCase(lang));
public Lowered(final Text text, final Locale locale) {
super((Scalar<String>) () -> text.asString().toLowerCase(locale));
}

}
2 changes: 1 addition & 1 deletion src/main/java/org/cactoos/text/NormalizedText.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public NormalizedText(final String text) {
*/
public NormalizedText(final Text text) {
super(
(Scalar<String>) () -> new ReplacedText(
(Scalar<String>) () -> new Replaced(
new TrimmedText(text),
"\\s+",
" "
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/cactoos/text/PaddedStartText.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public PaddedStartText(
final String original = text.asString();
return new JoinedText(
new TextOf(""),
new RepeatedText(
new Repeated(
new TextOf(symbol), length - original.length()
),
text
Expand Down
56 changes: 56 additions & 0 deletions src/main/java/org/cactoos/text/PrefixOf.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2017-2018 Yegor Bugayenko
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.cactoos.text;

import org.cactoos.Scalar;

/**
* Returns a text that is before given boundary.
*
* <p>There is no thread-safety guarantee.
*
* @since 1.0
*/
public final class PrefixOf extends TextEnvelope {

/**
* Ctor.
* @param text Text representing the text value
* @param boundary String to which text will be split
*/
@SuppressWarnings({"PMD.CallSuperInConstructor",
"PMD.ConstructorOnlyInitializesOrCallOtherConstructors"})
public PrefixOf(final String text, final String boundary) {
super((Scalar<String>) () -> {
final String prefix;
final int idx = text.indexOf(boundary);
if (idx >= 0) {
prefix = text.substring(0, idx);
} else {
prefix = text;
}
return prefix;
});
}
}
Loading

0 comments on commit 6969dcf

Please sign in to comment.