Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/yegor256/cactoos into 790
Browse files Browse the repository at this point in the history
  • Loading branch information
proshin-roman committed May 8, 2018
2 parents dae27df + f9315fe commit 2b934bd
Show file tree
Hide file tree
Showing 41 changed files with 1,017 additions and 197 deletions.
9 changes: 4 additions & 5 deletions .rultor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@ assets:
pubring.gpg: zerocracy/home#assets/pubring.gpg
secring.gpg: zerocracy/home#assets/secring.gpg
env:
MAVEN_OPTS: -XX:MaxPermSize=256m -Xmx1g
JAVA_OPTS: -XX:MaxPermSize=256m -Xmx1g
MAVEN_OPTS: -Xmx1g
JAVA_OPTS: -Xmx1g
install: |
sudo gem install --no-rdoc --no-ri pdd
sudo gem install --no-rdoc --no-ri xcop
architect:
- yegor256
- llorllale
- yegor256
merge:
script: |
pdd --file=/dev/null
mvn clean install -Pqulice --errors --settings ../settings.xml
mvn clean site -Psite --errors --settings ../settings.xml
mvn clean
pdd --source=$(pwd) --verbose --file=/dev/null
deploy:
script: |
mvn clean deploy -Pqulice --errors --settings ../settings.xml
Expand Down
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ cache:
- $HOME/.m2
script:
- set -e
- mvn clean site -Psite --errors --batch-mode
- pdd --file=/dev/null
- mvn clean install -Pqulice --errors --batch-mode
- mvn clean site -Psite --errors --batch-mode
install:
- gem install pdd
- gem install est
- gem install xcop
env:
global:
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/cactoos/Text.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*
* <p>If you don't want to have any checked exceptions being thrown
* out of your {@link Text}, you can use
* {@link UncheckedText} decorator.</p>
* {@link org.cactoos.text.UncheckedText} decorator.</p>
*
* <p>There is no thread-safety guarantee.
*
Expand Down Expand Up @@ -62,13 +62,15 @@ final class NoNulls implements Text {
* The origin text.
*/
private final Text origin;

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

@Override
public String asString() throws IOException {
if (this.origin == null) {
Expand All @@ -85,5 +87,4 @@ public String asString() throws IOException {
return string;
}
}

}
10 changes: 10 additions & 0 deletions src/main/java/org/cactoos/func/BiFuncOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.cactoos.BiProc;
import org.cactoos.Func;
import org.cactoos.Proc;
import org.cactoos.Scalar;

/**
* Represents many possible inputs as {@link BiFunc}.
Expand Down Expand Up @@ -56,6 +57,14 @@ public BiFuncOf(final Z result) {
this((first, second) -> result);
}

/**
* Ctor.
* @param scalar The scalar
*/
public BiFuncOf(final Scalar<Z> scalar) {
this((first, second) -> scalar.value());
}

/**
* Ctor.
* @param fnc The func
Expand Down Expand Up @@ -128,4 +137,5 @@ private BiFuncOf(final BiFunc<X, Y, Z> fnc) {
public Z apply(final X first, final Y second) throws Exception {
return this.func.apply(first, second);
}

}
19 changes: 8 additions & 11 deletions src/main/java/org/cactoos/io/DigestEnvelope.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,19 @@ public DigestEnvelope(

@Override
public byte[] asBytes() throws IOException {
try {
try (final InputStream stream = this.source.stream()) {
final MessageDigest msg = MessageDigest.getInstance(this.algorithm);
try (final InputStream stream = this.source.stream()) {
final byte[] buf = new byte[this.size];
while (true) {
final int len = stream.read(buf);
if (len < 0) {
break;
}
msg.update(buf, 0, len);
final byte[] buf = new byte[this.size];
while (true) {
final int len = stream.read(buf);
if (len < 0) {
break;
}
return msg.digest();
msg.update(buf, 0, len);
}
return msg.digest();
} catch (final NoSuchAlgorithmException ex) {
throw new IOException(ex);
}
}

}
2 changes: 1 addition & 1 deletion src/main/java/org/cactoos/io/TeeInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public int available() throws IOException {
@Override
public void close() throws IOException {
this.input.close();
this.output.close();
this.output.flush();
}

@Override
Expand Down
18 changes: 2 additions & 16 deletions src/main/java/org/cactoos/iterable/IterableOfBooleans.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,14 @@
*/
package org.cactoos.iterable;

import java.util.ArrayList;
import java.util.Collection;
import org.cactoos.iterator.IteratorOfBooleans;

/**
* Iterable of boolean values.
*
* @author Vedran Vatavuk (123vgv@gmail.com)
* @version $Id$
* @since 1.0
* @todo #748:30min Introduce IteratorOfBooleans, IteratorOfChars,
* IteratorOfBytes and IteratorOfDoubles which will take array of their
* related primitive types (boolean, char, byte, double) and produce iterator
* of reference type (Boolean, Character, Byte, Double).
* Refactor appropriate IterableOf* classes by using those newly created
* iterators to avoid unnecessary copying elements to a new array.
*/
public final class IterableOfBooleans extends IterableEnvelope<Boolean> {

Expand All @@ -46,13 +39,6 @@ public final class IterableOfBooleans extends IterableEnvelope<Boolean> {
* @param values Boolean values
*/
public IterableOfBooleans(final boolean... values) {
super(() -> {
final Collection<Boolean> iterable =
new ArrayList<>(values.length);
for (final boolean value: values) {
iterable.add(value);
}
return iterable;
});
super(() -> new IterableOf<>(new IteratorOfBooleans(values)));
}
}
5 changes: 5 additions & 0 deletions src/main/java/org/cactoos/iterable/IterableOfBytes.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
* @author Vedran Vatavuk (123vgv@gmail.com)
* @version $Id$
* @since 1.0
* @todo #803:30min Introduce IteratorOfBytes and IteratorOfDoubles which will
* take array of their related primitive types (byte, double) and produce
* iterator of reference type (Byte, Double).
* Refactor appropriate IterableOf* classes by using those newly created
* iterators to avoid unnecessary copying elements to a new array.
*/
public final class IterableOfBytes extends IterableEnvelope<Byte> {

Expand Down
12 changes: 2 additions & 10 deletions src/main/java/org/cactoos/iterable/IterableOfChars.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
*/
package org.cactoos.iterable;

import java.util.ArrayList;
import java.util.Collection;
import org.cactoos.iterator.IteratorOfChars;

/**
* Iterable of characters.
Expand All @@ -40,13 +39,6 @@ public final class IterableOfChars extends IterableEnvelope<Character> {
* @param chars Characters
*/
public IterableOfChars(final char... chars) {
super(() -> {
final Collection<Character> iterable =
new ArrayList<>(chars.length);
for (final char chr: chars) {
iterable.add(chr);
}
return iterable;
});
super(() -> new IterableOf<>(new IteratorOfChars(chars)));
}
}
21 changes: 5 additions & 16 deletions src/main/java/org/cactoos/iterable/IterableOfFloats.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,15 @@
*/
package org.cactoos.iterable;

import java.util.ArrayList;
import java.util.Collection;
import org.cactoos.iterator.IteratorOfFloats;
import org.cactoos.scalar.UncheckedScalar;

/**
* Iterable of float values.
*
* @author Vedran Vatavuk (123vgv@gmail.com)
* @version $Id$
* @since 1.0
* @todo #748:30min Introduce IteratorOfFloats, IteratorOfInts,
* IteratorOfLongs and IteratorOfShorts which will take array of their
* related primitive types (float, int, long, short) and produce iterator
* of reference type (Float, Integer, Long, Short).
* Refactor appropriate IterableOf* classes by using those newly created
* iterators to avoid unnecessary copying elements to a new array.
*/
public final class IterableOfFloats extends IterableEnvelope<Float> {

Expand All @@ -47,13 +41,8 @@ public final class IterableOfFloats extends IterableEnvelope<Float> {
*/
@SuppressWarnings("PMD.AvoidUsingShortType")
public IterableOfFloats(final float... values) {
super(() -> {
final Collection<Float> iterable =
new ArrayList<>(values.length);
for (final float value: values) {
iterable.add(value);
}
return iterable;
});
super(() -> ()
-> new UncheckedScalar<>(() -> new IteratorOfFloats(values)).value()
);
}
}
15 changes: 5 additions & 10 deletions src/main/java/org/cactoos/iterable/IterableOfInts.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
*/
package org.cactoos.iterable;

import java.util.ArrayList;
import java.util.Collection;
import org.cactoos.iterator.IteratorOfInts;
import org.cactoos.scalar.UncheckedScalar;

/**
* Iterable of integer values.
Expand All @@ -40,13 +40,8 @@ public final class IterableOfInts extends IterableEnvelope<Integer> {
* @param values Integer values
*/
public IterableOfInts(final int... values) {
super(() -> {
final Collection<Integer> iterable =
new ArrayList<>(values.length);
for (final int value: values) {
iterable.add(value);
}
return iterable;
});
super(() -> ()
-> new UncheckedScalar<>(() -> new IteratorOfInts(values)).value()
);
}
}
5 changes: 5 additions & 0 deletions src/main/java/org/cactoos/iterable/IterableOfLongs.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
* @author Vedran Vatavuk (123vgv@gmail.com)
* @version $Id$
* @since 1.0
* @todo #802:30min Introduce IteratorOfLongs and IteratorOfShorts which will
* take array of their related primitive types (long, short) and
* produce iterator of reference type (Long, Short).
* Refactor appropriate IterableOf* classes by using those newly created
* iterators to avoid unnecessary copying elements to a new array.
*/
public final class IterableOfLongs extends IterableEnvelope<Long> {

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/cactoos/iterator/Endless.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import java.util.Iterator;
import org.cactoos.Scalar;
import org.cactoos.iterable.IterableOf;
import org.cactoos.scalar.UncheckedScalar;

/**
Expand Down Expand Up @@ -77,6 +76,6 @@ public boolean hasNext() {

@Override
public T next() {
return new IterableOf<T>(this.origin.value()).iterator().next();
return this.origin.value();
}
}
73 changes: 73 additions & 0 deletions src/main/java/org/cactoos/iterator/IteratorOfBooleans.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* 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.iterator;

import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.concurrent.atomic.AtomicInteger;

/**
* Iterator that returns the set of booleans.
*
* <p>There is no thread-safety guarantee.</p>
*
* @author Krzysztof Krason (Krzysztof.Krason@gmail.com)
* @version $Id$
* @since 0.32
*/
public final class IteratorOfBooleans implements Iterator<Boolean> {
/**
* The list of items to iterate.
*/
private final boolean[] list;

/**
* Current position.
*/
private final AtomicInteger position;

/**
* Ctor.
* @param items Items to iterate
*/
public IteratorOfBooleans(final boolean... items) {
this.list = items;
this.position = new AtomicInteger(0);
}

@Override
public boolean hasNext() {
return this.position.intValue() < this.list.length;
}

@Override
public Boolean next() {
if (!this.hasNext()) {
throw new NoSuchElementException(
"The iterator doesn't have any more items"
);
}
return this.list[this.position.getAndIncrement()];
}
}
Loading

0 comments on commit 2b934bd

Please sign in to comment.