diff --git a/README.md b/README.md index d5de1c4f9a..7c12c98e27 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![Build Status](https://travis-ci.org/yegor256/cactoos.svg?branch=master)](https://travis-ci.org/yegor256/cactoos) [![Build status](https://ci.appveyor.com/api/projects/status/8vs8huy61og6jwif?svg=true)](https://ci.appveyor.com/project/yegor256/cactoos) -[![Javadoc](https://javadoc-emblem.rhcloud.com/doc/org.cactoos/cactoos/badge.svg?color=blue&prefix=v)](http://www.javadoc.io/doc/org.cactoos/cactoos) +[![Javadoc](http://www.javadoc.io/badge/org.cactoos/cactoos.svg)](http://www.javadoc.io/doc/org.cactoos/cactoos) [![PDD status](http://www.0pdd.com/svg?name=yegor256/cactoos)](http://www.0pdd.com/p?name=yegor256/cactoos) [![Maven Central](https://img.shields.io/maven-central/v/org.cactoos/cactoos.svg)](https://maven-badges.herokuapp.com/maven-central/org.cactoos/cactoos) [![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/yegor256/cactoos/blob/master/LICENSE.txt) @@ -242,6 +242,10 @@ Cactoos | Guava | Apache Commons | JDK 8 `TrimmedText` | - | `StringUtils.stripAll()` | `String#trim()` `UpperText` | - | - | `String#toUpperCase()` +## Questions + +Ask your questions related to cactoos library on [Stackoverflow](https://stackoverflow.com/questions/ask) with [cactoos](https://stackoverflow.com/tags/cactoos/info) tag. + ## How to contribute? Just fork the repo and send us a pull request. diff --git a/src/main/java/org/cactoos/BiFunc.java b/src/main/java/org/cactoos/BiFunc.java index 7ce632db5a..9a5c7cab86 100644 --- a/src/main/java/org/cactoos/BiFunc.java +++ b/src/main/java/org/cactoos/BiFunc.java @@ -26,6 +26,11 @@ /** * Function that accepts two arguments. * + *

If you don't want to have any checked exceptions being thrown + * out of your {@link BiFunc}, you can use + * {@link org.cactoos.func.UncheckedBiFunc} decorator. Also + * you may try {@link org.cactoos.func.IoCheckedBiFunc}.

+ * *

There is no thread-safety guarantee. * * @author Yegor Bugayenko (yegor256@gmail.com) diff --git a/src/main/java/org/cactoos/BiProc.java b/src/main/java/org/cactoos/BiProc.java index ba891a6bc3..f7c4c82e33 100644 --- a/src/main/java/org/cactoos/BiProc.java +++ b/src/main/java/org/cactoos/BiProc.java @@ -26,6 +26,11 @@ /** * Proc that accepts two arguments. * + *

If you don't want to have any checked exceptions being thrown + * out of your {@link BiProc}, you can use + * {@link org.cactoos.func.UncheckedBiProc} decorator. Also + * you may try {@link org.cactoos.func.IoCheckedBiProc}.

+ * *

There is no thread-safety guarantee. * * @author Yegor Bugayenko (yegor256@gmail.com) diff --git a/src/main/java/org/cactoos/Input.java b/src/main/java/org/cactoos/Input.java index a058450b2e..da20af6fd1 100644 --- a/src/main/java/org/cactoos/Input.java +++ b/src/main/java/org/cactoos/Input.java @@ -36,15 +36,17 @@ * new InputOf(new File("/tmp/names.txt")) * ).asString(); * - *

Here {@link InputOf} implements {@link Input} and behaves like - * one, providing read-only access to the encapsulated {@link java.io.File}.

+ *

Here {@link org.cactoos.io.InputOf} implements + * {@link Input} and behaves like + * one, providing read-only access to + * the encapsulated {@link java.io.File}.

* *

There is no thread-safety guarantee. * * @author Yegor Bugayenko (yegor256@gmail.com) * @author Fabricio Cabral (fabriciofx@gmail.com) * @version $Id$ - * @see InputOf + * @see org.cactoos.io.InputOf * @since 0.1 */ public interface Input { diff --git a/src/main/java/org/cactoos/Output.java b/src/main/java/org/cactoos/Output.java index 7412ba62f6..1fae173179 100644 --- a/src/main/java/org/cactoos/Output.java +++ b/src/main/java/org/cactoos/Output.java @@ -53,7 +53,6 @@ * @author Yegor Bugayenko (yegor256@gmail.com) * @version $Id$ * @see OutputTo - * @see org.cactoos.io.OutputTo * @since 0.1 */ public interface Output { diff --git a/src/main/java/org/cactoos/Proc.java b/src/main/java/org/cactoos/Proc.java index 8a652dd0e0..f8b88df209 100644 --- a/src/main/java/org/cactoos/Proc.java +++ b/src/main/java/org/cactoos/Proc.java @@ -26,6 +26,11 @@ /** * Procedure. * + *

If you don't want to have any checked exceptions being thrown + * out of your {@link Proc}, you can use + * {@link org.cactoos.func.UncheckedProc} decorator. Also + * you may try {@link org.cactoos.func.IoCheckedProc}.

+ * *

There is no thread-safety guarantee. * * @author Yegor Bugayenko (yegor256@gmail.com) diff --git a/src/main/java/org/cactoos/Text.java b/src/main/java/org/cactoos/Text.java index bedbf41346..f908f9e60a 100644 --- a/src/main/java/org/cactoos/Text.java +++ b/src/main/java/org/cactoos/Text.java @@ -29,6 +29,10 @@ /** * Text. * + *

If you don't want to have any checked exceptions being thrown + * out of your {@link Text}, you can use + * {@link UncheckedText} decorator.

+ * *

There is no thread-safety guarantee. * * @author Yegor Bugayenko (yegor256@gmail.com) diff --git a/src/main/java/org/cactoos/scalar/LongOf.java b/src/main/java/org/cactoos/bytes/Base64Bytes.java similarity index 65% rename from src/main/java/org/cactoos/scalar/LongOf.java rename to src/main/java/org/cactoos/bytes/Base64Bytes.java index bd071743de..b8c27b7c3c 100644 --- a/src/main/java/org/cactoos/scalar/LongOf.java +++ b/src/main/java/org/cactoos/bytes/Base64Bytes.java @@ -21,49 +21,38 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package org.cactoos.scalar; + +package org.cactoos.bytes; import java.io.IOException; -import org.cactoos.Scalar; -import org.cactoos.Text; -import org.cactoos.text.TextOf; +import java.util.Base64; +import org.cactoos.Bytes; /** - * Text as {@link Long}. - * - *

There is no thread-safety guarantee. + * Decodes all origin bytes using the Base64 encoding scheme. * - * @author Kirill (g4s8.public@gmail.com) + * @author Ilia Rogozhin (ilia.rogozhin@gmail.com) * @version $Id$ - * @since 0.2 + * @since 0.20.2 */ -public final class LongOf implements Scalar { - - /** - * Source text. - */ - private final Text origin; +public final class Base64Bytes implements Bytes { /** - * Ctor. - * - * @param string Number-string + * Origin bytes. */ - public LongOf(final String string) { - this(new TextOf(string)); - } + private final Bytes origin; /** * Ctor. * - * @param text Number-text + * @param origin Origin bytes */ - public LongOf(final Text text) { - this.origin = text; + public Base64Bytes(final Bytes origin) { + this.origin = origin; } @Override - public Long value() throws IOException { - return Long.valueOf(this.origin.asString()); + public byte[] asBytes() throws IOException { + return Base64.getDecoder().decode(this.origin.asBytes()); } } diff --git a/src/main/java/org/cactoos/scalar/FloatOf.java b/src/main/java/org/cactoos/bytes/BytesBase64.java similarity index 64% rename from src/main/java/org/cactoos/scalar/FloatOf.java rename to src/main/java/org/cactoos/bytes/BytesBase64.java index e3e396ada1..7208ca1dc7 100644 --- a/src/main/java/org/cactoos/scalar/FloatOf.java +++ b/src/main/java/org/cactoos/bytes/BytesBase64.java @@ -21,49 +21,37 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package org.cactoos.scalar; + +package org.cactoos.bytes; import java.io.IOException; -import org.cactoos.Scalar; -import org.cactoos.Text; -import org.cactoos.text.TextOf; +import java.util.Base64; +import org.cactoos.Bytes; /** - * Text as {@link Float}. - * - *

There is no thread-safety guarantee. + * Encodes all origin bytes using the Base64 encoding scheme. * - * @author Kirill (g4s8.public@gmail.com) + * @author Ilia Rogozhin (ilia.rogozhin@gmail.com) * @version $Id$ - * @since 0.2 + * @since 0.20.2 */ -public final class FloatOf implements Scalar { +public final class BytesBase64 implements Bytes { /** - * Source text. + * Origin bytes. */ - private final Text origin; - - /** - * Ctor. - * - * @param string Number-string - */ - public FloatOf(final String string) { - this(new TextOf(string)); - } + private final Bytes origin; /** * Ctor. - * - * @param text Number-text + * @param origin Origin bytes. */ - public FloatOf(final Text text) { - this.origin = text; + public BytesBase64(final Bytes origin) { + this.origin = origin; } @Override - public Float value() throws IOException { - return Float.valueOf(this.origin.asString()); + public byte[] asBytes() throws IOException { + return Base64.getEncoder().encode(this.origin.asBytes()); } } diff --git a/src/main/java/org/cactoos/bytes/package-info.java b/src/main/java/org/cactoos/bytes/package-info.java new file mode 100644 index 0000000000..220878a550 --- /dev/null +++ b/src/main/java/org/cactoos/bytes/package-info.java @@ -0,0 +1,32 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2017 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. + */ + +/** + * Bytes. + * + * @author Ilia Rogozhin (ilia.rogozhin@gmail.com) + * @version $Id$ + * @since 0.20.2 + */ +package org.cactoos.bytes; diff --git a/src/main/java/org/cactoos/func/IoCheckedBiProc.java b/src/main/java/org/cactoos/func/IoCheckedBiProc.java new file mode 100644 index 0000000000..a75d3b66ab --- /dev/null +++ b/src/main/java/org/cactoos/func/IoCheckedBiProc.java @@ -0,0 +1,78 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2017 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.func; + +import java.io.IOException; +import org.cactoos.BiProc; + +/** + * BiProc that doesn't throw checked {@link Exception}, but throws + * {@link IOException} instead. + * + *

There is no thread-safety guarantee. + * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @param Type of input + * @param Type of input + * @since 0.22 + */ +public final class IoCheckedBiProc implements BiProc { + + /** + * Original proc. + */ + private final BiProc proc; + + /** + * Ctor. + * @param prc Encapsulated func + */ + public IoCheckedBiProc(final BiProc prc) { + this.proc = prc; + } + + @Override + @SuppressWarnings + ( + { + "PMD.AvoidCatchingGenericException", + "PMD.AvoidRethrowingException" + } + ) + public void exec(final X first, final Y second) throws IOException { + try { + this.proc.exec(first, second); + } catch (final IOException ex) { + throw ex; + } catch (final InterruptedException ex) { + Thread.currentThread().interrupt(); + throw new IOException(ex); + // @checkstyle IllegalCatchCheck (1 line) + } catch (final Exception ex) { + throw new IOException(ex); + } + } + +} diff --git a/src/main/java/org/cactoos/func/MaxFunc.java b/src/main/java/org/cactoos/func/MaxFunc.java new file mode 100644 index 0000000000..52c2ea18b1 --- /dev/null +++ b/src/main/java/org/cactoos/func/MaxFunc.java @@ -0,0 +1,45 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2017 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.func; + +import org.cactoos.BiFunc; + +/** + * Function, finding max among two items. + * + * @author Alexander Dyadyushenko (gookven@gmail.com) + * @version $Id$ + * @param comparable type + * @since 0.9 + */ +public final class MaxFunc> implements BiFunc { + @Override + public T apply(final T first, final T second) throws Exception { + T max = first; + if (second.compareTo(max) > 0) { + max = second; + } + return max; + } +} diff --git a/src/main/java/org/cactoos/func/MinFunc.java b/src/main/java/org/cactoos/func/MinFunc.java new file mode 100644 index 0000000000..b760d35278 --- /dev/null +++ b/src/main/java/org/cactoos/func/MinFunc.java @@ -0,0 +1,45 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2017 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.func; + +import org.cactoos.BiFunc; + +/** + * Function, finding min among two items. + * + * @author Alexander Dyadyushenko (gookven@gmail.com) + * @version $Id$ + * @param comparable type + * @since 0.9 + */ +public final class MinFunc> implements BiFunc { + @Override + public T apply(final T first, final T second) throws Exception { + T min = first; + if (second.compareTo(min) < 0) { + min = second; + } + return min; + } +} diff --git a/src/main/java/org/cactoos/scalar/IntOf.java b/src/main/java/org/cactoos/func/UncheckedBiProc.java similarity index 64% rename from src/main/java/org/cactoos/scalar/IntOf.java rename to src/main/java/org/cactoos/func/UncheckedBiProc.java index 0264159b88..9b8c40c5d3 100644 --- a/src/main/java/org/cactoos/scalar/IntOf.java +++ b/src/main/java/org/cactoos/func/UncheckedBiProc.java @@ -21,49 +21,44 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package org.cactoos.scalar; +package org.cactoos.func; import java.io.IOException; -import org.cactoos.Scalar; -import org.cactoos.Text; -import org.cactoos.text.TextOf; +import java.io.UncheckedIOException; +import org.cactoos.BiProc; /** - * Text as {@link Integer}. + * BiProc that doesn't throw checked {@link Exception}. * *

There is no thread-safety guarantee. * - * @author Kirill (g4s8.public@gmail.com) + * @author Yegor Bugayenko (yegor256@gmail.com) * @version $Id$ - * @since 0.2 + * @param Type of input + * @param Type of input + * @since 0.22 */ -public final class IntOf implements Scalar { +public final class UncheckedBiProc implements BiProc { /** - * Source text. + * Original proc. */ - private final Text origin; + private final BiProc proc; /** * Ctor. - * - * @param string Number-string + * @param prc Encapsulated proc */ - public IntOf(final String string) { - this(new TextOf(string)); - } - - /** - * Ctor. - * - * @param text Number-text - */ - public IntOf(final Text text) { - this.origin = text; + public UncheckedBiProc(final BiProc prc) { + this.proc = prc; } @Override - public Integer value() throws IOException { - return Integer.valueOf(this.origin.asString()); + public void exec(final X first, final Y second) { + try { + new IoCheckedBiProc<>(this.proc).exec(first, second); + } catch (final IOException ex) { + throw new UncheckedIOException(ex); + } } } diff --git a/src/main/java/org/cactoos/iterable/SumOfInts.java b/src/main/java/org/cactoos/io/Directory.java similarity index 61% rename from src/main/java/org/cactoos/iterable/SumOfInts.java rename to src/main/java/org/cactoos/io/Directory.java index d9101937fa..bee0096b2f 100644 --- a/src/main/java/org/cactoos/iterable/SumOfInts.java +++ b/src/main/java/org/cactoos/io/Directory.java @@ -21,51 +21,55 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package org.cactoos.iterable; +package org.cactoos.io; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.Iterator; -import org.cactoos.Scalar; +import java.util.stream.Collectors; +import java.util.stream.Stream; /** - * Int total of numbers. + * Files in a directory. * *

There is no thread-safety guarantee. * - * @author Vseslav Sekorin (vssekorin@gmail.com) + * @author Yegor Bugayenko (yegor256@gmail.com) * @version $Id$ - * @since 0.9 + * @since 0.21 */ -public final class SumOfInts implements Scalar { +public final class Directory implements Iterable { /** - * The iterable. + * Path of the directory. */ - private final Iterable> src; + private final Path dir; /** * Ctor. - * @param src Numbers + * @param path Path of the dir */ - @SafeVarargs - public SumOfInts(final Scalar... src) { - this(new IterableOf<>(src)); + public Directory(final File path) { + this(path.toPath()); } /** * Ctor. - * @param src The iterable + * @param path Path of the dir */ - public SumOfInts(final Iterable> src) { - this.src = src; + public Directory(final Path path) { + this.dir = path; } @Override - public Long value() throws Exception { - final Iterator> numbers = this.src.iterator(); - Long result = 0L; - while (numbers.hasNext()) { - result += numbers.next().value().longValue(); + public Iterator iterator() { + try (final Stream files = Files.walk(this.dir)) { + return files.collect(Collectors.toList()).iterator(); + } catch (final IOException ex) { + throw new IllegalStateException(ex); } - return result; } + } diff --git a/src/main/java/org/cactoos/scalar/And.java b/src/main/java/org/cactoos/scalar/And.java index a0fc2549da..9cb81dbd3b 100644 --- a/src/main/java/org/cactoos/scalar/And.java +++ b/src/main/java/org/cactoos/scalar/And.java @@ -43,10 +43,17 @@ * name -> System.out.printf("The name: %s\n", name) * ).value(); * + *

This class implements {@link Scalar}, which throws a checked + * {@link Exception}. This may not be convenient in many cases. To make + * it more convenient and get rid of the checked exception you can + * use {@link UncheckedScalar} or {@link IoCheckedScalar} decorators.

+ * *

There is no thread-safety guarantee. * * @author Vseslav Sekorin (vssekorin@gmail.com) * @version $Id$ + * @see UncheckedScalar + * @see IoCheckedScalar * @since 0.8 */ public final class And implements Scalar { diff --git a/src/main/java/org/cactoos/scalar/AndWithIndex.java b/src/main/java/org/cactoos/scalar/AndWithIndex.java index 45f1b459c2..234d27954c 100644 --- a/src/main/java/org/cactoos/scalar/AndWithIndex.java +++ b/src/main/java/org/cactoos/scalar/AndWithIndex.java @@ -48,6 +48,11 @@ * ) * ).value(); * + *

This class implements {@link Scalar}, which throws a checked + * {@link Exception}. This may not be convenient in many cases. To make + * it more convenient and get rid of the checked exception you can + * use {@link UncheckedScalar} or {@link IoCheckedScalar} decorators.

+ * *

There is no thread-safety guarantee. * * @author Yegor Bugayenko (yegor256@gmail.com) diff --git a/src/main/java/org/cactoos/scalar/BoolOf.java b/src/main/java/org/cactoos/scalar/BoolOf.java index c06ff108e7..fee574cb21 100644 --- a/src/main/java/org/cactoos/scalar/BoolOf.java +++ b/src/main/java/org/cactoos/scalar/BoolOf.java @@ -33,6 +33,11 @@ * *

There is no thread-safety guarantee. * + *

This class implements {@link Scalar}, which throws a checked + * {@link Exception}. This may not be convenient in many cases. To make + * it more convenient and get rid of the checked exception you can + * use {@link UncheckedScalar} or {@link IoCheckedScalar} decorators.

+ * * @author Kirill (g4s8.public@gmail.com) * @version $Id$ * @since 0.2 @@ -47,10 +52,10 @@ public final class BoolOf implements Scalar { /** * Ctor. * - * @param string True or false string + * @param txt True or false string */ - public BoolOf(final String string) { - this(new TextOf(string)); + public BoolOf(final String txt) { + this(new TextOf(txt)); } /** diff --git a/src/main/java/org/cactoos/scalar/Equals.java b/src/main/java/org/cactoos/scalar/Equals.java index b2586bbcb8..9e3de6a95c 100644 --- a/src/main/java/org/cactoos/scalar/Equals.java +++ b/src/main/java/org/cactoos/scalar/Equals.java @@ -30,6 +30,11 @@ * *

There is no thread-safety guarantee. * + *

This class implements {@link Scalar}, which throws a checked + * {@link Exception}. This may not be convenient in many cases. To make + * it more convenient and get rid of the checked exception you can + * use {@link UncheckedScalar} or {@link IoCheckedScalar} decorators.

+ * * @author Fabricio Cabral (fabriciofx@gmail.com) * @version $Id$ * @param Type of object to compare diff --git a/src/main/java/org/cactoos/scalar/False.java b/src/main/java/org/cactoos/scalar/False.java index f18e421b63..35a381a059 100644 --- a/src/main/java/org/cactoos/scalar/False.java +++ b/src/main/java/org/cactoos/scalar/False.java @@ -37,7 +37,7 @@ public final class False implements Scalar { @Override - public Boolean value() throws Exception { + public Boolean value() { return false; } } diff --git a/src/main/java/org/cactoos/iterable/SumOfReals.java b/src/main/java/org/cactoos/scalar/Folded.java similarity index 51% rename from src/main/java/org/cactoos/iterable/SumOfReals.java rename to src/main/java/org/cactoos/scalar/Folded.java index b9bd56980e..21b18f5830 100644 --- a/src/main/java/org/cactoos/iterable/SumOfReals.java +++ b/src/main/java/org/cactoos/scalar/Folded.java @@ -21,51 +21,63 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package org.cactoos.iterable; +package org.cactoos.scalar; import java.util.Iterator; +import java.util.NoSuchElementException; +import org.cactoos.BiFunc; import org.cactoos.Scalar; /** - * Real total of numbers. + * Folds iterable via BiFunc * *

There is no thread-safety guarantee. * - * @author Vseslav Sekorin (vssekorin@gmail.com) + *

This class implements {@link Scalar}, which throws a checked + * {@link Exception}. This may not be convenient in many cases. To make + * it more convenient and get rid of the checked exception you can + * use {@link UncheckedScalar} or {@link IoCheckedScalar} decorators.

+ * + * @author Alexander Dyadyushenko (gookven@gmail.com) * @version $Id$ + * @param Scalar type * @since 0.9 */ -public final class SumOfReals implements Scalar { +public final class Folded implements Scalar { /** - * The iterable. + * Items. */ - private final Iterable> src; + private final Iterable> items; /** - * Ctor. - * @param src Numbers + * Folding function. */ - @SafeVarargs - public SumOfReals(final Scalar... src) { - this(new IterableOf<>(src)); - } + private final BiFunc fold; /** * Ctor. - * @param src The iterable + * @param fold Folding function + * @param items The items */ - public SumOfReals(final Iterable> src) { - this.src = src; + public Folded(final BiFunc fold, final Iterable> items) { + this.items = items; + this.fold = fold; } @Override - public Double value() throws Exception { - final Iterator> numbers = this.src.iterator(); - double result = 0.0d; - while (numbers.hasNext()) { - result += numbers.next().value().doubleValue(); + public T value() throws Exception { + final Iterator> iter = this.items.iterator(); + if (!iter.hasNext()) { + throw new NoSuchElementException( + "Can't find first element in an empty iterable" + ); + } + T acc = iter.next().value(); + while (iter.hasNext()) { + final T next = iter.next().value(); + acc = this.fold.apply(acc, next); } - return result; + return acc; } } diff --git a/src/main/java/org/cactoos/scalar/IoCheckedScalar.java b/src/main/java/org/cactoos/scalar/IoCheckedScalar.java index f0ddc6dffd..2f4f134320 100644 --- a/src/main/java/org/cactoos/scalar/IoCheckedScalar.java +++ b/src/main/java/org/cactoos/scalar/IoCheckedScalar.java @@ -33,6 +33,11 @@ * *

There is no thread-safety guarantee. * + *

This class implements {@link Scalar}, which throws a checked + * {@link Exception}. This may not be convenient in many cases. To make + * it more convenient and get rid of the checked exception you can + * use {@link UncheckedScalar} or {@link IoCheckedScalar} decorators.

+ * * @author Yegor Bugayenko (yegor256@gmail.com) * @version $Id$ * @param Type of result diff --git a/src/main/java/org/cactoos/scalar/Max.java b/src/main/java/org/cactoos/scalar/Max.java index 0962c8a305..1785b42977 100644 --- a/src/main/java/org/cactoos/scalar/Max.java +++ b/src/main/java/org/cactoos/scalar/Max.java @@ -23,19 +23,25 @@ */ package org.cactoos.scalar; -import java.util.Iterator; -import java.util.NoSuchElementException; import org.cactoos.Scalar; +import org.cactoos.func.MaxFunc; import org.cactoos.iterable.IterableOf; /** * Find the greater among items. * + *

This class implements {@link Scalar}, which throws a checked + * {@link Exception}. This may not be convenient in many cases. To make + * it more convenient and get rid of the checked exception you can + * use {@link UncheckedScalar} or {@link IoCheckedScalar} decorators.

+ * *

There is no thread-safety guarantee. * * @author Fabricio Cabral (fabriciofx@gmail.com) * @version $Id$ * @param Scalar type + * @see UncheckedScalar + * @see IoCheckedScalar * @since 0.10 */ public final class Max> implements Scalar { @@ -43,7 +49,7 @@ public final class Max> implements Scalar { /** * Items. */ - private final Iterable> items; + private final Scalar result; /** * Ctor. @@ -59,25 +65,15 @@ public Max(final Scalar... scalars) { * @param iterable The items */ public Max(final Iterable> iterable) { - this.items = iterable; + this.result = new Folded<>( + new MaxFunc<>(), + iterable + ); } @Override public T value() throws Exception { - final Iterator> iter = this.items.iterator(); - if (!iter.hasNext()) { - throw new NoSuchElementException( - "Can't find greater element in an empty iterable" - ); - } - T max = iter.next().value(); - while (iter.hasNext()) { - final T next = iter.next().value(); - if (next.compareTo(max) > 0) { - max = next; - } - } - return max; + return this.result.value(); } } diff --git a/src/main/java/org/cactoos/scalar/Min.java b/src/main/java/org/cactoos/scalar/Min.java index ce845dcd0e..1b5a672639 100644 --- a/src/main/java/org/cactoos/scalar/Min.java +++ b/src/main/java/org/cactoos/scalar/Min.java @@ -23,9 +23,8 @@ */ package org.cactoos.scalar; -import java.util.Iterator; -import java.util.NoSuchElementException; import org.cactoos.Scalar; +import org.cactoos.func.MinFunc; import org.cactoos.iterable.IterableOf; /** @@ -33,6 +32,11 @@ * *

There is no thread-safety guarantee. * + *

This class implements {@link Scalar}, which throws a checked + * {@link Exception}. This may not be convenient in many cases. To make + * it more convenient and get rid of the checked exception you can + * use {@link UncheckedScalar} or {@link IoCheckedScalar} decorators.

+ * * @author Fabricio Cabral (fabriciofx@gmail.com) * @version $Id$ * @param Scalar type @@ -43,7 +47,7 @@ public final class Min> implements Scalar { /** * Items. */ - private final Iterable> items; + private final Scalar result; /** * Ctor. @@ -59,25 +63,15 @@ public Min(final Scalar... scalars) { * @param iterable The items */ public Min(final Iterable> iterable) { - this.items = iterable; + this.result = new Folded<>( + new MinFunc<>(), + iterable + ); } @Override public T value() throws Exception { - final Iterator> iter = this.items.iterator(); - if (!iter.hasNext()) { - throw new NoSuchElementException( - "Can't find smaller element in an empty iterable" - ); - } - T min = iter.next().value(); - while (iter.hasNext()) { - final T next = iter.next().value(); - if (next.compareTo(min) < 0) { - min = next; - } - } - return min; + return this.result.value(); } } diff --git a/src/main/java/org/cactoos/scalar/Not.java b/src/main/java/org/cactoos/scalar/Not.java index 5f66433c68..f2825b7f08 100644 --- a/src/main/java/org/cactoos/scalar/Not.java +++ b/src/main/java/org/cactoos/scalar/Not.java @@ -30,6 +30,11 @@ * *

There is no thread-safety guarantee. * + *

This class implements {@link Scalar}, which throws a checked + * {@link Exception}. This may not be convenient in many cases. To make + * it more convenient and get rid of the checked exception you can + * use {@link UncheckedScalar} or {@link IoCheckedScalar} decorators.

+ * * @author Vseslav Sekorin (vssekorin@gmail.com) * @version $Id$ * @since 0.7 diff --git a/src/main/java/org/cactoos/scalar/NumberOf.java b/src/main/java/org/cactoos/scalar/NumberOf.java new file mode 100644 index 0000000000..18866b0597 --- /dev/null +++ b/src/main/java/org/cactoos/scalar/NumberOf.java @@ -0,0 +1,133 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2017 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.scalar; + +import org.cactoos.Scalar; +import org.cactoos.Text; +import org.cactoos.text.TextOf; + +/** + * Text as {@link Float}. + * + *

There is no thread-safety guarantee. + * + *

This class implements {@link Scalar}, which throws a checked + * {@link Exception}. This may not be convenient in many cases. To make + * it more convenient and get rid of the checked exception you can + * use {@link UncheckedScalar} or {@link IoCheckedScalar} decorators.

+ * + * @author Kirill (g4s8.public@gmail.com) + * @version $Id$ + * @since 0.2 + */ +public final class NumberOf extends Number implements Scalar { + + /** + * Serialization marker. + */ + private static final long serialVersionUID = -1924406337256921883L; + + /** + * The LONG number. + */ + private final Scalar lnum; + + /** + * The INT number. + */ + private final Scalar inum; + + /** + * The FLOAT number. + */ + private final Scalar fnum; + + /** + * The DOUBLE number. + */ + private final Scalar dnum; + + /** + * Ctor. + * + * @param txt Number-string + */ + public NumberOf(final String txt) { + this(new TextOf(txt)); + } + + /** + * Ctor. + * + * @param text Number-text + */ + public NumberOf(final Text text) { + super(); + this.lnum = new SyncScalar<>( + new StickyScalar<>( + () -> Long.parseLong(text.asString()) + ) + ); + this.inum = new SyncScalar<>( + new StickyScalar<>( + () -> Integer.parseInt(text.asString()) + ) + ); + this.fnum = new SyncScalar<>( + new StickyScalar<>( + () -> Float.parseFloat(text.asString()) + ) + ); + this.dnum = new SyncScalar<>( + new StickyScalar<>( + () -> Double.parseDouble(text.asString()) + ) + ); + } + + @Override + public Number value() { + return this; + } + + @Override + public int intValue() { + return new UncheckedScalar<>(this.inum).value(); + } + + @Override + public long longValue() { + return new UncheckedScalar<>(this.lnum).value(); + } + + @Override + public float floatValue() { + return new UncheckedScalar<>(this.fnum).value(); + } + + @Override + public double doubleValue() { + return new UncheckedScalar<>(this.dnum).value(); + } +} diff --git a/src/main/java/org/cactoos/scalar/Or.java b/src/main/java/org/cactoos/scalar/Or.java index 98fbe14663..66bc2b0aad 100644 --- a/src/main/java/org/cactoos/scalar/Or.java +++ b/src/main/java/org/cactoos/scalar/Or.java @@ -35,6 +35,11 @@ * *

There is no thread-safety guarantee. * + *

This class implements {@link Scalar}, which throws a checked + * {@link Exception}. This may not be convenient in many cases. To make + * it more convenient and get rid of the checked exception you can + * use {@link UncheckedScalar} or {@link IoCheckedScalar} decorators.

+ * * @author Vseslav Sekorin (vssekorin@gmail.com) * @version $Id$ * @since 0.8 diff --git a/src/main/java/org/cactoos/scalar/RetryScalar.java b/src/main/java/org/cactoos/scalar/RetryScalar.java index 9e78a02aa1..ae9fba7a7a 100644 --- a/src/main/java/org/cactoos/scalar/RetryScalar.java +++ b/src/main/java/org/cactoos/scalar/RetryScalar.java @@ -32,6 +32,11 @@ * *

There is no thread-safety guarantee. * + *

This class implements {@link Scalar}, which throws a checked + * {@link Exception}. This may not be convenient in many cases. To make + * it more convenient and get rid of the checked exception you can + * use {@link UncheckedScalar} or {@link IoCheckedScalar} decorators.

+ * * @author Yegor Bugayenko (yegor256@gmail.com) * @version $Id$ * @param Type of output diff --git a/src/main/java/org/cactoos/scalar/StickyScalar.java b/src/main/java/org/cactoos/scalar/StickyScalar.java index a9a791ef5b..708ff3ce73 100644 --- a/src/main/java/org/cactoos/scalar/StickyScalar.java +++ b/src/main/java/org/cactoos/scalar/StickyScalar.java @@ -35,7 +35,12 @@ * *

Pay attention that this class is not thread-safe. It is highly * recommended to always decorate it with {@link SyncScalar}.

- + * + *

This class implements {@link Scalar}, which throws a checked + * {@link Exception}. This may not be convenient in many cases. To make + * it more convenient and get rid of the checked exception you can + * use {@link UncheckedScalar} or {@link IoCheckedScalar} decorators.

+ * *

There is no thread-safety guarantee. * * @author Tim Hinkes (timmeey@timmeey.de) diff --git a/src/main/java/org/cactoos/scalar/SumOf.java b/src/main/java/org/cactoos/scalar/SumOf.java new file mode 100644 index 0000000000..d25e24c433 --- /dev/null +++ b/src/main/java/org/cactoos/scalar/SumOf.java @@ -0,0 +1,208 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2017 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.scalar; + +import java.util.Iterator; +import java.util.stream.Collectors; +import java.util.stream.DoubleStream; +import java.util.stream.IntStream; +import java.util.stream.LongStream; +import org.cactoos.Scalar; +import org.cactoos.iterable.IterableOf; +import org.cactoos.iterable.Mapped; + +/** + * Int total of numbers. + * + *

This class implements {@link Scalar}, which throws a checked + * {@link Exception}. This may not be convenient in many cases. To make + * it more convenient and get rid of the checked exception you can + * use {@link UncheckedScalar} or {@link IoCheckedScalar} decorators.

+ * + *

There is no thread-safety guarantee. + * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @author Vseslav Sekorin (vssekorin@gmail.com) + * @version $Id$ + * @since 0.9 + */ +public final class SumOf extends Number implements Scalar { + + /** + * Serialization marker. + */ + private static final long serialVersionUID = -1924406337256921883L; + + /** + * The LONG sum. + */ + private final Scalar lsum; + + /** + * The INT sum. + */ + private final Scalar isum; + + /** + * The FLOAT sum. + */ + private final Scalar fsum; + + /** + * The DOUBLE sum. + */ + private final Scalar dsum; + + /** + * Ctor. + * @param src Numbers + * @since 0.22 + */ + public SumOf(final int... src) { + this(new Mapped<>( + input -> () -> input, + IntStream.of(src).boxed().collect(Collectors.toList()) + )); + } + + /** + * Ctor. + * @param src Numbers + * @since 0.22 + */ + public SumOf(final long... src) { + this(new Mapped<>( + input -> () -> input, + LongStream.of(src).boxed().collect(Collectors.toList()) + )); + } + + /** + * Ctor. + * @param src Numbers + * @since 0.22 + */ + public SumOf(final double... src) { + this(new Mapped<>( + input -> () -> input, + DoubleStream.of(src).boxed().collect(Collectors.toList()) + )); + } + + /** + * Ctor. + * @param src Numbers + */ + @SafeVarargs + public SumOf(final Scalar... src) { + this(new IterableOf<>(src)); + } + + /** + * Ctor. + * @param src The iterable + * @checkstyle ExecutableStatementCountCheck (150 lines) + */ + public SumOf(final Iterable> src) { + super(); + this.lsum = new SyncScalar<>( + new StickyScalar<>( + () -> { + final Iterator> numbers = src.iterator(); + long sum = 0L; + while (numbers.hasNext()) { + final Number next = numbers.next().value(); + sum += next.longValue(); + } + return sum; + } + ) + ); + this.isum = new SyncScalar<>( + new StickyScalar<>( + () -> { + final Iterator> numbers = src.iterator(); + int sum = 0; + while (numbers.hasNext()) { + final Number next = numbers.next().value(); + sum += next.intValue(); + } + return sum; + } + ) + ); + this.fsum = new SyncScalar<>( + new StickyScalar<>( + () -> { + final Iterator> numbers = src.iterator(); + float sum = 0.0f; + while (numbers.hasNext()) { + final Number next = numbers.next().value(); + sum += next.floatValue(); + } + return sum; + } + ) + ); + this.dsum = new SyncScalar<>( + new StickyScalar<>( + () -> { + final Iterator> numbers = src.iterator(); + double sum = 0.0d; + while (numbers.hasNext()) { + final Number next = numbers.next().value(); + sum += next.doubleValue(); + } + return sum; + } + ) + ); + } + + @Override + public int intValue() { + return new UncheckedScalar<>(this.isum).value(); + } + + @Override + public long longValue() { + return new UncheckedScalar<>(this.lsum).value(); + } + + @Override + public float floatValue() { + return new UncheckedScalar<>(this.fsum).value(); + } + + @Override + public double doubleValue() { + return new UncheckedScalar<>(this.dsum).value(); + } + + @Override + public Number value() { + return this; + } + +} diff --git a/src/main/java/org/cactoos/scalar/SyncScalar.java b/src/main/java/org/cactoos/scalar/SyncScalar.java index dc06e7f4a0..dbd7492541 100644 --- a/src/main/java/org/cactoos/scalar/SyncScalar.java +++ b/src/main/java/org/cactoos/scalar/SyncScalar.java @@ -28,6 +28,11 @@ /** * Scalar that is thread-safe. * + *

This class implements {@link Scalar}, which throws a checked + * {@link Exception}. This may not be convenient in many cases. To make + * it more convenient and get rid of the checked exception you can + * use {@link UncheckedScalar} or {@link IoCheckedScalar} decorators.

+ * * @author Tim Hinkes (timmeey@timmeey.de) * @version $Id$ * @param Type of result diff --git a/src/main/java/org/cactoos/scalar/Ternary.java b/src/main/java/org/cactoos/scalar/Ternary.java index b8cd460026..933df1e291 100644 --- a/src/main/java/org/cactoos/scalar/Ternary.java +++ b/src/main/java/org/cactoos/scalar/Ternary.java @@ -31,6 +31,11 @@ * *

There is no thread-safety guarantee. * + *

This class implements {@link Scalar}, which throws a checked + * {@link Exception}. This may not be convenient in many cases. To make + * it more convenient and get rid of the checked exception you can + * use {@link UncheckedScalar} or {@link IoCheckedScalar} decorators.

+ * * @author Vseslav Sekorin (vssekorin@gmail.com) * @version $Id$ * @param Type of item. diff --git a/src/main/java/org/cactoos/scalar/True.java b/src/main/java/org/cactoos/scalar/True.java index a36fd50a5c..7c514a225b 100644 --- a/src/main/java/org/cactoos/scalar/True.java +++ b/src/main/java/org/cactoos/scalar/True.java @@ -37,7 +37,7 @@ public final class True implements Scalar { @Override - public Boolean value() throws Exception { + public Boolean value() { return true; } } diff --git a/src/main/java/org/cactoos/scalar/DoubleOf.java b/src/main/java/org/cactoos/text/Base64Text.java similarity index 63% rename from src/main/java/org/cactoos/scalar/DoubleOf.java rename to src/main/java/org/cactoos/text/Base64Text.java index 9171d48141..7d1bf0b9cb 100644 --- a/src/main/java/org/cactoos/scalar/DoubleOf.java +++ b/src/main/java/org/cactoos/text/Base64Text.java @@ -21,49 +21,57 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package org.cactoos.scalar; + +package org.cactoos.text; import java.io.IOException; -import org.cactoos.Scalar; import org.cactoos.Text; -import org.cactoos.text.TextOf; +import org.cactoos.bytes.Base64Bytes; +import org.cactoos.io.BytesOf; /** - * Text as {@link Double}. - * - *

There is no thread-safety guarantee. + * Decodes the origin text using the Base64 encoding scheme. * - * @author Kirill (g4s8.public@gmail.com) + * @author Ilia Rogozhin (ilia.rogozhin@gmail.com) * @version $Id$ - * @since 0.2 + * @since 0.20.2 */ -public final class DoubleOf implements Scalar { +public final class Base64Text implements Text { /** - * Source text. + * Origin text. */ private final Text origin; /** * Ctor. * - * @param string Number-string + * @param input The String */ - public DoubleOf(final String string) { - this(new TextOf(string)); + public Base64Text(final String input) { + this(new TextOf(input)); } /** * Ctor. * - * @param text Number-text + * @param origin Origin text */ - public DoubleOf(final Text text) { - this.origin = text; + public Base64Text(final Text origin) { + this.origin = origin; + } + + @Override + public String asString() throws IOException { + return new TextOf( + new Base64Bytes( + new BytesOf(this.origin) + ) + ).asString(); } @Override - public Double value() throws IOException { - return Double.valueOf(this.origin.asString()); + public int compareTo(final Text text) { + return new UncheckedText(this).compareTo(text); } } diff --git a/src/main/java/org/cactoos/text/TextBase64.java b/src/main/java/org/cactoos/text/TextBase64.java new file mode 100644 index 0000000000..b153c37b6e --- /dev/null +++ b/src/main/java/org/cactoos/text/TextBase64.java @@ -0,0 +1,77 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2017 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 java.io.IOException; +import org.cactoos.Text; +import org.cactoos.bytes.BytesBase64; +import org.cactoos.io.BytesOf; + +/** + * Encodes the origin text using the Base64 encoding scheme. + * + * @author Ilia Rogozhin (ilia.rogozhin@gmail.com) + * @version $Id$ + * @since 0.20.2 + */ +public final class TextBase64 implements Text { + + /** + * Origin text. + */ + private final Text origin; + + /** + * Ctor. + * + * @param input The String + */ + public TextBase64(final String input) { + this(new TextOf(input)); + } + + /** + * Ctor. + * + * @param origin Origin text + */ + public TextBase64(final Text origin) { + this.origin = origin; + } + + @Override + public String asString() throws IOException { + return new TextOf( + new BytesBase64( + new BytesOf(this.origin) + ) + ).asString(); + } + + @Override + public int compareTo(final Text text) { + return new UncheckedText(this).compareTo(text); + } +} diff --git a/src/main/java/org/cactoos/text/TextOf.java b/src/main/java/org/cactoos/text/TextOf.java index db236ace42..6113716c2f 100644 --- a/src/main/java/org/cactoos/text/TextOf.java +++ b/src/main/java/org/cactoos/text/TextOf.java @@ -37,6 +37,7 @@ import org.cactoos.Text; import org.cactoos.io.BytesOf; import org.cactoos.io.InputOf; +import org.cactoos.iterable.Mapped; import org.cactoos.scalar.IoCheckedScalar; /** @@ -273,6 +274,23 @@ public TextOf(final String input, final Charset cset) { this(() -> new String(input.getBytes(cset), cset)); } + /** + * Ctor. + * @param iterable The iterable to convert to string + * @since 0.21 + */ + public TextOf(final Iterable iterable) { + this( + () -> new JoinedText( + ", ", + new Mapped<>( + Object::toString, + iterable + ) + ).asString() + ); + } + /** * Ctor. * diff --git a/src/test/java/org/cactoos/scalar/DoubleOfTest.java b/src/test/java/org/cactoos/bytes/Base64BytesTest.java similarity index 66% rename from src/test/java/org/cactoos/scalar/DoubleOfTest.java rename to src/test/java/org/cactoos/bytes/Base64BytesTest.java index 74351fa5e1..fd4664ba75 100644 --- a/src/test/java/org/cactoos/scalar/DoubleOfTest.java +++ b/src/test/java/org/cactoos/bytes/Base64BytesTest.java @@ -21,35 +21,41 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package org.cactoos.scalar; + +package org.cactoos.bytes; import java.io.IOException; +import org.cactoos.io.BytesOf; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Test; /** - * Test case for {@link DoubleOf}. + * Test case for {@link org.cactoos.bytes.Base64Bytes}. * - * @author Kirill (g4s8.public@gmail.com) + * @author Ilia Rogozhin (ilia.rogozhin@gmail.com) * @version $Id$ - * @since 0.2 - * @checkstyle JavadocMethodCheck (500 lines) + * @since 0.20.2 */ -public final class DoubleOfTest { +public final class Base64BytesTest { + /** + * Check bytes decodes using the Base64 encoding scheme. + * @throws IOException If fails. + */ @Test - public strictfp void numberTest() throws IOException { + public void checkDecode() throws IOException { MatcherAssert.assertThat( - "Can't parse double number", - new DoubleOf("185.65156465123").value(), - // @checkstyle MagicNumber (1 line) - Matchers.equalTo(185.65156465123) + "Can't decodes bytes using the Base64 encoding scheme", + new Base64Bytes( + new BytesOf( + "SGVsbG8h" + ) + ).asBytes(), + Matchers.equalTo( + new BytesOf("Hello!").asBytes() + ) ); } - @Test(expected = NumberFormatException.class) - public void failsIfTextDoesNotRepresentADouble() throws IOException { - new DoubleOf("abc").value(); - } } diff --git a/src/test/java/org/cactoos/bytes/BytesBase64Test.java b/src/test/java/org/cactoos/bytes/BytesBase64Test.java new file mode 100644 index 0000000000..97aee47bfc --- /dev/null +++ b/src/test/java/org/cactoos/bytes/BytesBase64Test.java @@ -0,0 +1,60 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2017 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.bytes; + +import java.io.IOException; +import org.cactoos.io.BytesOf; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.Test; + +/** + * Test case for {@link org.cactoos.bytes.BytesBase64}. + * @author Ilia Rogozhin (ilia.rogozhin@gmail.com) + * @version $Id$ + * @since 0.20.2 + */ +public final class BytesBase64Test { + + /** + * Check bytes encodes using the Base64 encoding scheme. + * @throws IOException If fails. + */ + @Test + public void checkEncode() throws IOException { + MatcherAssert.assertThat( + "Can't encodes bytes using the Base64 encoding scheme", + new BytesBase64( + new BytesOf( + "Hello!" + ) + ).asBytes(), + Matchers.equalTo( + new BytesOf("SGVsbG8h").asBytes() + ) + ); + } + +} diff --git a/src/test/java/org/cactoos/bytes/package-info.java b/src/test/java/org/cactoos/bytes/package-info.java new file mode 100644 index 0000000000..45db840f10 --- /dev/null +++ b/src/test/java/org/cactoos/bytes/package-info.java @@ -0,0 +1,32 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2017 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. + */ + +/** + * Bytes, tests. + * + * @author Ilia Rogozhin (ilia.rogozhin@gmail.com) + * @version $Id$ + * @since 0.20.2 + */ +package org.cactoos.bytes; diff --git a/src/test/java/org/cactoos/scalar/LongOfTest.java b/src/test/java/org/cactoos/io/DirectoryTest.java similarity index 70% rename from src/test/java/org/cactoos/scalar/LongOfTest.java rename to src/test/java/org/cactoos/io/DirectoryTest.java index a6b2497fb8..14929bec9a 100644 --- a/src/test/java/org/cactoos/scalar/LongOfTest.java +++ b/src/test/java/org/cactoos/io/DirectoryTest.java @@ -21,35 +21,36 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package org.cactoos.scalar; +package org.cactoos.io; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Test; /** - * Test case for {@link LongOf}. - * - * @author Kirill (g4s8.public@gmail.com) + * Test case for {@link Directory}. + * @author Yegor Bugayenko (yegor256@gmail.com) * @version $Id$ - * @since 0.2 + * @since 0.12 * @checkstyle JavadocMethodCheck (500 lines) + * @checkstyle ClassDataAbstractionCouplingCheck (500 lines) */ -public final class LongOfTest { +public final class DirectoryTest { @Test - public void numberTest() throws IOException { + public void listsFilesInDirectory() throws IOException { + final Path dir = Files.createTempDirectory("x1"); + dir.resolve("x/y").toFile().mkdirs(); + Files.write(dir.resolve("x/y/test"), "".getBytes()); MatcherAssert.assertThat( - "Can't parse long number", - new LongOf("186789235425346").value(), + "Can't list files in a directory", + new Directory(dir), // @checkstyle MagicNumber (1 line) - Matchers.equalTo(186789235425346L) + Matchers.iterableWithSize(4) ); } - @Test(expected = NumberFormatException.class) - public void failsIfTextDoesNotRepresentALong() throws IOException { - new LongOf("abc").value(); - } } diff --git a/src/test/java/org/cactoos/iterable/IterableOfTest.java b/src/test/java/org/cactoos/iterable/IterableOfTest.java index a6af97356b..5e67203019 100644 --- a/src/test/java/org/cactoos/iterable/IterableOfTest.java +++ b/src/test/java/org/cactoos/iterable/IterableOfTest.java @@ -26,6 +26,7 @@ import org.cactoos.ScalarHasValue; import org.cactoos.text.TextOf; import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; import org.junit.Test; /** @@ -52,6 +53,15 @@ public void convertsScalarsToIterable() { ); } + @Test + public void convertsArrayOfIntsToIterable() { + MatcherAssert.assertThat( + "Can't convert int scalars to iterable", + new IterableOf<>(1, 2, 0, 2), + Matchers.hasItem(0) + ); + } + @Test public void convertsObjectsToIterable() { MatcherAssert.assertThat( diff --git a/src/test/java/org/cactoos/iterable/SumOfRealsTest.java b/src/test/java/org/cactoos/iterable/SumOfRealsTest.java deleted file mode 100644 index 03b97f58df..0000000000 --- a/src/test/java/org/cactoos/iterable/SumOfRealsTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * The MIT License (MIT) - * - * Copyright (c) 2017 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.iterable; - -import org.cactoos.Scalar; -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; -import org.junit.Test; - -/** - * Test case for {@link SumOfReals}. - * - * @author Vseslav Sekorin (vssekorin@gmail.com) - * @version $Id$ - * @since 0.9 - * @checkstyle JavadocMethodCheck (500 lines) - * @checkstyle MagicNumberCheck (500 lines) - */ -public final class SumOfRealsTest { - - @Test - public void withVarargsCtor() throws Exception { - MatcherAssert.assertThat( - new SumOfReals( - () -> 1.2, - () -> 2.5, - () -> 3.3 - ).value(), - Matchers.closeTo(7.0, 0.0) - ); - } - - @Test - public void withIterCtor() throws Exception { - MatcherAssert.assertThat( - new SumOfReals( - new IterableOf>( - () -> 7.1, - () -> 8.1, - () -> 10.1 - ) - ).value(), - Matchers.closeTo(25.0, 0.3) - ); - } -} diff --git a/src/test/java/org/cactoos/scalar/NumberOfTest.java b/src/test/java/org/cactoos/scalar/NumberOfTest.java new file mode 100644 index 0000000000..e7dc8cb5f9 --- /dev/null +++ b/src/test/java/org/cactoos/scalar/NumberOfTest.java @@ -0,0 +1,100 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2017 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.scalar; + +import java.io.IOException; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.Test; + +/** + * Test case for {@link NumberOf}. + * + * @author Kirill (g4s8.public@gmail.com) + * @version $Id$ + * @since 0.2 + * @checkstyle JavadocMethodCheck (500 lines) + */ +public final class NumberOfTest { + + @Test + public void parsesFloat() throws IOException { + MatcherAssert.assertThat( + "Can't parse float number", + new NumberOf("1656.894").floatValue(), + // @checkstyle MagicNumber (1 line) + Matchers.equalTo(1656.894F) + ); + } + + @Test(expected = RuntimeException.class) + public void failsIfTextDoesNotRepresentAFloat() throws IOException { + new NumberOf("abcfds").floatValue(); + } + + @Test + public void parsesLong() throws IOException { + MatcherAssert.assertThat( + "Can't parse long number", + new NumberOf("186789235425346").longValue(), + // @checkstyle MagicNumber (1 line) + Matchers.equalTo(186789235425346L) + ); + } + + @Test(expected = RuntimeException.class) + public void failsIfTextDoesNotRepresentALong() throws IOException { + new NumberOf("abcddd").longValue(); + } + + @Test + public void parsesInteger() throws IOException { + MatcherAssert.assertThat( + "Can't parse integer number", + new NumberOf("1867892354").intValue(), + // @checkstyle MagicNumber (1 line) + Matchers.equalTo(1867892354) + ); + } + + @Test(expected = RuntimeException.class) + public void failsIfTextDoesNotRepresentAnInt() throws IOException { + new NumberOf("abc fdsf").intValue(); + } + + @Test + public void parsesDouble() throws IOException { + MatcherAssert.assertThat( + "Can't parse double number", + new NumberOf("185.65156465123").doubleValue(), + // @checkstyle MagicNumber (1 line) + Matchers.equalTo(185.65156465123) + ); + } + + @Test(expected = RuntimeException.class) + public void failsIfTextDoesNotRepresentADouble() throws IOException { + new NumberOf("abfdsc").doubleValue(); + } +} diff --git a/src/test/java/org/cactoos/iterable/SumOfIntsTest.java b/src/test/java/org/cactoos/scalar/SumOfTest.java similarity index 70% rename from src/test/java/org/cactoos/iterable/SumOfIntsTest.java rename to src/test/java/org/cactoos/scalar/SumOfTest.java index 8fcaa05f3a..24245b3b7a 100644 --- a/src/test/java/org/cactoos/iterable/SumOfIntsTest.java +++ b/src/test/java/org/cactoos/scalar/SumOfTest.java @@ -21,15 +21,16 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package org.cactoos.iterable; +package org.cactoos.scalar; import org.cactoos.Scalar; +import org.cactoos.iterable.IterableOf; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Test; /** - * Test case for {@link SumOfInts}. + * Test case for {@link SumOf}. * * @author Vseslav Sekorin (vssekorin@gmail.com) * @version $Id$ @@ -37,16 +38,36 @@ * @checkstyle JavadocMethodCheck (500 lines) * @checkstyle MagicNumberCheck (500 lines) */ -public final class SumOfIntsTest { +public final class SumOfTest { + + @Test + public void withListOfNumbers() throws Exception { + MatcherAssert.assertThat( + new SumOf(1, 2, 3).intValue(), + Matchers.equalTo(6) + ); + MatcherAssert.assertThat( + new SumOf(1.0d, 2.0d, 3.0d).doubleValue(), + Matchers.equalTo(6.0d) + ); + MatcherAssert.assertThat( + new SumOf(1.0f, 2.0f, 3.0f).floatValue(), + Matchers.equalTo(6.0f) + ); + MatcherAssert.assertThat( + new SumOf(1L, 2L, 3L).longValue(), + Matchers.equalTo(6L) + ); + } @Test public void withVarargsCtor() throws Exception { MatcherAssert.assertThat( - new SumOfInts( + new SumOf( () -> 1, () -> 2, () -> 3 - ).value(), + ).longValue(), Matchers.equalTo(6L) ); } @@ -54,13 +75,13 @@ public void withVarargsCtor() throws Exception { @Test public void withIterCtor() throws Exception { MatcherAssert.assertThat( - new SumOfInts( + new SumOf( new IterableOf>( () -> 7, () -> 8, () -> 10 ) - ).value(), + ).longValue(), Matchers.equalTo(25L) ); } diff --git a/src/test/java/org/cactoos/scalar/IntOfTest.java b/src/test/java/org/cactoos/text/Base64TextTest.java similarity index 68% rename from src/test/java/org/cactoos/scalar/IntOfTest.java rename to src/test/java/org/cactoos/text/Base64TextTest.java index ebda11991a..4c28be33b8 100644 --- a/src/test/java/org/cactoos/scalar/IntOfTest.java +++ b/src/test/java/org/cactoos/text/Base64TextTest.java @@ -21,35 +21,37 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package org.cactoos.scalar; + +package org.cactoos.text; import java.io.IOException; +import org.cactoos.TextHasString; import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; import org.junit.Test; /** - * Test case for {@link IntOf}. + * Test Case for {@link org.cactoos.text.Base64Text}. * - * @author Kirill (g4s8.public@gmail.com) + * @author Ilia Rogozhin (ilia.rogozhin@gmail.com) * @version $Id$ - * @since 0.2 - * @checkstyle JavadocMethodCheck (500 lines) + * @since 0.20.2 */ -public final class IntOfTest { +public final class Base64TextTest { + /** + * Check text decodes using the Base64 encoding scheme. + * @throws IOException If fails. + */ @Test - public void numberTest() throws IOException { + public void checkDecode() throws IOException { MatcherAssert.assertThat( - "Can't parse integer number", - new IntOf("1867892354").value(), - // @checkstyle MagicNumber (1 line) - Matchers.equalTo(1867892354) + "Can't decodes text using the Base64 encoding scheme", + new Base64Text( + "SGVsbG8h" + ), + new TextHasString( + "Hello!" + ) ); } - - @Test(expected = NumberFormatException.class) - public void failsIfTextDoesNotRepresentAnInt() throws IOException { - new DoubleOf("abc").value(); - } } diff --git a/src/test/java/org/cactoos/scalar/FloatOfTest.java b/src/test/java/org/cactoos/text/TextBase64Test.java similarity index 67% rename from src/test/java/org/cactoos/scalar/FloatOfTest.java rename to src/test/java/org/cactoos/text/TextBase64Test.java index a3f381bfe7..0449728534 100644 --- a/src/test/java/org/cactoos/scalar/FloatOfTest.java +++ b/src/test/java/org/cactoos/text/TextBase64Test.java @@ -21,35 +21,36 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package org.cactoos.scalar; + +package org.cactoos.text; import java.io.IOException; +import org.cactoos.TextHasString; import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; import org.junit.Test; /** - * Test case for {@link FloatOf}. - * - * @author Kirill (g4s8.public@gmail.com) + * Test case for {@link org.cactoos.text.TextBase64}. + * @author Ilia Rogozhin (ilia.rogozhin@gmail.com) * @version $Id$ - * @since 0.2 - * @checkstyle JavadocMethodCheck (500 lines) + * @since 0.20.2 */ -public final class FloatOfTest { +public final class TextBase64Test { + /** + * Check text encodes using the Base64 encoding scheme. + * @throws IOException If fails. + */ @Test - public strictfp void numberTest() throws IOException { + public void checkEncode() throws IOException { MatcherAssert.assertThat( - "Can't parse float number", - new FloatOf("1656.894").value(), - // @checkstyle MagicNumber (1 line) - Matchers.equalTo(1656.894F) + "Can't encodes text using the Base64 encoding scheme", + new TextBase64( + "Hello!" + ), + new TextHasString( + "SGVsbG8h" + ) ); } - - @Test(expected = NumberFormatException.class) - public void failsIfTextDoesNotRepresentAFloat() throws IOException { - new FloatOf("abc").value(); - } }