diff --git a/.travis.yml b/.travis.yml index 297e4b6cdb..9b13c0f7e5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,8 +5,8 @@ cache: - $HOME/.m2 script: - set -e - - mvn clean install -Pqulice --errors --batch-mode - mvn clean site -Psite --errors --batch-mode + - mvn clean install -Pqulice --errors --batch-mode env: global: - MAVEN_OPTS="-Xmx256m" diff --git a/README.md b/README.md index 0641777c16..6ae102ed2f 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ [![DevOps By Rultor.com](http://www.rultor.com/b/yegor256/cactoos)](http://www.rultor.com/p/yegor256/cactoos) [![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) [![PDD status](http://www.0pdd.com/svg?name=yegor256/cactoos)](http://www.0pdd.com/p?name=yegor256/cactoos) [![Test Coverage](https://img.shields.io/codecov/c/github/yegor256/cactoos.svg)](https://codecov.io/github/yegor256/cactoos?branch=master) @@ -52,7 +53,10 @@ Java version required: 1.8+. ## Input/Output -To read a file: +More about it here: +[Object-Oriented Declarative Input/Output in Cactoos](http://www.yegor256.com/2017/06/22/object-oriented-input-output-in-cactoos.html). + +To read a text file in UTF-8: ```java String text = new BytesAsText( @@ -69,8 +73,10 @@ To write a text into a file: ```java new LengthOfInput( new TeeInput( - new TextAsInput( - new StringAsText("Hello, world!") + new BytesAsInput( + new TextAsBytes( + new StringAsText("Hello, world!") + ) ), new FileAsOutput( new File("/code/a.txt") @@ -83,9 +89,7 @@ To read a binary file from classpath: ```java byte[] data = new InputAsBytes( - new UrlAsInput( - this.getClass().getResource("/foo/img.jpg") - ) + new ResourceAsInput("foo/img.jpg") ).asBytes(); ``` @@ -141,15 +145,14 @@ new IterableAsCollection<>( To iterate a collection: ```java -new AllOf( - new TransformedIterable<>( +new And( + new MappedIterable<>( new ArrayAsIterable<>("how", "are", "you"), - new Func.Quiet() { - @Override - public void exec(final String input) throws Exception { + new ProcAsFunc<>( + input -> { System.out.printf("Item: %s\n", input); } - } + ) ) ).asValue(); ``` @@ -157,9 +160,9 @@ new AllOf( Or even more compact: ```java -new IterableAsBoolean( - new ArrayAsIterable<>("how", "are", "you"), - (Func.Quiet) i -> System.out.printf("Item: %s\n", i) +new And( + input -> System.out.printf("Item: %s\n", i), + "how", "are", "you" ).asValue(); ``` @@ -168,10 +171,12 @@ To sort a list of words in the file: ```java List sorted = new SortedList<>( new IterableAsList<>( - new TextAsLines( - new InputAsText( - new FileAsInput( - new File("/tmp/names.txt") + new SplitText( + new BytesAsText( + new InputAsBytes( + new FileAsInput( + new File("/tmp/names.txt") + ) ) ) ) @@ -183,7 +188,48 @@ To count elements in an iterable: ```java int total = new LengthOfIterable( - new ArrayAsIterable<>("how", "are", "you") + "how", "are", "you" +).asValue(); +``` + +## Funcs and Procs + +This is a traditional `foreach` loop: + +```java +for (String name : names) { + System.out.printf("Hello, %s!\n", name); +} +``` + +This is its object-oriented alternative (no streams!): + +```java +new And<>( + names, + n -> { + System.out.printf("Hello, %s!\n", n); + } +).asValue(); +``` + +This is an endless `while/do` loop: + +```java +while (!ready) { + System.out.prinln("Still waiting..."); +} +``` + +Here is its object-oriented alternative: + +```java +new And<>( + new EndlessIterable<>(ready), + r -> { + System.out.prinln("Still waiting..."); + return !ready; + } ).asValue(); ``` @@ -202,7 +248,15 @@ Note: [Checkstyle](https://en.wikipedia.org/wiki/Checkstyle) is used as a static ## Contributors - - [Kirill Che.](https://github.com/g4s8) g4s8.public@gmail.com + - [@yegor256](https://github.com/yegor256) as Yegor Bugayenko ([Blog](http://www.yegor256.com)) + - [@g4s8](https://github.com/g4s8) as Kirill Che. (g4s8.public@gmail.com) + - [@fabriciofx](https://github.com/fabriciofx) as Fabrício Cabral + - [@englishman](https://github.com/englishman) as Andriy Kryvtsun + - [@VsSekorin](https://github.com/VsSekorin) as Vseslav Sekorin + - [@DronMDF](https://github.com/DronMDF) as Andrey Valyaev + - [@dusan-rychnovsky](https://github.com/dusan-rychnovsky) as Dušan Rychnovský ([Blog](http://blog.dusanrychnovsky.cz/)) + - [@timmeey](https://github.com/timmeey) as Tim Hinkes ([Blog](https://blog.timmeey.de)) + ## License (MIT) diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000000..31927637cc --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,32 @@ +version: '{build}' +skip_tags: true +clone_depth: 10 +environment: + matrix: + - JAVA_HOME: C:\Program Files\Java\jdk1.8.0 +branches: + only: + - master + except: + - gh-pages +os: Windows Server 2012 +install: + - ps: | + Add-Type -AssemblyName System.IO.Compression.FileSystem + if (!(Test-Path -Path "C:\maven" )) { + (new-object System.Net.WebClient).DownloadFile('http://www.us.apache.org/dist/maven/maven-3/3.2.5/binaries/apache-maven-3.2.5-bin.zip', 'C:\maven-bin.zip') + [System.IO.Compression.ZipFile]::ExtractToDirectory("C:\maven-bin.zip", "C:\maven") + } + - cmd: SET PATH=C:\maven\apache-maven-3.2.5\bin;%JAVA_HOME%\bin;%PATH:C:\Ruby193\bin;=% + - cmd: SET M2_HOME=C:\maven\apache-maven-3.2.5 + - cmd: SET MAVEN_OPTS=-XX:MaxPermSize=2g -Xmx4g + - cmd: SET JAVA_OPTS=-XX:MaxPermSize=2g -Xmx4g + - cmd: mvn --version + - cmd: java -version +build_script: + - mvn clean package -B -Dmaven.test.skip=true +test_script: + - mvn clean install --batch-mode -Pqulice +cache: + - C:\maven\ + - C:\Users\appveyor\.m2 diff --git a/pom.xml b/pom.xml index 2843a28630..3c0d043a3b 100644 --- a/pom.xml +++ b/pom.xml @@ -29,7 +29,7 @@ com.jcabi parent - 0.48.1 + 0.48.5 org.cactoos cactoos diff --git a/src/main/java/org/cactoos/Bytes.java b/src/main/java/org/cactoos/Bytes.java index 27e0a9aa98..ec7c67c811 100644 --- a/src/main/java/org/cactoos/Bytes.java +++ b/src/main/java/org/cactoos/Bytes.java @@ -32,6 +32,7 @@ * * @author Yegor Bugayenko (yegor256@gmail.com) * @version $Id$ + * @see org.cactoos.text.TextAsBytes * @since 0.1 */ public interface Bytes { diff --git a/src/main/java/org/cactoos/Func.java b/src/main/java/org/cactoos/Func.java index 1e5bf41078..ee5ff8cb1a 100644 --- a/src/main/java/org/cactoos/Func.java +++ b/src/main/java/org/cactoos/Func.java @@ -26,12 +26,24 @@ /** * Function. * + *

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

+ * + *

If you want to cache the result of the {@link Func} and + * make sure it doesn't calculate anything twice, you can use + * {@link org.cactoos.func.StickyFunc} decorator.

+ * *

There is no thread-safety guarantee. * * @author Yegor Bugayenko (yegor256@gmail.com) * @version $Id$ * @param Type of input * @param Type of output + * @see org.cactoos.func.StickyFunc + * @see org.cactoos.func.UncheckedFunc + * @see org.cactoos.func.IoCheckedFunc * @since 0.1 */ public interface Func { diff --git a/src/main/java/org/cactoos/Input.java b/src/main/java/org/cactoos/Input.java index 2e51152c5a..7b3f037c3a 100644 --- a/src/main/java/org/cactoos/Input.java +++ b/src/main/java/org/cactoos/Input.java @@ -46,6 +46,9 @@ * * @author Yegor Bugayenko (yegor256@gmail.com) * @version $Id$ + * @see org.cactoos.io.BytesAsInput + * @see FileAsInput + * @see org.cactoos.io.PathAsInput * @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 7d5c9ff937..e753024651 100644 --- a/src/main/java/org/cactoos/Output.java +++ b/src/main/java/org/cactoos/Output.java @@ -52,6 +52,8 @@ * * @author Yegor Bugayenko (yegor256@gmail.com) * @version $Id$ + * @see FileAsOutput + * @see org.cactoos.io.PathAsOutput * @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 bdaf7a4f3e..e237cebf79 100644 --- a/src/main/java/org/cactoos/Proc.java +++ b/src/main/java/org/cactoos/Proc.java @@ -31,6 +31,7 @@ * @author Yegor Bugayenko (yegor256@gmail.com) * @version $Id$ * @param Type of input + * @see org.cactoos.func.ProcAsFunc * @since 0.1 */ public interface Proc { diff --git a/src/main/java/org/cactoos/Scalar.java b/src/main/java/org/cactoos/Scalar.java index c8bf2eeb73..9bbeac0ffc 100644 --- a/src/main/java/org/cactoos/Scalar.java +++ b/src/main/java/org/cactoos/Scalar.java @@ -23,16 +23,26 @@ */ package org.cactoos; -import java.io.IOException; - /** * Scalar. * + *

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

+ * + *

If you want to cache the result of the {@link Scalar} and + * make sure it doesn't calculate anything twice, you can use + * {@link org.cactoos.func.StickyScalar} decorator.

+ * *

There is no thread-safety guarantee. * * @author Yegor Bugayenko (yegor256@gmail.com) * @version $Id$ * @param Type of result + * @see org.cactoos.func.StickyScalar + * @see org.cactoos.func.UncheckedScalar + * @see org.cactoos.func.IoCheckedScalar * @since 0.1 */ public interface Scalar { @@ -40,8 +50,8 @@ public interface Scalar { /** * Convert it to the value. * @return The value - * @throws IOException If fails + * @throws Exception If fails */ - T asValue() throws IOException; + T asValue() throws Exception; } diff --git a/src/main/java/org/cactoos/ScalarHasValue.java b/src/main/java/org/cactoos/ScalarHasValue.java index e0fedaaa2c..c6ac248aa5 100644 --- a/src/main/java/org/cactoos/ScalarHasValue.java +++ b/src/main/java/org/cactoos/ScalarHasValue.java @@ -23,7 +23,7 @@ */ package org.cactoos; -import java.io.IOException; +import org.cactoos.func.UncheckedScalar; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; @@ -63,11 +63,9 @@ public ScalarHasValue(final Matcher mtr) { @Override public boolean matchesSafely(final Scalar item) { - try { - return this.matcher.matches(item.asValue()); - } catch (final IOException ex) { - throw new IllegalStateException(ex); - } + return this.matcher.matches( + new UncheckedScalar<>(item).asValue() + ); } @Override diff --git a/src/main/java/org/cactoos/Text.java b/src/main/java/org/cactoos/Text.java index 2511977f64..577917bb85 100644 --- a/src/main/java/org/cactoos/Text.java +++ b/src/main/java/org/cactoos/Text.java @@ -32,6 +32,7 @@ * * @author Yegor Bugayenko (yegor256@gmail.com) * @version $Id$ + * @see org.cactoos.text.StringAsText * @since 0.1 */ public interface Text { diff --git a/src/main/java/org/cactoos/TextHasString.java b/src/main/java/org/cactoos/TextHasString.java index 4f6397598e..a63a083cb3 100644 --- a/src/main/java/org/cactoos/TextHasString.java +++ b/src/main/java/org/cactoos/TextHasString.java @@ -23,7 +23,7 @@ */ package org.cactoos; -import java.io.IOException; +import org.cactoos.text.UncheckedText; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; @@ -62,11 +62,7 @@ public TextHasString(final Matcher mtr) { @Override public boolean matchesSafely(final Text item) { - try { - return this.matcher.matches(item.asString()); - } catch (final IOException ex) { - throw new IllegalStateException(ex); - } + return this.matcher.matches(new UncheckedText(item).asString()); } @Override diff --git a/src/main/java/org/cactoos/func/And.java b/src/main/java/org/cactoos/func/And.java new file mode 100644 index 0000000000..4c8b422a8a --- /dev/null +++ b/src/main/java/org/cactoos/func/And.java @@ -0,0 +1,124 @@ +/** + * 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.Func; +import org.cactoos.Proc; +import org.cactoos.Scalar; +import org.cactoos.list.ArrayAsIterable; +import org.cactoos.list.MappedIterable; + +/** + * Logical conjunction. + * + *

There is no thread-safety guarantee. + * + * @author Vseslav Sekorin (vssekorin@gmail.com) + * @version $Id$ + * @since 0.8 + */ +public final class And implements Scalar { + + /** + * The iterator. + */ + private final Iterable> iterable; + + /** + * Ctor. + * @param proc Proc to map + * @param src The iterable + * @param Type of items in the iterable + */ + @SafeVarargs + public And(final Proc proc, final X... src) { + this(new ProcAsFunc<>(proc, true), src); + } + + /** + * Ctor. + * @param func Func to map + * @param src The iterable + * @param Type of items in the iterable + */ + @SafeVarargs + public And(final Func func, final X... src) { + this(new ArrayAsIterable<>(src), func); + } + + /** + * Ctor. + * @param src The iterable + * @param proc Proc to use + * @param Type of items in the iterable + */ + public And(final Iterable src, final Proc proc) { + this(src, new ProcAsFunc<>(proc, true)); + } + + /** + * Ctor. + * @param src The iterable + * @param func Func to map + * @param Type of items in the iterable + */ + public And(final Iterable src, final Func func) { + this( + new MappedIterable<>( + src, + item -> (Scalar) () -> func.apply(item) + ) + ); + } + + /** + * Ctor. + * @param src The iterable + */ + @SafeVarargs + public And(final Scalar... src) { + this(new ArrayAsIterable<>(src)); + } + + /** + * Ctor. + * @param src The iterable + */ + public And(final Iterable> src) { + this.iterable = src; + } + + @Override + public Boolean asValue() throws Exception { + boolean result = true; + for (final Scalar item : this.iterable) { + if (!item.asValue()) { + result = false; + break; + } + } + return result; + } + +} diff --git a/src/main/java/org/cactoos/func/False.java b/src/main/java/org/cactoos/func/False.java new file mode 100644 index 0000000000..d70e038fdb --- /dev/null +++ b/src/main/java/org/cactoos/func/False.java @@ -0,0 +1,43 @@ +/** + * 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.Scalar; + +/** + * Logical false. + * + *

There is no thread-safety guarantee. + * + * @author Vseslav Sekorin (vssekorin@gmail.com) + * @version $Id$ + * @since 0.7 + */ +public final class False implements Scalar { + + @Override + public Boolean asValue() throws Exception { + return false; + } +} diff --git a/src/main/java/org/cactoos/func/AlwaysTrueFunc.java b/src/main/java/org/cactoos/func/FuncAsProc.java similarity index 65% rename from src/main/java/org/cactoos/func/AlwaysTrueFunc.java rename to src/main/java/org/cactoos/func/FuncAsProc.java index fb396e03f9..13e50948bd 100644 --- a/src/main/java/org/cactoos/func/AlwaysTrueFunc.java +++ b/src/main/java/org/cactoos/func/FuncAsProc.java @@ -27,54 +27,32 @@ import org.cactoos.Proc; /** - * Func as that is always true. - * - *

You may want to use this decorator when you need - * a procedure that returns boolean instead of a function:

- * - *
 List<String> list = new LinkedList<>();
- * new AllOf(
- *   new IterableAsBooleans<String>(
- *     Collections.emptyList(),
- *     new AlwaysTrueFunc<>(list::add)
- *   )
- * ).asValue();
- * 
+ * Func as Proc. * *

There is no thread-safety guarantee. * * @author Yegor Bugayenko (yegor256@gmail.com) * @version $Id$ * @param Type of input - * @since 0.2 + * @since 0.6 */ -public final class AlwaysTrueFunc implements Func { +public final class FuncAsProc implements Proc { /** - * Original func. + * The func. */ private final Func func; /** * Ctor. - * @param proc Encapsulated proc - */ - public AlwaysTrueFunc(final Proc proc) { - this(new ProcAsFunc<>(proc)); - } - - /** - * Ctor. - * @param fnc Encapsulated func + * @param fnc The proc */ - public AlwaysTrueFunc(final Func fnc) { + public FuncAsProc(final Func fnc) { this.func = fnc; } @Override - public Boolean apply(final X input) throws Exception { + public void exec(final X input) throws Exception { this.func.apply(input); - return true; } - } diff --git a/src/main/java/org/cactoos/func/FuncWithFallback.java b/src/main/java/org/cactoos/func/FuncWithFallback.java new file mode 100644 index 0000000000..9667a3d91b --- /dev/null +++ b/src/main/java/org/cactoos/func/FuncWithFallback.java @@ -0,0 +1,95 @@ +/** + * 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.Func; + +/** + * Func with a fallback plan. + * + *

There is no thread-safety guarantee. + * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @param Type of input + * @param Type of output + * @since 0.2 + */ +public final class FuncWithFallback implements Func { + + /** + * The func. + */ + private final Func func; + + /** + * The fallback. + */ + private final Func fallback; + + /** + * The follow up. + */ + private final Func follow; + + /** + * Ctor. + * @param fnc The func + * @param fbk The fallback + */ + public FuncWithFallback(final Func fnc, + final Func fbk) { + this(fnc, fbk, input -> input); + } + + /** + * Ctor. + * @param fnc The func + * @param fbk The fallback + * @param flw The follow up func + */ + public FuncWithFallback(final Func fnc, + final Func fbk, final Func flw) { + this.func = fnc; + this.fallback = fbk; + this.follow = flw; + } + + @Override + @SuppressWarnings("PMD.AvoidCatchingThrowable") + public Y apply(final X input) throws Exception { + Y result; + try { + result = this.func.apply(input); + } catch (final InterruptedException ex) { + Thread.currentThread().interrupt(); + result = this.fallback.apply(ex); + // @checkstyle IllegalCatchCheck (1 line) + } catch (final Throwable ex) { + result = this.fallback.apply(ex); + } + return this.follow.apply(result); + } + +} diff --git a/src/main/java/org/cactoos/func/FuncWithCallback.java b/src/main/java/org/cactoos/func/IoCheckedFunc.java similarity index 69% rename from src/main/java/org/cactoos/func/FuncWithCallback.java rename to src/main/java/org/cactoos/func/IoCheckedFunc.java index 2e0dc53e06..bc083ceb86 100644 --- a/src/main/java/org/cactoos/func/FuncWithCallback.java +++ b/src/main/java/org/cactoos/func/IoCheckedFunc.java @@ -23,10 +23,12 @@ */ package org.cactoos.func; +import java.io.IOException; import org.cactoos.Func; /** - * Func with Callback. + * Func that doesn't throw checked {@link Exception}, but throws + * {@link IOException} instead. * *

There is no thread-safety guarantee. * @@ -34,45 +36,43 @@ * @version $Id$ * @param Type of input * @param Type of output - * @since 0.2 + * @since 0.4 */ -public final class FuncWithCallback implements Func { +public final class IoCheckedFunc implements Func { /** - * The func. + * Original func. */ private final Func func; - /** - * The callback. - */ - private final Func callback; - /** * Ctor. - * @param fnc The func - * @param cbk The callback + * @param fnc Encapsulated func */ - public FuncWithCallback(final Func fnc, - final Func cbk) { + public IoCheckedFunc(final Func fnc) { this.func = fnc; - this.callback = cbk; } @Override - @SuppressWarnings("PMD.AvoidCatchingThrowable") - public Y apply(final X input) throws Exception { - Y result; + @SuppressWarnings + ( + { + "PMD.AvoidCatchingGenericException", + "PMD.AvoidRethrowingException" + } + ) + public Y apply(final X input) throws IOException { try { - result = this.func.apply(input); + return this.func.apply(input); + } catch (final IOException ex) { + throw ex; } catch (final InterruptedException ex) { Thread.currentThread().interrupt(); - result = this.callback.apply(ex); + throw new IOException(ex); // @checkstyle IllegalCatchCheck (1 line) - } catch (final Throwable ex) { - result = this.callback.apply(ex); + } catch (final Exception ex) { + throw new IOException(ex); } - return result; } } diff --git a/src/main/java/org/cactoos/func/IoCheckedProc.java b/src/main/java/org/cactoos/func/IoCheckedProc.java new file mode 100644 index 0000000000..ed17d8af7e --- /dev/null +++ b/src/main/java/org/cactoos/func/IoCheckedProc.java @@ -0,0 +1,66 @@ +/** + * 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.Func; +import org.cactoos.Proc; + +/** + * Proc that doesn't throw checked {@link Exception}, but + * throws {@link java.io.IOException} instead. + * + *

There is no thread-safety guarantee. + * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @param Type of input + * @since 0.4 + */ +public final class IoCheckedProc implements Proc { + + /** + * Original proc. + */ + private final Proc proc; + + /** + * Ctor. + * @param prc Encapsulated func + */ + public IoCheckedProc(final Proc prc) { + this.proc = prc; + } + + @Override + public void exec(final X input) throws IOException { + new IoCheckedFunc<>( + (Func) arg -> { + this.proc.exec(arg); + return true; + } + ).apply(input); + } + +} diff --git a/src/main/java/org/cactoos/list/AnyOf.java b/src/main/java/org/cactoos/func/IoCheckedScalar.java similarity index 69% rename from src/main/java/org/cactoos/list/AnyOf.java rename to src/main/java/org/cactoos/func/IoCheckedScalar.java index a08b63a7cd..23356dbff3 100644 --- a/src/main/java/org/cactoos/list/AnyOf.java +++ b/src/main/java/org/cactoos/func/IoCheckedScalar.java @@ -21,44 +21,42 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package org.cactoos.list; +package org.cactoos.func; +import java.io.IOException; import org.cactoos.Scalar; /** - * Is {@code true} when any item in the collection is {@code true}. + * Scalar 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$ - * @since 0.1 + * @param Type of result + * @since 0.4 */ -public final class AnyOf implements Scalar { +public final class IoCheckedScalar implements Scalar { /** - * Iterable. + * Original scalar. */ - private final Iterable iterable; + private final Scalar scalar; /** * Ctor. - * @param src Source iterable + * @param scalar Encapsulated scalar */ - public AnyOf(final Iterable src) { - this.iterable = src; + public IoCheckedScalar(final Scalar scalar) { + this.scalar = scalar; } @Override - public Boolean asValue() { - boolean success = false; - for (final Boolean item : this.iterable) { - if (item) { - success = true; - break; - } - } - return success; + public T asValue() throws IOException { + return new IoCheckedFunc, T>( + Scalar::asValue + ).apply(this.scalar); } } diff --git a/src/main/java/org/cactoos/func/Neg.java b/src/main/java/org/cactoos/func/Neg.java new file mode 100644 index 0000000000..8999393d40 --- /dev/null +++ b/src/main/java/org/cactoos/func/Neg.java @@ -0,0 +1,56 @@ +/** + * 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.Scalar; + +/** + * Negative. + * + *

There is no thread-safety guarantee. + * + * @author Vseslav Sekorin (vssekorin@gmail.com) + * @version $Id$ + * @since 0.7 + */ +public final class Neg implements Scalar { + + /** + * The origin scalar. + */ + private final Scalar origin; + + /** + * Ctor. + * @param origin The scalar + */ + public Neg(final Scalar origin) { + this.origin = origin; + } + + @Override + public Boolean asValue() throws Exception { + return !this.origin.asValue(); + } +} diff --git a/src/main/java/org/cactoos/func/Or.java b/src/main/java/org/cactoos/func/Or.java new file mode 100644 index 0000000000..ff424ae921 --- /dev/null +++ b/src/main/java/org/cactoos/func/Or.java @@ -0,0 +1,74 @@ +/** + * 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.Scalar; +import org.cactoos.list.ArrayAsIterable; + +/** + * Logical disjunction. + * + *

There is no thread-safety guarantee. + * + * @author Vseslav Sekorin (vssekorin@gmail.com) + * @version $Id$ + * @since 0.8 + */ +public final class Or implements Scalar { + + /** + * The iterator. + */ + private final Iterable> iterable; + + /** + * Ctor. + * @param src The iterable + */ + @SafeVarargs + public Or(final Scalar... src) { + this(new ArrayAsIterable<>(src)); + } + + /** + * Ctor. + * @param src The iterable + */ + public Or(final Iterable> src) { + this.iterable = src; + } + + @Override + public Boolean asValue() throws Exception { + boolean result = false; + for (final Scalar item : this.iterable) { + if (item.asValue()) { + result = true; + break; + } + } + return result; + } + +} diff --git a/src/main/java/org/cactoos/func/ProcAsFunc.java b/src/main/java/org/cactoos/func/ProcAsFunc.java index 33d2caf3e0..ac41c7f061 100644 --- a/src/main/java/org/cactoos/func/ProcAsFunc.java +++ b/src/main/java/org/cactoos/func/ProcAsFunc.java @@ -46,17 +46,33 @@ public final class ProcAsFunc implements Func { */ private final Proc proc; + /** + * The result. + */ + private final Y result; + /** * Ctor. * @param prc The proc */ public ProcAsFunc(final Proc prc) { + this(prc, null); + } + + /** + * Ctor. + * @param prc The proc + * @param rslt Result to return + * @since 0.7 + */ + public ProcAsFunc(final Proc prc, final Y rslt) { this.proc = prc; + this.result = rslt; } @Override public Y apply(final X input) throws Exception { this.proc.exec(input); - return null; + return this.result; } } diff --git a/src/main/java/org/cactoos/func/RepeatedFunc.java b/src/main/java/org/cactoos/func/RepeatedFunc.java new file mode 100644 index 0000000000..5b2d55a4ab --- /dev/null +++ b/src/main/java/org/cactoos/func/RepeatedFunc.java @@ -0,0 +1,82 @@ +/** + * 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.Func; +import org.cactoos.text.FormattedText; + +/** + * Func that repeats its calculation a few times before + * returning the last result. + * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @param Type of input + * @param Type of output + * @since 0.6 + */ +public final class RepeatedFunc implements Func { + + /** + * Original func. + */ + private final Func func; + + /** + * How many times to run. + */ + private final int times; + + /** + * Ctor. + * + *

If {@code max} is equal or less than zero {@link #apply(Object)} + * will return {@code null}.

+ * + * @param fnc Func original + * @param max How many times + */ + public RepeatedFunc(final Func fnc, final int max) { + this.func = fnc; + this.times = max; + } + + @Override + public Y apply(final X input) throws Exception { + Y result = null; + for (int idx = 0; idx < this.times; ++idx) { + result = this.func.apply(input); + } + if (result == null) { + throw new IllegalArgumentException( + new FormattedText( + "Repeat counter is equal or less than zero: %d", + this.times + ).asString() + ); + } + return result; + } + +} diff --git a/src/main/java/org/cactoos/func/RetryFunc.java b/src/main/java/org/cactoos/func/RetryFunc.java new file mode 100644 index 0000000000..463a375e77 --- /dev/null +++ b/src/main/java/org/cactoos/func/RetryFunc.java @@ -0,0 +1,102 @@ +/** + * 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.Func; + +/** + * Func that will try a few times before throwing an exception. + * + *

There is no thread-safety guarantee. + * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @param Type of input + * @param Type of output + * @since 0.8 + */ +public final class RetryFunc implements Func { + + /** + * Original func. + */ + private final Func func; + + /** + * Exit condition. + */ + private final Func exit; + + /** + * Ctor. + * @param fnc Func original + */ + public RetryFunc(final Func fnc) { + // @checkstyle MagicNumberCheck (1 line) + this(fnc, 3); + } + + /** + * Ctor. + * @param fnc Func original + * @param attempts Maximum number of attempts + */ + public RetryFunc(final Func fnc, final int attempts) { + this(fnc, attempt -> attempt >= attempts); + } + + /** + * Ctor. + * @param fnc Func original + * @param ext Exit condition, returns TRUE if there is no more reason to try + */ + public RetryFunc(final Func fnc, final Func ext) { + this.func = fnc; + this.exit = ext; + } + + @Override + @SuppressWarnings("PMD.AvoidCatchingGenericException") + public Y apply(final X input) throws Exception { + int attempt = 0; + Exception error = new IllegalArgumentException( + "An immediate exit, didn't have a chance to try at least once" + ); + while (!this.exit.apply(attempt)) { + try { + return this.func.apply(input); + } catch (final InterruptedException ex) { + Thread.currentThread().interrupt(); + error = ex; + break; + // @checkstyle IllegalCatchCheck (1 line) + } catch (final Exception ex) { + error = ex; + } + ++attempt; + } + throw error; + } + +} diff --git a/src/main/java/org/cactoos/func/RetryScalar.java b/src/main/java/org/cactoos/func/RetryScalar.java new file mode 100644 index 0000000000..39c104acf5 --- /dev/null +++ b/src/main/java/org/cactoos/func/RetryScalar.java @@ -0,0 +1,86 @@ +/** + * 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.Func; +import org.cactoos.Scalar; + +/** + * Func that will try a few times before throwing an exception. + * + *

There is no thread-safety guarantee. + * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @param Type of output + * @since 0.9 + */ +public final class RetryScalar implements Scalar { + + /** + * Original scalar. + */ + private final Scalar scalar; + + /** + * Exit condition. + */ + private final Func exit; + + /** + * Ctor. + * @param slr Scalar original + */ + public RetryScalar(final Scalar slr) { + // @checkstyle MagicNumberCheck (1 line) + this(slr, 3); + } + + /** + * Ctor. + * @param slr Scalar original + * @param attempts Maximum number of attempts + */ + public RetryScalar(final Scalar slr, final int attempts) { + this(slr, attempt -> attempt >= attempts); + } + + /** + * Ctor. + * @param slr Func original + * @param ext Exit condition, returns TRUE if there is no more reason to try + */ + public RetryScalar(final Scalar slr, final Func ext) { + this.scalar = slr; + this.exit = ext; + } + + @Override + public T asValue() throws Exception { + return new RetryFunc<>( + (Func) input -> this.scalar.asValue(), + this.exit + ).apply(true); + } +} diff --git a/src/main/java/org/cactoos/func/RunnableWithFallback.java b/src/main/java/org/cactoos/func/RunnableWithFallback.java new file mode 100644 index 0000000000..c616b0e047 --- /dev/null +++ b/src/main/java/org/cactoos/func/RunnableWithFallback.java @@ -0,0 +1,70 @@ +/** + * 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.Proc; + +/** + * Runnable with a fallback plan. + * + *

There is no thread-safety guarantee. + * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @since 0.6 + */ +public final class RunnableWithFallback implements Runnable { + + /** + * The runnable. + */ + private final Runnable runnable; + + /** + * The fallback. + */ + private final Proc fallback; + + /** + * Ctor. + * @param rnb Runnable + * @param fbk The fallback + */ + public RunnableWithFallback(final Runnable rnb, + final Proc fbk) { + this.runnable = rnb; + this.fallback = fbk; + } + + @Override + public void run() { + new UncheckedFunc<>( + new FuncWithFallback( + new RunnableAsFunc<>(this.runnable), + new ProcAsFunc<>(this.fallback) + ) + ).apply(true); + } + +} diff --git a/src/main/java/org/cactoos/func/StickyFunc.java b/src/main/java/org/cactoos/func/StickyFunc.java index 5a4645ec81..d53aa1a140 100644 --- a/src/main/java/org/cactoos/func/StickyFunc.java +++ b/src/main/java/org/cactoos/func/StickyFunc.java @@ -31,12 +31,16 @@ * Func that caches previously calculated values and doesn't * recalculate again. * + *

This {@link Func} decorator technically is an in-memory + * cache.

+ * *

There is no thread-safety guarantee. * * @author Yegor Bugayenko (yegor256@gmail.com) * @version $Id$ * @param Type of input * @param Type of output + * @see StickyScalar * @since 0.1 */ public final class StickyFunc implements Func { diff --git a/src/main/java/org/cactoos/func/StickyScalar.java b/src/main/java/org/cactoos/func/StickyScalar.java new file mode 100644 index 0000000000..dba757846d --- /dev/null +++ b/src/main/java/org/cactoos/func/StickyScalar.java @@ -0,0 +1,65 @@ +/** + * 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.Func; +import org.cactoos.Scalar; + +/** + * Cached version of a Scalar. + * + *

This {@link Scalar} decorator technically is an in-memory + * cache.

+ * + *

There is no thread-safety guarantee. + * + * @author Tim Hinkes (timmeey@timmeey.de) + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @param Type of result + * @see StickyFunc + * @since 0.3 + */ +public final class StickyScalar implements Scalar { + + /** + * Func. + */ + private final Func func; + + /** + * Ctor. + * @param src The Scalar to cache + */ + public StickyScalar(final Scalar src) { + this.func = new StickyFunc<>( + input -> src.asValue() + ); + } + + @Override + public T asValue() throws Exception { + return this.func.apply(true); + } +} diff --git a/src/main/java/org/cactoos/func/SyncFunc.java b/src/main/java/org/cactoos/func/SyncFunc.java new file mode 100644 index 0000000000..ccc8d80f41 --- /dev/null +++ b/src/main/java/org/cactoos/func/SyncFunc.java @@ -0,0 +1,59 @@ +/** + * 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.Func; + +/** + * Func that is thread-safe. + * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @param Type of input + * @param Type of output + * @since 0.4 + */ +public final class SyncFunc implements Func { + + /** + * Original func. + */ + private final Func func; + + /** + * Ctor. + * @param fnc Func original + */ + public SyncFunc(final Func fnc) { + this.func = fnc; + } + + @Override + public Y apply(final X input) throws Exception { + synchronized (this.func) { + return this.func.apply(input); + } + } + +} diff --git a/src/main/java/org/cactoos/func/SyncProc.java b/src/main/java/org/cactoos/func/SyncProc.java new file mode 100644 index 0000000000..ed9de046ef --- /dev/null +++ b/src/main/java/org/cactoos/func/SyncProc.java @@ -0,0 +1,58 @@ +/** + * 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.Proc; + +/** + * Proc that is thread-safe. + * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @param Type of input + * @since 0.4 + */ +public final class SyncProc implements Proc { + + /** + * Original proc. + */ + private final Proc proc; + + /** + * Ctor. + * @param prc Func original + */ + public SyncProc(final Proc prc) { + this.proc = prc; + } + + @Override + public void exec(final X input) throws Exception { + synchronized (this.proc) { + this.proc.exec(input); + } + } + +} diff --git a/src/main/java/org/cactoos/func/SyncScalar.java b/src/main/java/org/cactoos/func/SyncScalar.java new file mode 100644 index 0000000000..26c3112941 --- /dev/null +++ b/src/main/java/org/cactoos/func/SyncScalar.java @@ -0,0 +1,57 @@ +/** + * 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.Scalar; + +/** + * Scalar that is thread-safe. + * + * @author Tim Hinkes (timmeey@timmeey.de) + * @version $Id$ + * @param Type of result + * @since 0.3 + */ +public final class SyncScalar implements Scalar { + + /** + * The scalar to cache. + */ + private final Scalar source; + + /** + * Ctor. + * @param src The Scalar to cache + */ + public SyncScalar(final Scalar src) { + this.source = src; + } + + @Override + public T asValue() throws Exception { + synchronized (this.source) { + return this.source.asValue(); + } + } +} diff --git a/src/main/java/org/cactoos/func/Ternary.java b/src/main/java/org/cactoos/func/Ternary.java new file mode 100644 index 0000000000..4a8ed9c153 --- /dev/null +++ b/src/main/java/org/cactoos/func/Ternary.java @@ -0,0 +1,81 @@ +/** + * 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.Scalar; + +/** + * Ternary operation. + * + *

There is no thread-safety guarantee. + * + * @author Vseslav Sekorin (vssekorin@gmail.com) + * @version $Id$ + * @param Type of item. + * @since 0.8 + */ +public final class Ternary implements Scalar { + + /** + * The condition. + */ + private final Scalar condition; + + /** + * The consequent. + */ + private final T cons; + + /** + * The alternative. + */ + private final T alter; + + /** + * Ctor. + * @param condition The condition + * @param cons The consequent + * @param alter The alternative + */ + public Ternary( + final Scalar condition, + final T cons, + final T alter + ) { + this.condition = condition; + this.cons = cons; + this.alter = alter; + } + + @Override + public T asValue() throws Exception { + final T result; + if (this.condition.asValue()) { + result = this.cons; + } else { + result = this.alter; + } + return result; + } +} diff --git a/src/main/java/org/cactoos/func/True.java b/src/main/java/org/cactoos/func/True.java new file mode 100644 index 0000000000..8f3584ceae --- /dev/null +++ b/src/main/java/org/cactoos/func/True.java @@ -0,0 +1,43 @@ +/** + * 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.Scalar; + +/** + * Logical truth. + * + *

There is no thread-safety guarantee. + * + * @author Vseslav Sekorin (vssekorin@gmail.com) + * @version $Id$ + * @since 0.7 + */ +public final class True implements Scalar { + + @Override + public Boolean asValue() throws Exception { + return true; + } +} diff --git a/src/main/java/org/cactoos/func/UncheckedFunc.java b/src/main/java/org/cactoos/func/UncheckedFunc.java index b62582473c..e4ee5c7c26 100644 --- a/src/main/java/org/cactoos/func/UncheckedFunc.java +++ b/src/main/java/org/cactoos/func/UncheckedFunc.java @@ -23,6 +23,8 @@ */ package org.cactoos.func; +import java.io.IOException; +import java.io.UncheckedIOException; import org.cactoos.Func; /** @@ -52,16 +54,11 @@ public UncheckedFunc(final Func fnc) { } @Override - @SuppressWarnings("PMD.AvoidCatchingGenericException") public Y apply(final X input) { try { - return this.func.apply(input); - } catch (final InterruptedException ex) { - Thread.currentThread().interrupt(); - throw new IllegalStateException(ex); - // @checkstyle IllegalCatchCheck (1 line) - } catch (final Exception ex) { - throw new IllegalStateException(ex); + return new IoCheckedFunc<>(this.func).apply(input); + } catch (final IOException ex) { + throw new UncheckedIOException(ex); } } diff --git a/src/main/java/org/cactoos/func/UncheckedProc.java b/src/main/java/org/cactoos/func/UncheckedProc.java index 66df43f6c9..5999d2d3e2 100644 --- a/src/main/java/org/cactoos/func/UncheckedProc.java +++ b/src/main/java/org/cactoos/func/UncheckedProc.java @@ -23,7 +23,6 @@ */ package org.cactoos.func; -import org.cactoos.Func; import org.cactoos.Proc; /** @@ -53,12 +52,7 @@ public UncheckedProc(final Proc prc) { @Override public void exec(final X input) { - new UncheckedFunc<>( - (Func) arg -> { - this.proc.exec(arg); - return true; - } - ).apply(input); + new UncheckedFunc<>(new ProcAsFunc<>(this.proc)).apply(input); } } diff --git a/src/main/java/org/cactoos/func/UncheckedScalar.java b/src/main/java/org/cactoos/func/UncheckedScalar.java new file mode 100644 index 0000000000..d421534687 --- /dev/null +++ b/src/main/java/org/cactoos/func/UncheckedScalar.java @@ -0,0 +1,64 @@ +/** + * 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 java.io.UncheckedIOException; +import org.cactoos.Scalar; + +/** + * Scalar that doesn't throw checked {@link Exception}. + * + *

There is no thread-safety guarantee. + * + * @author Fabricio Cabral (fabriciofx@gmail.com) + * @version $Id$ + * @param Type of result + * @since 0.3 + */ +public final class UncheckedScalar implements Scalar { + + /** + * Original scalar. + */ + private final Scalar scalar; + + /** + * Ctor. + * @param scr Encapsulated scalar + */ + public UncheckedScalar(final Scalar scr) { + this.scalar = scr; + } + + @Override + public T asValue() { + try { + return new IoCheckedScalar<>(this.scalar).asValue(); + } catch (final IOException ex) { + throw new UncheckedIOException(ex); + } + } + +} diff --git a/src/main/java/org/cactoos/io/BytesAsInput.java b/src/main/java/org/cactoos/io/BytesAsInput.java index 1eabae559f..400d324eed 100644 --- a/src/main/java/org/cactoos/io/BytesAsInput.java +++ b/src/main/java/org/cactoos/io/BytesAsInput.java @@ -28,6 +28,9 @@ import java.io.InputStream; import org.cactoos.Bytes; import org.cactoos.Input; +import org.cactoos.Text; +import org.cactoos.text.ArrayAsBytes; +import org.cactoos.text.TextAsBytes; /** * Bytes as Input. @@ -45,6 +48,32 @@ public final class BytesAsInput implements Input { */ private final Bytes source; + /** + * Ctor. + * @param text The text + * @since 0.8 + */ + public BytesAsInput(final Text text) { + this(new TextAsBytes(text)); + } + + /** + * Ctor. + * @param text The text + * @since 0.4 + */ + public BytesAsInput(final String text) { + this(new TextAsBytes(text)); + } + + /** + * Ctor. + * @param bytes The bytes + */ + public BytesAsInput(final byte[] bytes) { + this(new ArrayAsBytes(bytes)); + } + /** * Ctor. * @param bytes The bytes diff --git a/src/main/java/org/cactoos/io/FileAsInput.java b/src/main/java/org/cactoos/io/FileAsInput.java index e7611e8393..1c418996e1 100644 --- a/src/main/java/org/cactoos/io/FileAsInput.java +++ b/src/main/java/org/cactoos/io/FileAsInput.java @@ -28,6 +28,8 @@ import java.io.FileNotFoundException; import java.io.InputStream; import org.cactoos.Input; +import org.cactoos.Scalar; +import org.cactoos.func.UncheckedScalar; /** * File as Input. @@ -43,19 +45,37 @@ public final class FileAsInput implements Input { /** * The file. */ - private final File file; + private final UncheckedScalar file; /** * Ctor. * @param src The file */ public FileAsInput(final File src) { + this(() -> src); + } + + /** + * Ctor. + * @param src The file + * @since 0.8 + */ + public FileAsInput(final Scalar src) { + this(new UncheckedScalar<>(src)); + } + + /** + * Ctor. + * @param src The file + * @since 0.8 + */ + public FileAsInput(final UncheckedScalar src) { this.file = src; } @Override public InputStream stream() throws FileNotFoundException { - return new FileInputStream(this.file); + return new FileInputStream(this.file.asValue()); } } diff --git a/src/main/java/org/cactoos/io/FileAsOutput.java b/src/main/java/org/cactoos/io/FileAsOutput.java index 0a2a056cd3..7724910709 100644 --- a/src/main/java/org/cactoos/io/FileAsOutput.java +++ b/src/main/java/org/cactoos/io/FileAsOutput.java @@ -28,6 +28,8 @@ import java.io.FileOutputStream; import java.io.OutputStream; import org.cactoos.Output; +import org.cactoos.Scalar; +import org.cactoos.func.UncheckedScalar; /** * File as Output. @@ -43,19 +45,37 @@ public final class FileAsOutput implements Output { /** * The file. */ - private final File file; + private final UncheckedScalar file; /** * Ctor. * @param src The file */ public FileAsOutput(final File src) { + this(() -> src); + } + + /** + * Ctor. + * @param src The file + * @since 0.8 + */ + public FileAsOutput(final Scalar src) { + this(new UncheckedScalar<>(src)); + } + + /** + * Ctor. + * @param src The file + * @since 0.8 + */ + public FileAsOutput(final UncheckedScalar src) { this.file = src; } @Override public OutputStream stream() throws FileNotFoundException { - return new FileOutputStream(this.file); + return new FileOutputStream(this.file.asValue()); } } diff --git a/src/main/java/org/cactoos/io/InputAsBytes.java b/src/main/java/org/cactoos/io/InputAsBytes.java index 667edddc5f..0ea6e9b340 100644 --- a/src/main/java/org/cactoos/io/InputAsBytes.java +++ b/src/main/java/org/cactoos/io/InputAsBytes.java @@ -71,11 +71,11 @@ public InputAsBytes(final Input input, final int max) { @Override public byte[] asBytes() throws IOException { - try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) { + try (final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final InputStream stream = new TeeInput( this.source, new OutputStreamAsOutput(baos) - ).stream(); + ).stream()) { final byte[] buf = new byte[this.size]; while (true) { if (stream.read(buf) != buf.length) { diff --git a/src/main/java/org/cactoos/io/InputAsLSInput.java b/src/main/java/org/cactoos/io/InputAsLSInput.java new file mode 100644 index 0000000000..0814935665 --- /dev/null +++ b/src/main/java/org/cactoos/io/InputAsLSInput.java @@ -0,0 +1,189 @@ +/** + * 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.io; + +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.nio.charset.StandardCharsets; +import org.cactoos.Input; +import org.cactoos.text.BytesAsText; +import org.cactoos.text.UncheckedText; +import org.w3c.dom.ls.LSInput; + +// @checkstyle AbbreviationAsWordInNameCheck (10 lines) +/** + * Input as LSInput. + * + *

There is no thread-safety guarantee. + * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @since 0.6 + */ +public final class InputAsLSInput implements LSInput { + + /** + * The input. + */ + private final Input input; + + /** + * PublicID. + */ + private final String pid; + + /** + * SystemID. + */ + private final String sid; + + /** + * Base. + */ + private final String base; + + /** + * Ctor. + * @param inpt Input + */ + public InputAsLSInput(final Input inpt) { + this(inpt, "#public", "#system", "#base"); + } + + // @checkstyle ParameterNumberCheck (10 lines) + /** + * Ctor. + * @param inpt Input + * @param pubid PublicID + * @param sysid SystemID + * @param bse Base + */ + public InputAsLSInput(final Input inpt, final String pubid, + final String sysid, final String bse) { + this.input = inpt; + this.pid = pubid; + this.sid = sysid; + this.base = bse; + } + + @Override + public Reader getCharacterStream() { + return new InputStreamReader(this.getByteStream()); + } + + @Override + public void setCharacterStream(final Reader stream) { + throw new UnsupportedOperationException( + "#setCharacterStream() is not supported" + ); + } + + @Override + public InputStream getByteStream() { + return new UncheckedInput(this.input).stream(); + } + + @Override + public void setByteStream(final InputStream stream) { + throw new UnsupportedOperationException( + "#setByteStream() is not supported" + ); + } + + @Override + public String getStringData() { + return new UncheckedText( + new BytesAsText(new InputAsBytes(this.input)) + ).asString(); + } + + @Override + public void setStringData(final String data) { + throw new UnsupportedOperationException( + "#setStringData() is not supported" + ); + } + + @Override + public String getSystemId() { + return this.sid; + } + + @Override + public void setSystemId(final String sysid) { + throw new UnsupportedOperationException( + "#setSystemId() is not supported" + ); + } + + @Override + public String getPublicId() { + return this.pid; + } + + @Override + public void setPublicId(final String pubid) { + throw new UnsupportedOperationException( + "#setPublicId() is not supported" + ); + } + + @Override + public String getBaseURI() { + return this.base; + } + + @Override + public void setBaseURI(final String uri) { + throw new UnsupportedOperationException( + "#setBaseURI() is not supported" + ); + } + + @Override + public String getEncoding() { + return StandardCharsets.UTF_8.displayName(); + } + + @Override + public void setEncoding(final String encoding) { + throw new UnsupportedOperationException( + "#setEncoding() is not supported" + ); + } + + @Override + @SuppressWarnings("PMD.BooleanGetMethodName") + public boolean getCertifiedText() { + return true; + } + + @Override + public void setCertifiedText(final boolean text) { + throw new UnsupportedOperationException( + "#setCertifiedText() is not supported" + ); + } +} diff --git a/src/main/java/org/cactoos/io/InputAsProperties.java b/src/main/java/org/cactoos/io/InputAsProperties.java new file mode 100644 index 0000000000..d243c92884 --- /dev/null +++ b/src/main/java/org/cactoos/io/InputAsProperties.java @@ -0,0 +1,95 @@ +/** + * 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.io; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; +import org.cactoos.Bytes; +import org.cactoos.Input; +import org.cactoos.Scalar; +import org.cactoos.Text; +import org.cactoos.text.StringAsText; +import org.cactoos.text.TextAsBytes; + +/** + * Input as {@link Properties}. + * + *

There is no thread-safety guarantee. + * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @since 0.8 + */ +public final class InputAsProperties implements Scalar { + + /** + * The input. + */ + private final Input source; + + /** + * Ctor. + * @param text Text + * @since 0.9 + */ + public InputAsProperties(final String text) { + this(new StringAsText(text)); + } + + /** + * Ctor. + * @param text Text + * @since 0.9 + */ + public InputAsProperties(final Text text) { + this(new TextAsBytes(text)); + } + + /** + * Ctor. + * @param bytes Bytes + * @since 0.9 + */ + public InputAsProperties(final Bytes bytes) { + this(new BytesAsInput(bytes)); + } + + /** + * Ctor. + * @param input The input + */ + public InputAsProperties(final Input input) { + this.source = input; + } + + @Override + public Properties asValue() throws IOException { + final Properties props = new Properties(); + try (final InputStream input = this.source.stream()) { + props.load(input); + } + return props; + } +} diff --git a/src/main/java/org/cactoos/io/LengthOfInput.java b/src/main/java/org/cactoos/io/LengthOfInput.java index 2fa55ce1ba..9a6b0cc337 100644 --- a/src/main/java/org/cactoos/io/LengthOfInput.java +++ b/src/main/java/org/cactoos/io/LengthOfInput.java @@ -29,7 +29,7 @@ import org.cactoos.Scalar; /** - * Length of Input. + * Length of {@link Input}. * *

There is no thread-safety guarantee. * @@ -70,19 +70,20 @@ public LengthOfInput(final Input input, final int max) { @Override public Long asValue() throws IOException { - final InputStream stream = this.source.stream(); - final byte[] buf = new byte[this.size]; - long length = 0L; - while (true) { - final int len = stream.read(buf); - if (len > 0) { - length += (long) len; - } - if (len != buf.length) { - break; + try (final InputStream stream = this.source.stream()) { + final byte[] buf = new byte[this.size]; + long length = 0L; + while (true) { + final int len = stream.read(buf); + if (len > 0) { + length += (long) len; + } + if (len < 0) { + break; + } } + return length; } - return length; } } diff --git a/src/main/java/org/cactoos/io/NotNullInput.java b/src/main/java/org/cactoos/io/NotNullInput.java new file mode 100644 index 0000000000..8d481c2537 --- /dev/null +++ b/src/main/java/org/cactoos/io/NotNullInput.java @@ -0,0 +1,62 @@ +/** + * 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.io; + +import java.io.IOException; +import java.io.InputStream; +import org.cactoos.Input; + +/** + * A safe Input. + * + *

There is no thread-safety guarantee. + * + * @author Fabricio Cabral (fabriciofx@gmail.com) + * @version $Id$ + * @since 0.3 + */ +public final class NotNullInput implements Input { + + /** + * The input. + */ + private final Input origin; + + /** + * Ctor. + * @param input The input + */ + public NotNullInput(final Input input) { + this.origin = input; + } + + @Override + public InputStream stream() throws IOException { + if (this.origin == null) { + throw new IOException("NULL instead of a valid input"); + } + return this.origin.stream(); + } + +} diff --git a/src/main/java/org/cactoos/io/NotNullOutput.java b/src/main/java/org/cactoos/io/NotNullOutput.java new file mode 100644 index 0000000000..82b072e2fd --- /dev/null +++ b/src/main/java/org/cactoos/io/NotNullOutput.java @@ -0,0 +1,62 @@ +/** + * 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.io; + +import java.io.IOException; +import java.io.OutputStream; +import org.cactoos.Output; + +/** + * A safe Output. + * + *

There is no thread-safety guarantee. + * + * @author Fabricio Cabral (fabriciofx@gmail.com) + * @version $Id$ + * @since 0.3 + */ +public final class NotNullOutput implements Output { + + /** + * The output. + */ + private final Output origin; + + /** + * Ctor. + * @param output The output + */ + public NotNullOutput(final Output output) { + this.origin = output; + } + + @Override + public OutputStream stream() throws IOException { + if (this.origin == null) { + throw new IOException("NULL instead of a valid output"); + } + return this.origin.stream(); + } + +} diff --git a/src/main/java/org/cactoos/io/ResourceAsInput.java b/src/main/java/org/cactoos/io/ResourceAsInput.java index ed8dbf9bb8..da7ff7c0cb 100644 --- a/src/main/java/org/cactoos/io/ResourceAsInput.java +++ b/src/main/java/org/cactoos/io/ResourceAsInput.java @@ -25,11 +25,19 @@ import java.io.IOException; import java.io.InputStream; +import org.cactoos.Func; import org.cactoos.Input; +import org.cactoos.func.IoCheckedFunc; import org.cactoos.text.FormattedText; +import org.cactoos.text.TextAsBytes; /** - * Jar class resource. + * Classpath resource. + * + *

Pay attention that the name of resource must always be + * global, not starting with a leading slash. Thus, + * if you want to load a text file from {@code /com/example/Test.txt}, + * you must provide this name: {@code "com/example/Test.txt"}.

* * @author Kirill (g4s8.public@gmail.com) * @version $Id$ @@ -43,6 +51,11 @@ public final class ResourceAsInput implements Input { */ private final String path; + /** + * Fallback. + */ + private final Func fallback; + /** * Resource class loader. */ @@ -50,37 +63,79 @@ public final class ResourceAsInput implements Input { /** * New resource input with current context {@link ClassLoader}. - * * @param res Resource name */ public ResourceAsInput(final String res) { + this(res, Thread.currentThread().getContextClassLoader()); + } + + /** + * New resource input with current context {@link ClassLoader}. + * @param res Resource name + * @param fbk Fallback + */ + public ResourceAsInput(final String res, final String fbk) { + this(res, input -> new BytesAsInput(new TextAsBytes(fbk))); + } + + /** + * New resource input with current context {@link ClassLoader}. + * @param res Resource name + * @param fbk Fallback + */ + public ResourceAsInput(final String res, final Input fbk) { + this(res, input -> fbk); + } + + /** + * New resource input with current context {@link ClassLoader}. + * @param res Resource name + * @param fbk Fallback + */ + public ResourceAsInput(final String res, final Func fbk) { + this(res, fbk, Thread.currentThread().getContextClassLoader()); + } + + /** + * New resource input with specified {@link ClassLoader}. + * @param res Resource name + * @param ldr Resource class loader + */ + public ResourceAsInput(final String res, final ClassLoader ldr) { this( res, - Thread.currentThread().getContextClassLoader() + input -> { + throw new IOException( + new FormattedText( + "Resource \"%s\" was not found", + input + ).asString() + ); + }, + ldr ); } /** * New resource input with specified {@link ClassLoader}. - * * @param res Resource name * @param ldr Resource class loader + * @param fbk Fallback */ - public ResourceAsInput(final String res, final ClassLoader ldr) { + public ResourceAsInput(final String res, final Func fbk, + final ClassLoader ldr) { this.path = res; this.loader = ldr; + this.fallback = fbk; } @Override public InputStream stream() throws IOException { - final InputStream input = this.loader.getResourceAsStream(this.path); + InputStream input = this.loader.getResourceAsStream(this.path); if (input == null) { - throw new IOException( - new FormattedText( - "Resource '%s' was not found", - this.path - ).asString() - ); + input = new IoCheckedFunc<>(this.fallback) + .apply(this.path) + .stream(); } return input; } diff --git a/src/main/java/org/cactoos/io/StderrOutput.java b/src/main/java/org/cactoos/io/StderrOutput.java new file mode 100644 index 0000000000..72bbfac1d8 --- /dev/null +++ b/src/main/java/org/cactoos/io/StderrOutput.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.io; + +import java.io.OutputStream; +import org.cactoos.Output; + +/** + * Output that writes to {@code stderr}. + * + *

There is no thread-safety guarantee. + * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @since 0.6 + */ +public final class StderrOutput implements Output { + + @Override + public OutputStream stream() { + return System.err; + } + +} diff --git a/src/main/java/org/cactoos/io/StdinInput.java b/src/main/java/org/cactoos/io/StdinInput.java new file mode 100644 index 0000000000..25b5d904e3 --- /dev/null +++ b/src/main/java/org/cactoos/io/StdinInput.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.io; + +import java.io.InputStream; +import org.cactoos.Input; + +/** + * Input that reads from {@code stdin}. + * + *

There is no thread-safety guarantee. + * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @since 0.6 + */ +public final class StdinInput implements Input { + + @Override + public InputStream stream() { + return System.in; + } + +} diff --git a/src/main/java/org/cactoos/io/StdoutOutput.java b/src/main/java/org/cactoos/io/StdoutOutput.java new file mode 100644 index 0000000000..9187487700 --- /dev/null +++ b/src/main/java/org/cactoos/io/StdoutOutput.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.io; + +import java.io.OutputStream; +import org.cactoos.Output; + +/** + * Output that writes to {@code stdout}. + * + *

There is no thread-safety guarantee. + * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @since 0.6 + */ +public final class StdoutOutput implements Output { + + @Override + public OutputStream stream() { + return System.out; + } + +} diff --git a/src/main/java/org/cactoos/list/IterableAsBoolean.java b/src/main/java/org/cactoos/io/StickyInput.java similarity index 56% rename from src/main/java/org/cactoos/list/IterableAsBoolean.java rename to src/main/java/org/cactoos/io/StickyInput.java index 6352b4b85b..2e77f35910 100644 --- a/src/main/java/org/cactoos/list/IterableAsBoolean.java +++ b/src/main/java/org/cactoos/io/StickyInput.java @@ -21,60 +21,54 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package org.cactoos.list; +package org.cactoos.io; -import org.cactoos.Func; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import org.cactoos.Input; import org.cactoos.Scalar; +import org.cactoos.func.IoCheckedScalar; +import org.cactoos.func.StickyScalar; /** - * Iterable into boolean. - * - *

You can use this class, for example, in order to iterate through - * a collection of items:

- * - *
 new IterableAsBoolean<>(
- *   Arrays.asList("hello", "world"),
- *   i -> System.out.println(i)
- * ).asValue();
+ * Input that reads only once. * *

There is no thread-safety guarantee. * - * @author Yegor Bugayenko (yegor256@gmail.com) + * @author Fabricio Cabral (fabriciofx@gmail.com) * @version $Id$ - * @param Type of source item - * @see IterableAsBooleans - * @since 0.1 + * @since 0.6 */ -public final class IterableAsBoolean implements Scalar { - - /** - * Iterable. - */ - private final Iterable iterable; +public final class StickyInput implements Input { /** - * Proc. + * The cache. */ - private final Func func; + private final Scalar cache; /** * Ctor. - * @param src Source iterable - * @param fnc Func + * @param input The input */ - public IterableAsBoolean(final Iterable src, - final Func fnc) { - this.iterable = src; - this.func = fnc; + public StickyInput(final Input input) { + this.cache = new StickyScalar<>( + () -> { + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + new LengthOfInput( + new TeeInput(input, new OutputStreamAsOutput(baos)) + ).asValue(); + return baos.toByteArray(); + } + ); } @Override - public Boolean asValue() { - return new AllOf( - new IterableAsBooleans<>( - this.iterable, - this.func - ) - ).asValue(); + public InputStream stream() throws IOException { + return new ByteArrayInputStream( + new IoCheckedScalar<>(this.cache).asValue() + ); } + } diff --git a/src/main/java/org/cactoos/io/TeeInput.java b/src/main/java/org/cactoos/io/TeeInput.java index 246c6d81f2..b21e2dd181 100644 --- a/src/main/java/org/cactoos/io/TeeInput.java +++ b/src/main/java/org/cactoos/io/TeeInput.java @@ -23,8 +23,10 @@ */ package org.cactoos.io; +import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.nio.file.Path; import org.cactoos.Input; import org.cactoos.Output; @@ -49,6 +51,86 @@ public final class TeeInput implements Input { */ private final Output target; + /** + * Ctor. + * @param input The source + * @param output The output file + * @since 0.5 + */ + public TeeInput(final Path input, final Path output) { + this(new PathAsInput(input), new PathAsOutput(output)); + } + + /** + * Ctor. + * @param input The source + * @param output The output file + * @since 0.5 + */ + public TeeInput(final Path input, final File output) { + this(new PathAsInput(input), new FileAsOutput(output)); + } + + /** + * Ctor. + * @param input The source + * @param output The output file + * @since 0.5 + */ + public TeeInput(final File input, final File output) { + this(new FileAsInput(input), new FileAsOutput(output)); + } + + /** + * Ctor. + * @param input The source + * @param output The output file + * @since 0.5 + */ + public TeeInput(final File input, final Path output) { + this(new FileAsInput(input), new PathAsOutput(output)); + } + + /** + * Ctor. + * @param input The source + * @param file The output file + * @since 0.5 + */ + public TeeInput(final String input, final File file) { + this(new BytesAsInput(input), new FileAsOutput(file)); + } + + /** + * Ctor. + * @param input The source + * @param file The output file + * @since 0.5 + */ + public TeeInput(final String input, final Path file) { + this(new BytesAsInput(input), new PathAsOutput(file)); + } + + /** + * Ctor. + * @param input The source + * @param file The output file + * @since 0.5 + */ + public TeeInput(final byte[] input, final Path file) { + this(new BytesAsInput(input), new PathAsOutput(file)); + } + + /** + * Ctor. + * @param input The source + * @param output The target + * @since 0.5 + */ + public TeeInput(final String input, final Output output) { + this(new BytesAsInput(input), output); + } + /** * Ctor. * @param input The source diff --git a/src/main/java/org/cactoos/io/TeeInputStream.java b/src/main/java/org/cactoos/io/TeeInputStream.java index bd31b29de9..9ea6a68425 100644 --- a/src/main/java/org/cactoos/io/TeeInputStream.java +++ b/src/main/java/org/cactoos/io/TeeInputStream.java @@ -37,14 +37,17 @@ * @since 0.1 */ public final class TeeInputStream extends InputStream { + /** * Input. */ private final InputStream input; + /** * Output. */ private final OutputStream output; + /** * Ctor. * @param src Source of data @@ -59,7 +62,9 @@ public TeeInputStream(final InputStream src, final OutputStream tgt) { @Override public int read() throws IOException { final int data = this.input.read(); - this.output.write(data); + if (data >= 0) { + this.output.write(data); + } return data; } diff --git a/src/main/java/org/cactoos/list/IterableAsBooleans.java b/src/main/java/org/cactoos/io/UncheckedBytes.java similarity index 53% rename from src/main/java/org/cactoos/list/IterableAsBooleans.java rename to src/main/java/org/cactoos/io/UncheckedBytes.java index 98c50a1c0f..ba5cf8645f 100644 --- a/src/main/java/org/cactoos/list/IterableAsBooleans.java +++ b/src/main/java/org/cactoos/io/UncheckedBytes.java @@ -21,63 +21,69 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package org.cactoos.list; +package org.cactoos.io; -import java.util.Iterator; +import java.io.IOException; +import java.io.UncheckedIOException; +import org.cactoos.Bytes; import org.cactoos.Func; +import org.cactoos.func.UncheckedFunc; /** - * Iterable into booleans. - * - *

You can use this class, for example, in order to iterate through - * a collection of items, in combination with {@link AllOf}:

- * - *
 new AllOf(
- *   new IterableAsBooleans<String>(
- *     Arrays.asList("hello", "world"),
- *     i -> System.out.println(i)
- *   )
- * ).asValue();
- * - *

Also, consider a much shorter version with {@link IterableAsBoolean}.

+ * Bytes that doesn't throw checked {@link Exception}. * *

There is no thread-safety guarantee. * - * @author Yegor Bugayenko (yegor256@gmail.com) + * @author Fabricio Cabral (fabriciofx@gmail.com) * @version $Id$ - * @param Type of source item - * @see IterableAsBoolean - * @since 0.1 + * @since 0.3 */ -public final class IterableAsBooleans implements Iterable { +public final class UncheckedBytes implements Bytes { + + /** + * Original bytes. + */ + private final Bytes bytes; /** - * Iterable. + * Fallback. */ - private final Iterable iterable; + private final Func fallback; /** - * Func. + * Ctor. + * @param bts Encapsulated bytes */ - private final Func func; + public UncheckedBytes(final Bytes bts) { + this( + bts, + error -> { + throw new UncheckedIOException(error); + } + ); + } /** * Ctor. - * @param src Source iterable - * @param fnc Func + * @param bts Encapsulated bytes + * @param fbk Fallback + * @since 0.5 */ - public IterableAsBooleans(final Iterable src, - final Func fnc) { - this.iterable = src; - this.func = fnc; + public UncheckedBytes(final Bytes bts, + final Func fbk) { + this.bytes = bts; + this.fallback = fbk; } @Override - public Iterator iterator() { - return new TransformedIterator<>( - this.iterable.iterator(), - this.func - ); + public byte[] asBytes() { + byte[] data; + try { + data = this.bytes.asBytes(); + } catch (final IOException ex) { + data = new UncheckedFunc<>(this.fallback).apply(ex); + } + return data; } } diff --git a/src/main/java/org/cactoos/io/UncheckedInput.java b/src/main/java/org/cactoos/io/UncheckedInput.java new file mode 100644 index 0000000000..afea5f1aec --- /dev/null +++ b/src/main/java/org/cactoos/io/UncheckedInput.java @@ -0,0 +1,59 @@ +/** + * 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.io; + +import java.io.InputStream; +import org.cactoos.Input; +import org.cactoos.func.UncheckedScalar; + +/** + * Input that doesn't throw checked {@link Exception}. + * + *

There is no thread-safety guarantee. + * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @since 0.9 + */ +public final class UncheckedInput implements Input { + + /** + * Original input. + */ + private final Input input; + + /** + * Ctor. + * @param ipt Input + */ + public UncheckedInput(final Input ipt) { + this.input = ipt; + } + + @Override + public InputStream stream() { + return new UncheckedScalar<>(this.input::stream).asValue(); + } + +} diff --git a/src/main/java/org/cactoos/io/UncheckedOutput.java b/src/main/java/org/cactoos/io/UncheckedOutput.java new file mode 100644 index 0000000000..f229810780 --- /dev/null +++ b/src/main/java/org/cactoos/io/UncheckedOutput.java @@ -0,0 +1,59 @@ +/** + * 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.io; + +import java.io.OutputStream; +import org.cactoos.Output; +import org.cactoos.func.UncheckedScalar; + +/** + * Input that doesn't throw checked {@link Exception}. + * + *

There is no thread-safety guarantee. + * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @since 0.9 + */ +public final class UncheckedOutput implements Output { + + /** + * Original output. + */ + private final Output output; + + /** + * Ctor. + * @param opt Output + */ + public UncheckedOutput(final Output opt) { + this.output = opt; + } + + @Override + public OutputStream stream() { + return new UncheckedScalar<>(this.output::stream).asValue(); + } + +} diff --git a/src/main/java/org/cactoos/io/UrlAsInput.java b/src/main/java/org/cactoos/io/UrlAsInput.java index 6fc8588aeb..02238ea027 100644 --- a/src/main/java/org/cactoos/io/UrlAsInput.java +++ b/src/main/java/org/cactoos/io/UrlAsInput.java @@ -25,8 +25,11 @@ import java.io.IOException; import java.io.InputStream; +import java.net.URI; import java.net.URL; import org.cactoos.Input; +import org.cactoos.Scalar; +import org.cactoos.func.IoCheckedScalar; /** * URL as Input. @@ -42,19 +45,45 @@ public final class UrlAsInput implements Input { /** * The URL. */ - private final URL source; + private final Scalar source; + + /** + * Ctor. + * @param url The URL + * @since 0.6 + */ + public UrlAsInput(final String url) { + this(() -> new URL(url)); + } + + /** + * Ctor. + * @param url The URL + * @since 0.6 + */ + public UrlAsInput(final URI url) { + this(url::toURL); + } /** * Ctor. * @param url The URL */ public UrlAsInput(final URL url) { - this.source = url; + this(() -> url); + } + + /** + * Ctor. + * @param src Source + */ + public UrlAsInput(final Scalar src) { + this.source = src; } @Override public InputStream stream() throws IOException { - return this.source.openStream(); + return new IoCheckedScalar<>(this.source).asValue().openStream(); } } diff --git a/src/main/java/org/cactoos/list/AllOf.java b/src/main/java/org/cactoos/list/AllOf.java deleted file mode 100644 index 7819887b8d..0000000000 --- a/src/main/java/org/cactoos/list/AllOf.java +++ /dev/null @@ -1,92 +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.list; - -import org.cactoos.Scalar; - -/** - * Is {@code true} when all items in the collection are {@code true}. - * - *

You can use this class in order to iterate all items - * in the collection. This is very similar to the {@code forEach()} - * in steams, but more object oriented. For example, if you want - * to print all items from the array:

- * - *
 new AllOf(
- *   new TransformedIterable<String>(
- *     Arrays.asList("hello", "world"),
- *     new ProcAsFunc<>(i -> System.out.println(i))
- *   )
- * ).asValue();
- * - *

Or even more compact, through {@link IterableAsBooleans}:

- * - *
 new AllOf(
- *   new IterableAsBooleans<String>(
- *     Arrays.asList("hello", "world"),
- *     i -> System.out.println(i)
- *   )
- * ).asValue();
- * - *

Or you can even use {@link IterableAsBoolean}:

- * - *
 new IterableAsBoolean<String>(
- *   Arrays.asList("hello", "world"),
- *   i -> System.out.println(i)
- * ).asValue();
- * - *

There is no thread-safety guarantee. - * - * @author Yegor Bugayenko (yegor256@gmail.com) - * @version $Id$ - * @since 0.1 - */ -public final class AllOf implements Scalar { - - /** - * Iterable. - */ - private final Iterable iterable; - - /** - * Ctor. - * @param src Source iterable - */ - public AllOf(final Iterable src) { - this.iterable = src; - } - - @Override - public Boolean asValue() { - boolean success = true; - for (final Boolean item : this.iterable) { - if (!item) { - success = false; - break; - } - } - return success; - } - -} diff --git a/src/main/java/org/cactoos/list/ArrayAsIterable.java b/src/main/java/org/cactoos/list/ArrayAsIterable.java index 5ceb323499..adfad62b9c 100644 --- a/src/main/java/org/cactoos/list/ArrayAsIterable.java +++ b/src/main/java/org/cactoos/list/ArrayAsIterable.java @@ -48,7 +48,6 @@ public final class ArrayAsIterable implements Iterable { * @param items The array */ @SafeVarargs - @SuppressWarnings("varargs") public ArrayAsIterable(final X... items) { this.array = items; } diff --git a/src/main/java/org/cactoos/list/ConcatenatedIterable.java b/src/main/java/org/cactoos/list/ConcatIterable.java similarity index 83% rename from src/main/java/org/cactoos/list/ConcatenatedIterable.java rename to src/main/java/org/cactoos/list/ConcatIterable.java index b2b2c89879..606be04b31 100644 --- a/src/main/java/org/cactoos/list/ConcatenatedIterable.java +++ b/src/main/java/org/cactoos/list/ConcatIterable.java @@ -23,7 +23,6 @@ */ package org.cactoos.list; -import java.util.Arrays; import java.util.Iterator; import org.cactoos.func.StickyFunc; @@ -37,7 +36,7 @@ * @param Type of item * @since 0.1 */ -public final class ConcatenatedIterable implements Iterable { +public final class ConcatIterable implements Iterable { /** * Iterables. @@ -49,23 +48,22 @@ public final class ConcatenatedIterable implements Iterable { * @param items Items to concatenate */ @SafeVarargs - @SuppressWarnings("varargs") - public ConcatenatedIterable(final Iterable... items) { - this(Arrays.asList(items)); + public ConcatIterable(final Iterable... items) { + this(new IterableAsList<>(items)); } /** * Ctor. * @param items Items to concatenate */ - public ConcatenatedIterable(final Iterable> items) { + public ConcatIterable(final Iterable> items) { this.list = items; } @Override public Iterator iterator() { - return new ConcatenatedIterator<>( - new TransformedIterable<>( + return new ConcatIterator<>( + new MappedIterable<>( this.list, new StickyFunc<>(Iterable::iterator) ) diff --git a/src/main/java/org/cactoos/list/ConcatenatedIterator.java b/src/main/java/org/cactoos/list/ConcatIterator.java similarity index 87% rename from src/main/java/org/cactoos/list/ConcatenatedIterator.java rename to src/main/java/org/cactoos/list/ConcatIterator.java index a9c138b9d6..49a7eef18d 100644 --- a/src/main/java/org/cactoos/list/ConcatenatedIterator.java +++ b/src/main/java/org/cactoos/list/ConcatIterator.java @@ -23,7 +23,6 @@ */ package org.cactoos.list; -import java.util.Arrays; import java.util.Iterator; /** @@ -36,7 +35,7 @@ * @param Type of item * @since 0.1 */ -public final class ConcatenatedIterator implements Iterator { +public final class ConcatIterator implements Iterator { /** * Iterables. @@ -48,16 +47,15 @@ public final class ConcatenatedIterator implements Iterator { * @param items Items to concatenate */ @SafeVarargs - @SuppressWarnings("varargs") - public ConcatenatedIterator(final Iterator... items) { - this(Arrays.asList(items)); + public ConcatIterator(final Iterator... items) { + this(new IterableAsList<>(items)); } /** * Ctor. * @param items Items to concatenate */ - public ConcatenatedIterator(final Iterable> items) { + public ConcatIterator(final Iterable> items) { this.list = items; } diff --git a/src/main/java/org/cactoos/list/FirstOf.java b/src/main/java/org/cactoos/list/CycledIterable.java similarity index 67% rename from src/main/java/org/cactoos/list/FirstOf.java rename to src/main/java/org/cactoos/list/CycledIterable.java index 597a9048f8..ede1f74621 100644 --- a/src/main/java/org/cactoos/list/FirstOf.java +++ b/src/main/java/org/cactoos/list/CycledIterable.java @@ -21,42 +21,38 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ + package org.cactoos.list; -import java.io.IOException; import java.util.Iterator; -import org.cactoos.Scalar; /** - * First element in {@link Iterable}. + * Cycled Iterable. + * + *

There is no thread-safety guarantee. * - * @author Kirill (g4s8.public@gmail.com) + * @author Ilia Rogozhin (ilia.rogozhin@gmail.com) * @version $Id$ - * @param Scalar type - * @since 0.1 + * @param Type of item + * @since 0.8 */ -public final class FirstOf implements Scalar { +public final class CycledIterable implements Iterable { /** - * Source iterable. + * Iterable. */ - private final Iterable source; + private final Iterable iterable; /** * Ctor. - * - * @param source Iterable + * @param iterable Iterable */ - public FirstOf(final Iterable source) { - this.source = source; + public CycledIterable(final Iterable iterable) { + this.iterable = iterable; } @Override - public T asValue() throws IOException { - final Iterator iterator = this.source.iterator(); - if (!iterator.hasNext()) { - throw new IOException("Iterable is empty"); - } - return iterator.next(); + public Iterator iterator() { + return new CycledIterator<>(this.iterable); } } diff --git a/src/main/java/org/cactoos/list/CycledIterator.java b/src/main/java/org/cactoos/list/CycledIterator.java new file mode 100644 index 0000000000..81580bb528 --- /dev/null +++ b/src/main/java/org/cactoos/list/CycledIterator.java @@ -0,0 +1,75 @@ +/** + * 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.list; + +import java.util.Iterator; +import java.util.NoSuchElementException; + +/** + * Cycled Iterator. + * + *

There is no thread-safety guarantee. + * + * @author Ilia Rogozhin (ilia.rogozhin@gmail.com) + * @version $Id$ + * @param Type of item + * @since 0.8 + */ +public final class CycledIterator implements Iterator { + + /** + * Iterable. + */ + private final Iterable iterable; + + /** + * Iterator. + */ + private Iterator iterator; + + /** + * Ctor. + * @param iterable Iterable. + */ + public CycledIterator(final Iterable iterable) { + this.iterable = iterable; + } + + @Override + public boolean hasNext() { + if (this.iterator == null || !this.iterator.hasNext()) { + this.iterator = this.iterable.iterator(); + } + return this.iterator.hasNext(); + } + + @Override + public T next() { + if (!this.hasNext()) { + throw new NoSuchElementException(); + } + return this.iterator.next(); + } +} diff --git a/src/main/java/org/cactoos/list/EndlessIterable.java b/src/main/java/org/cactoos/list/EndlessIterable.java new file mode 100644 index 0000000000..bc1a1172db --- /dev/null +++ b/src/main/java/org/cactoos/list/EndlessIterable.java @@ -0,0 +1,59 @@ +/** + * 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.list; + +import java.util.Iterator; + +/** + * Endless iterable. + * + *

If you need to repeat certain amount of time, + * use {@link RepeatIterable}.

+ * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @param Element type + * @since 0.4 + */ +public final class EndlessIterable implements Iterable { + + /** + * Element to repeat. + */ + private final T element; + + /** + * Ctor. + * @param elm To repeat + */ + public EndlessIterable(final T elm) { + this.element = elm; + } + + @Override + public Iterator iterator() { + return new EndlessIterator<>(this.element); + } + +} diff --git a/src/main/java/org/cactoos/list/EndlessIterator.java b/src/main/java/org/cactoos/list/EndlessIterator.java new file mode 100644 index 0000000000..aef99db174 --- /dev/null +++ b/src/main/java/org/cactoos/list/EndlessIterator.java @@ -0,0 +1,81 @@ +/** + * 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.list; + +import java.util.Iterator; +import org.cactoos.Scalar; +import org.cactoos.func.UncheckedScalar; + +/** + * Iterator that never ends. + * + *

If you need to repeat certain amount of time, + * use {@link RepeatIterator}.

+ * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @param Element type + * @since 0.4 + */ +public final class EndlessIterator implements Iterator { + + /** + * The element to repeat. + */ + private final UncheckedScalar element; + + /** + * Ctor. + * @param elm Element to repeat + */ + public EndlessIterator(final T elm) { + this(() -> elm); + } + + /** + * Ctor. + * @param elm Element to repeat + */ + public EndlessIterator(final Scalar elm) { + this(new UncheckedScalar<>(elm)); + } + + /** + * Ctor. + * @param elm Element to repeat + */ + public EndlessIterator(final UncheckedScalar elm) { + this.element = elm; + } + + @Override + public boolean hasNext() { + return true; + } + + @Override + public T next() { + return this.element.asValue(); + } +} diff --git a/src/main/java/org/cactoos/list/FilteredIterator.java b/src/main/java/org/cactoos/list/FilteredIterator.java index a4c7739eee..0cc335b18a 100644 --- a/src/main/java/org/cactoos/list/FilteredIterator.java +++ b/src/main/java/org/cactoos/list/FilteredIterator.java @@ -100,7 +100,7 @@ public boolean hasNext() { public X next() { if (!this.hasNext()) { throw new NoSuchElementException( - "No more elements with fits the condition." + "No more elements that fit the condition" ); } return this.buffer.poll(); @@ -108,7 +108,9 @@ public X next() { @Override public void remove() { - this.iterator.remove(); + throw new UnsupportedOperationException( + "#remove() is not supported" + ); } } diff --git a/src/main/java/org/cactoos/list/ItemOfIterable.java b/src/main/java/org/cactoos/list/ItemOfIterable.java new file mode 100644 index 0000000000..0a7b5d29d5 --- /dev/null +++ b/src/main/java/org/cactoos/list/ItemOfIterable.java @@ -0,0 +1,146 @@ +/** + * 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.list; + +import java.io.IOException; +import org.cactoos.Func; +import org.cactoos.Scalar; +import org.cactoos.text.FormattedText; + +/** + * Element from position in {@link Iterable} + * or fallback value if iterable hasn't this position. + * + *

There is no thread-safety guarantee. + * + * @author Kirill (g4s8.public@gmail.com) + * @version $Id$ + * @param Scalar type + * @since 0.7 + */ +public final class ItemOfIterable implements Scalar { + + /** + * Source iterable. + */ + private final Iterable src; + + /** + * Fallback value. + */ + private final Func, T> fbk; + + /** + * Position. + */ + private final int pos; + + /** + * Ctor. + * + * @param src Iterable + */ + public ItemOfIterable(final Iterable src) { + this( + src, + itr -> { + throw new IOException( + new FormattedText("Iterable %s is empty", itr) + .asString() + ); + } + ); + } + + /** + * Ctor. + * + * @param src Iterable + * @param fbk Fallback value + */ + public ItemOfIterable(final Iterable src, final T fbk) { + this(src, itr -> fbk); + } + + /** + * Ctor. + * + * @param src Iterable + * @param fbk Fallback value + */ + public ItemOfIterable( + final Iterable src, + final Func, T> fbk + ) { + this(src, 0, fbk); + } + + /** + * Ctor. + * + * @param src Iterable + * @param pos Position + */ + public ItemOfIterable(final Iterable src, final int pos) { + this( + src, + pos, + itr -> { + throw new IOException( + new FormattedText( + "Iterable %s doesn't have element at position #%d", + itr, + pos + ).asString() + ); + } + ); + } + + /** + * Ctor. + * + * @param src Iterable + * @param pos Position + * @param fbk Fallback value + */ + public ItemOfIterable( + final Iterable src, + final int pos, + final Func, T> fbk + ) { + this.pos = pos; + this.src = src; + this.fbk = fbk; + } + + @Override + public T asValue() throws Exception { + return new ItemOfIterator<>( + this.src.iterator(), + this.pos, + this.fbk + ).asValue(); + } +} diff --git a/src/main/java/org/cactoos/list/ItemOfIterator.java b/src/main/java/org/cactoos/list/ItemOfIterator.java new file mode 100644 index 0000000000..99166ce0a5 --- /dev/null +++ b/src/main/java/org/cactoos/list/ItemOfIterator.java @@ -0,0 +1,157 @@ +/** + * 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.list; + +import java.io.IOException; +import java.util.Iterator; +import org.cactoos.Func; +import org.cactoos.Scalar; +import org.cactoos.text.FormattedText; + +/** + * Element from position in {@link Iterator} + * or fallback value if iterator hasn't this position. + * + *

There is no thread-safety guarantee. + * + * @author Ilia Rogozhin (ilia.rogozhin@gmail.com) + * @version $Id$ + * @param Scalar type + * @since 0.7 + */ +public final class ItemOfIterator implements Scalar { + + /** + * Source iterator. + */ + private final Iterator src; + + /** + * Fallback value. + */ + private final Func, T> fbk; + + /** + * Position. + */ + private final int pos; + + /** + * Ctor. + * + * @param src Iterator + */ + public ItemOfIterator(final Iterator src) { + this( + src, + itr -> { + throw new IOException("Iterator is empty"); + } + ); + } + + /** + * Ctor. + * + * @param src Iterator + * @param fbk Fallback value + */ + public ItemOfIterator(final Iterator src, final T fbk) { + this(src, itr -> fbk); + } + + /** + * Ctor. + * + * @param src Iterator + * @param fbk Fallback value + */ + public ItemOfIterator( + final Iterator src, + final Func, T> fbk + ) { + this(src, 0, fbk); + } + + /** + * Ctor. + * + * @param src Iterator + * @param pos Position + */ + public ItemOfIterator(final Iterator src, final int pos) { + this( + src, + pos, + itr -> { + throw new IOException( + new FormattedText( + "Iterator doesn't have an element at #%d position", + pos + ).asString() + ); + } + ); + } + + /** + * Ctor. + * + * @param src Iterator + * @param pos Position + * @param fbk Fallback value + */ + public ItemOfIterator( + final Iterator src, + final int pos, + final Func, T> fbk + ) { + this.pos = pos; + this.src = src; + this.fbk = fbk; + } + + @Override + public T asValue() throws Exception { + if (this.pos < 0) { + throw new IOException( + new FormattedText( + "The position must be non-negative: %d", + this.pos + ).asString() + ); + } + final T ret; + int cur; + for (cur = 0; cur < this.pos && this.src.hasNext(); ++cur) { + this.src.next(); + } + if (cur == this.pos && this.src.hasNext()) { + ret = this.src.next(); + } else { + ret = this.fbk.apply(() -> this.src); + } + return ret; + } +} diff --git a/src/main/java/org/cactoos/list/IterableAsList.java b/src/main/java/org/cactoos/list/IterableAsList.java index 7e0d850c6d..6928da5621 100644 --- a/src/main/java/org/cactoos/list/IterableAsList.java +++ b/src/main/java/org/cactoos/list/IterableAsList.java @@ -23,86 +23,206 @@ */ package org.cactoos.list; -import java.util.AbstractList; -import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.LinkedList; import java.util.List; -import org.cactoos.text.FormattedText; +import java.util.ListIterator; /** * Iterable as {@link List}. * + *

This class should be used very carefully. You must understand that + * it will fetch the entire content of the encapsulated {@link List} on each + * method call. It doesn't cache the data anyhow.

+ * + *

If you don't need this {@link List} to re-fresh its content on every call, + * by doing round-trips to the encapsulated iterable, use + * {@link StickyList}.

+ * *

There is no thread-safety guarantee. * + * @author Alexey Semenyuk (semenyukalexey88@gmail.com) * @author Kirill (g4s8.public@gmail.com) + * @author Yegor Bugayenko (yegor256@gmail.com) * @version $Id$ * @param List type + * @see StickyList * @since 0.1 */ -public final class IterableAsList extends AbstractList { - - /** - * Iterable source. - */ - private final Iterable source; +@SuppressWarnings("PMD.TooManyMethods") +public final class IterableAsList implements List { /** - * Cache for source. + * The source. */ - private final List cache; + private final Iterable iterable; /** - * Iterable length. + * Ctor. * - * @todo #39:30m Needs cached `LengthOfIterable` version - * to improve `IterableAsList` performance. Now each call - * to `size()` goes through all iterable to calculate the size. + * @param array An array of some elements */ - private final LengthOfIterable length; + @SafeVarargs + public IterableAsList(final T... array) { + this(new ArrayAsIterable<>(array)); + } /** * Ctor. * - * @param iterable An {@link Iterable} + * @param src An {@link Iterable} */ - public IterableAsList(final Iterable iterable) { - super(); - this.source = iterable; - this.cache = new ArrayList<>(0); - this.length = new LengthOfIterable(iterable); + public IterableAsList(final Iterable src) { + this.iterable = src; + } + + @Override + public int size() { + return new LengthOfIterable(this.iterable).asValue(); + } + + @Override + public boolean isEmpty() { + return !this.iterable.iterator().hasNext(); + } + + @Override + public boolean contains(final Object object) { + return this.list().contains(object); + } + + @Override + public Iterator iterator() { + return this.iterable.iterator(); + } + + @Override + public Object[] toArray() { + return this.list().toArray(); + } + + @Override + @SuppressWarnings("PMD.UseVarargs") + public Y[] toArray(final Y[] array) { + return this.list().toArray(array); + } + + @Override + public boolean add(final T element) { + throw new UnsupportedOperationException( + "#add(final T element) is not supported" + ); + } + + @Override + public boolean remove(final Object object) { + throw new UnsupportedOperationException( + "#remove(final Object object) is not supported" + ); + } + + @Override + public boolean containsAll(final Collection collection) { + return this.list().containsAll(collection); + } + + @Override + public boolean addAll(final Collection collection) { + throw new UnsupportedOperationException( + "#addAll(final Collection collection) is not supported" + ); + } + + @Override + public boolean addAll(final int index, + final Collection collection) { + throw new UnsupportedOperationException( + "#addAll() is not supported" + ); + } + + @Override + public boolean removeAll(final Collection collection) { + throw new UnsupportedOperationException( + "#removeAll(final Collection collection) is not supported" + ); + } + + @Override + public boolean retainAll(final Collection collection) { + throw new UnsupportedOperationException( + "#retainAll(final Collection collection) is not supported" + ); + } + + @Override + public void clear() { + throw new UnsupportedOperationException( + "#clear() is not supported" + ); } @Override public T get(final int index) { - if (index < 0 || index >= this.size()) { - throw new IndexOutOfBoundsException( - new FormattedText( - "index=%d, bounds=[%d; %d]", - index, - 0, - this.size() - ).asString() - ); - } - return this.cachedItem(index); + return this.list().get(index); } @Override - public int size() { - return this.length.asValue(); + public T set(final int index, final T element) { + throw new UnsupportedOperationException( + "#set() is not supported" + ); + } + + @Override + public void add(final int index, final T element) { + throw new UnsupportedOperationException( + "#add(final int index, final T element) is not supported" + ); + } + + @Override + public T remove(final int index) { + throw new UnsupportedOperationException( + "#remove(final int index) is not supported" + ); + } + + @Override + public int indexOf(final Object object) { + return this.list().indexOf(object); + } + + @Override + public int lastIndexOf(final Object object) { + return this.list().lastIndexOf(object); + } + + @Override + public ListIterator listIterator() { + return this.list().listIterator(); + } + + @Override + public ListIterator listIterator(final int index) { + return this.list().listIterator(index); + } + + @Override + public List subList(final int fromindex, final int toindex) { + return this.list().subList(fromindex, toindex); } /** - * Find item in cache by index. - * - * @param index Item index - * @return Cached item + * Build a list. + * @return List */ - private T cachedItem(final int index) { - if (this.cache.size() != this.size()) { - for (final T item : this.source) { - this.cache.add(item); - } + private List list() { + final List list = new LinkedList<>(); + for (final T item : this.iterable) { + list.add(item); } - return this.cache.get(index); + return list; } } diff --git a/src/main/java/org/cactoos/list/IterableAsMap.java b/src/main/java/org/cactoos/list/IterableAsMap.java new file mode 100644 index 0000000000..f36724c0b0 --- /dev/null +++ b/src/main/java/org/cactoos/list/IterableAsMap.java @@ -0,0 +1,156 @@ +/** + * 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.list; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +/** + * Iterable as {@link Map}. + * + *

This class should be used very carefully. You must understand that + * it will fetch the entire content of the encapsulated {@link Map} on each + * method call. It doesn't cache the data anyhow.

+ * + *

If you don't need this {@link Map} to re-fresh its content on every call, + * by doing round-trips to the encapsulated iterable, use + * {@link StickyMap}.

+ * + *

There is no thread-safety guarantee. + * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @param Type of key + * @param Type of value + * @see StickyMap + * @since 0.4 + */ +@SuppressWarnings("PMD.TooManyMethods") +public final class IterableAsMap implements Map { + + /** + * The iterable. + */ + private final Iterable> entries; + + /** + * Ctor. + * @param list List of entries + */ + @SafeVarargs + public IterableAsMap(final Map.Entry... list) { + this(new ArrayAsIterable<>(list)); + } + + /** + * Ctor. + * @param list Entries for the entries + */ + public IterableAsMap(final Iterable> list) { + this.entries = list; + } + + @Override + public int size() { + return new LengthOfIterable(this.entries).asValue(); + } + + @Override + public boolean isEmpty() { + return !this.entries.iterator().hasNext(); + } + + @Override + public boolean containsKey(final Object key) { + return this.map().containsKey(key); + } + + @Override + public boolean containsValue(final Object value) { + return this.map().containsValue(value); + } + + @Override + public Y get(final Object key) { + return this.map().get(key); + } + + @Override + public Y put(final X key, final Y value) { + throw new UnsupportedOperationException( + "#put() is not supported" + ); + } + + @Override + public Y remove(final Object key) { + throw new UnsupportedOperationException( + "#remove() is not supported" + ); + } + + @Override + public void putAll(final Map list) { + throw new UnsupportedOperationException( + "#putAll() is not supported" + ); + } + + @Override + public void clear() { + throw new UnsupportedOperationException( + "#clear() is not supported" + ); + } + + @Override + public Set keySet() { + return this.map().keySet(); + } + + @Override + public Collection values() { + return this.map().values(); + } + + @Override + public Set> entrySet() { + return this.map().entrySet(); + } + + /** + * Make a map. + * @return Map + */ + private Map map() { + final Map temp = new HashMap<>(0); + for (final Map.Entry entry : this.entries) { + temp.put(entry.getKey(), entry.getValue()); + } + return temp; + } + +} diff --git a/src/main/java/org/cactoos/list/LimitedIterable.java b/src/main/java/org/cactoos/list/LimitedIterable.java new file mode 100644 index 0000000000..364936929d --- /dev/null +++ b/src/main/java/org/cactoos/list/LimitedIterable.java @@ -0,0 +1,68 @@ +/** + * 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.list; + +import java.util.Iterator; + +/** + * Limited iterable. + * + *

This is a view of an existing iterable containing the given number of its + * first elements.

+ * + *

There is no thread-safety guarantee.

+ * + * @author Dusan Rychnovsky (dusan.rychnovsky@gmail.com) + * @version $Id$ + * @param Element type + * @since 0.6 + */ +public final class LimitedIterable implements Iterable { + + /** + * Decorated iterable. + */ + private final Iterable iterable; + + /** + * Number of elements to return. + */ + private final int limit; + + /** + * Ctor. + * + * @param iterable The underlying iterable + * @param limit The requested number of elements + */ + public LimitedIterable(final Iterable iterable, final int limit) { + this.iterable = iterable; + this.limit = limit; + } + + @Override + public Iterator iterator() { + return new LimitedIterator<>(this.iterable.iterator(), this.limit); + } +} diff --git a/src/main/java/org/cactoos/list/LimitedIterator.java b/src/main/java/org/cactoos/list/LimitedIterator.java new file mode 100644 index 0000000000..45c96ef11b --- /dev/null +++ b/src/main/java/org/cactoos/list/LimitedIterator.java @@ -0,0 +1,85 @@ +/** + * 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.list; + +import java.util.Iterator; +import java.util.NoSuchElementException; + +/** + * Limited iterator. + * + *

This is a decorator over an existing iterator. Returns elements of the + * original iterator, until either the requested number of items have been + * returned or the underlying iterator has been exhausted.

+ * + *

There is no thread-safety guarantee.

+ * + * @author Dusan Rychnovsky (dusan.rychnovsky@gmail.com) + * @version $Id$ + * @param Element type + * @since 0.6 + */ +public final class LimitedIterator implements Iterator { + + /** + * Decorated iterator. + */ + private final Iterator iterator; + + /** + * Number of elements to return. + */ + private final int limit; + + /** + * Number of elements returned so far. + */ + private int consumed; + + /** + * Ctor. + * + * @param iterator The underlying iterator + * @param limit The requested number of elements + */ + public LimitedIterator(final Iterator iterator, final int limit) { + this.iterator = iterator; + this.limit = limit; + this.consumed = 0; + } + + @Override + public boolean hasNext() { + return this.consumed < this.limit && this.iterator.hasNext(); + } + + @Override + public T next() { + if (!this.hasNext()) { + throw new NoSuchElementException("No more elements."); + } + ++this.consumed; + return this.iterator.next(); + } +} diff --git a/src/main/java/org/cactoos/list/MapAsProperties.java b/src/main/java/org/cactoos/list/MapAsProperties.java new file mode 100644 index 0000000000..d70723b306 --- /dev/null +++ b/src/main/java/org/cactoos/list/MapAsProperties.java @@ -0,0 +1,83 @@ +/** + * 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.list; + +import java.util.AbstractMap; +import java.util.Map; +import java.util.Properties; +import org.cactoos.Scalar; + +/** + * Map as {@link java.util.Properties}. + * + *

There is no thread-safety guarantee. + * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @since 0.7 + */ +public final class MapAsProperties implements Scalar { + + /** + * The map. + */ + private final Map map; + + /** + * Ctor. + * @param entries The map with properties + */ + public MapAsProperties(final Map.Entry... entries) { + this( + new IterableAsMap<>( + new MappedIterable, Map.Entry>( + new ArrayAsIterable<>(entries), + input -> new AbstractMap.SimpleEntry<>( + input.getKey().toString(), input.getValue().toString() + ) + ) + ) + ); + } + + /** + * Ctor. + * @param src The map with properties + */ + public MapAsProperties(final Map src) { + this.map = src; + } + + @Override + public Properties asValue() { + final Properties props = new Properties(); + for (final Map.Entry entry : this.map.entrySet()) { + props.setProperty( + entry.getKey().toString(), + entry.getValue().toString() + ); + } + return props; + } +} diff --git a/src/main/java/org/cactoos/list/TransformedIterable.java b/src/main/java/org/cactoos/list/MappedIterable.java similarity index 89% rename from src/main/java/org/cactoos/list/TransformedIterable.java rename to src/main/java/org/cactoos/list/MappedIterable.java index 7c0b7cdbe4..a80bfe5652 100644 --- a/src/main/java/org/cactoos/list/TransformedIterable.java +++ b/src/main/java/org/cactoos/list/MappedIterable.java @@ -27,7 +27,7 @@ import org.cactoos.Func; /** - * Transformed iterable. + * Mapped iterable. * *

There is no thread-safety guarantee. * @@ -37,7 +37,7 @@ * @param Type of target item * @since 0.1 */ -public final class TransformedIterable implements Iterable { +public final class MappedIterable implements Iterable { /** * Iterable. @@ -54,14 +54,14 @@ public final class TransformedIterable implements Iterable { * @param src Source iterable * @param fnc Func */ - public TransformedIterable(final Iterable src, final Func fnc) { + public MappedIterable(final Iterable src, final Func fnc) { this.iterable = src; this.func = fnc; } @Override public Iterator iterator() { - return new TransformedIterator<>( + return new MappedIterator<>( this.iterable.iterator(), this.func ); } diff --git a/src/main/java/org/cactoos/list/TransformedIterator.java b/src/main/java/org/cactoos/list/MappedIterator.java similarity index 89% rename from src/main/java/org/cactoos/list/TransformedIterator.java rename to src/main/java/org/cactoos/list/MappedIterator.java index fe3424e550..41125ec778 100644 --- a/src/main/java/org/cactoos/list/TransformedIterator.java +++ b/src/main/java/org/cactoos/list/MappedIterator.java @@ -28,7 +28,7 @@ import org.cactoos.func.UncheckedFunc; /** - * Transformed iterator. + * Mapped iterator. * *

There is no thread-safety guarantee. * @@ -38,7 +38,7 @@ * @param Type of target item * @since 0.1 */ -public final class TransformedIterator implements Iterator { +public final class MappedIterator implements Iterator { /** * Iterator. @@ -55,7 +55,7 @@ public final class TransformedIterator implements Iterator { * @param src Source iterable * @param fnc Func */ - public TransformedIterator(final Iterator src, final Func fnc) { + public MappedIterator(final Iterator src, final Func fnc) { this.iterator = src; this.func = fnc; } @@ -66,7 +66,6 @@ public boolean hasNext() { } @Override - @SuppressWarnings("PMD.AvoidCatchingGenericException") public Y next() { return new UncheckedFunc<>(this.func).apply(this.iterator.next()); } diff --git a/src/main/java/org/cactoos/list/NaturalNumbers.java b/src/main/java/org/cactoos/list/NaturalNumbers.java new file mode 100644 index 0000000000..6466e70585 --- /dev/null +++ b/src/main/java/org/cactoos/list/NaturalNumbers.java @@ -0,0 +1,42 @@ +/** + * 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.list; + +import java.util.Iterator; +import java.util.stream.LongStream; + +/** + * Iterable providing Natural Numbers. + * + * @author Tim Hinkes (timmeey@timmeey.de) + * @version $Id$ + * @since 0.7 + */ +public final class NaturalNumbers implements Iterable { + + @Override + public Iterator iterator() { + return LongStream.range(0, Long.MAX_VALUE).iterator(); + } +} diff --git a/src/main/java/org/cactoos/list/Repeat.java b/src/main/java/org/cactoos/list/RepeatIterable.java similarity index 63% rename from src/main/java/org/cactoos/list/Repeat.java rename to src/main/java/org/cactoos/list/RepeatIterable.java index 4249660c92..54ec35e22b 100644 --- a/src/main/java/org/cactoos/list/Repeat.java +++ b/src/main/java/org/cactoos/list/RepeatIterable.java @@ -24,21 +24,26 @@ package org.cactoos.list; import java.util.Iterator; +import org.cactoos.Scalar; +import org.cactoos.func.UncheckedScalar; /** * Repeat an element. * + *

If you need to repeat endlessly, use {@link EndlessIterable}.

+ * * @author Kirill (g4s8.public@gmail.com) + * @author Yegor Bugayenko (yegor256@gmail.com) * @version $Id$ * @param Element type * @since 0.1 */ -public final class Repeat implements Iterable { +public final class RepeatIterable implements Iterable { /** * Element to repeat. */ - private final T element; + private final UncheckedScalar element; /** * Repeat count. @@ -47,39 +52,35 @@ public final class Repeat implements Iterable { /** * Ctor. - * - * @param element To repeat - * @param count Count + * @param elm To repeat + * @param cnt Count */ - public Repeat(final T element, final int count) { - this.element = element; - this.count = count; + public RepeatIterable(final T elm, final int cnt) { + this(() -> elm, cnt); } - @Override - public Iterator iterator() { - return new RepeatIterator(); + /** + * Ctor. + * @param elm To repeat + * @param cnt Count + */ + public RepeatIterable(final Scalar elm, final int cnt) { + this(new UncheckedScalar(elm), cnt); } /** - * An iterator. + * Ctor. + * @param elm To repeat + * @param cnt Count */ - private final class RepeatIterator implements Iterator { - - /** - * Current position. - */ - private int cursor; - - @Override - public boolean hasNext() { - return this.cursor < Repeat.this.count; - } + public RepeatIterable(final UncheckedScalar elm, final int cnt) { + this.element = elm; + this.count = cnt; + } - @Override - public T next() { - ++this.cursor; - return Repeat.this.element; - } + @Override + public Iterator iterator() { + return new RepeatIterator<>(this.element, this.count); } + } diff --git a/src/main/java/org/cactoos/list/RepeatIterator.java b/src/main/java/org/cactoos/list/RepeatIterator.java new file mode 100644 index 0000000000..4d24d8b3b2 --- /dev/null +++ b/src/main/java/org/cactoos/list/RepeatIterator.java @@ -0,0 +1,91 @@ +/** + * 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.list; + +import java.util.Iterator; +import org.cactoos.Scalar; +import org.cactoos.func.UncheckedScalar; + +/** + * Repeat an element. + * + *

If you need to repeat endlessly, use {@link EndlessIterable}.

+ * + * @author Kirill (g4s8.public@gmail.com) + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @param Element type + * @since 0.4 + */ +public final class RepeatIterator implements Iterator { + + /** + * The element to repeat. + */ + private final UncheckedScalar element; + + /** + * How many more repeats will happen. + */ + private int left; + + /** + * Ctor. + * @param elm Element to repeat + * @param max How many times to repeat + */ + public RepeatIterator(final T elm, final int max) { + this(() -> elm, max); + } + + /** + * Ctor. + * @param elm Element to repeat + * @param max How many times to repeat + */ + public RepeatIterator(final Scalar elm, final int max) { + this(new UncheckedScalar(elm), max); + } + + /** + * Ctor. + * @param elm Element to repeat + * @param max How many times to repeat + */ + public RepeatIterator(final UncheckedScalar elm, final int max) { + this.element = elm; + this.left = max; + } + + @Override + public boolean hasNext() { + return this.left > 0; + } + + @Override + public T next() { + --this.left; + return this.element.asValue(); + } +} diff --git a/src/main/java/org/cactoos/list/SkippedIterable.java b/src/main/java/org/cactoos/list/SkippedIterable.java new file mode 100644 index 0000000000..79c55ef92e --- /dev/null +++ b/src/main/java/org/cactoos/list/SkippedIterable.java @@ -0,0 +1,64 @@ +/** + * 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.list; + +import java.util.Iterator; + +/** + * Skipped iterable. + * + *

There is no thread-safety guarantee.

+ * + * @author Ilia Rogozhin (ilia.rogozhin@gmail.com) + * @version $Id$ + * @param Element type + * @since 0.8 + */ +public final class SkippedIterable implements Iterable { + + /** + * Decorated iterable. + */ + private final Iterable iterable; + + /** + * Count skip elements. + */ + private final int skip; + + /** + * Ctor. + * @param iterable Decorated iterable + * @param skip Count skip elements + */ + public SkippedIterable(final Iterable iterable, final int skip) { + this.iterable = iterable; + this.skip = skip; + } + + @Override + public Iterator iterator() { + return new SkippedIterator<>(this.iterable.iterator(), this.skip); + } +} diff --git a/src/main/java/org/cactoos/list/SkippedIterator.java b/src/main/java/org/cactoos/list/SkippedIterator.java new file mode 100644 index 0000000000..4774f1038e --- /dev/null +++ b/src/main/java/org/cactoos/list/SkippedIterator.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.list; + +import java.util.Iterator; +import java.util.NoSuchElementException; + +/** + * Skipped iterator. + * + *

There is no thread-safety guarantee.

+ * + * @author Ilia Rogozhin (ilia.rogozhin@gmail.com) + * @version $Id$ + * @param Element type + * @since 0.8 + */ +public final class SkippedIterator implements Iterator { + + /** + * Decorated iterator. + */ + private final Iterator iterator; + + /** + * Count skip elements. + */ + private int skip; + + /** + * Ctor. + * @param iterator Decorated iterator + * @param skip Count skip elements + */ + public SkippedIterator(final Iterator iterator, final int skip) { + this.iterator = iterator; + this.skip = skip; + } + + @Override + public boolean hasNext() { + while (this.skip > 0 && this.iterator.hasNext()) { + this.iterator.next(); + --this.skip; + } + return this.iterator.hasNext(); + } + + @Override + public T next() { + if (!this.hasNext()) { + throw new NoSuchElementException(); + } + return this.iterator.next(); + } +} diff --git a/src/main/java/org/cactoos/list/SortedIterable.java b/src/main/java/org/cactoos/list/SortedIterable.java new file mode 100644 index 0000000000..96f487fa55 --- /dev/null +++ b/src/main/java/org/cactoos/list/SortedIterable.java @@ -0,0 +1,94 @@ +/** + * 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.list; + +import java.util.Comparator; +import java.util.Iterator; + +/** + * Sorted iterable. + * + *

There is no thread-safety guarantee.

+ * + * @author Dusan Rychnovsky (dusan.rychnovsky@gmail.com) + * @version $Id$ + * @param Element type + * @since 0.7 + */ +public final class + SortedIterable> implements + Iterable { + + /** + * Decorated iterable. + */ + private final Iterable iterable; + + /** + * Comparator. + */ + private final Comparator comparator; + + /** + * Ctor. + * @param src The underlying iterable + */ + @SafeVarargs + public SortedIterable(final T... src) { + this(new ArrayAsIterable<>(src)); + } + + /** + * Ctor. + * @param src The underlying iterable + */ + public SortedIterable(final Iterable src) { + this(Comparator.naturalOrder(), src); + } + + /** + * Ctor. + * @param src The underlying iterable + * @param cmp The comparator + */ + @SafeVarargs + public SortedIterable(final Comparator cmp, final T... src) { + this(cmp, new ArrayAsIterable<>(src)); + } + + /** + * Ctor. + * @param src The underlying iterable + * @param cmp The comparator + */ + public SortedIterable(final Comparator cmp, final Iterable src) { + this.iterable = src; + this.comparator = cmp; + } + + @Override + public Iterator iterator() { + return new SortedIterator<>(this.comparator, this.iterable.iterator()); + } +} diff --git a/src/main/java/org/cactoos/list/SortedIterator.java b/src/main/java/org/cactoos/list/SortedIterator.java new file mode 100644 index 0000000000..2ae36a15e6 --- /dev/null +++ b/src/main/java/org/cactoos/list/SortedIterator.java @@ -0,0 +1,89 @@ +/** + * 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.list; + +import java.util.Comparator; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import org.cactoos.func.StickyScalar; +import org.cactoos.func.UncheckedScalar; + +/** + * Sorted iterator. + * + *

There is no thread-safety guarantee.

+ * + * @author Dusan Rychnovsky (dusan.rychnovsky@gmail.com) + * @version $Id$ + * @param Element type + * @since 0.7 + */ +public final class + SortedIterator> implements + Iterator { + + /** + * Sorted one. + */ + private final UncheckedScalar> sorted; + + /** + * Ctor. + * @param src The underlying iterator + */ + public SortedIterator(final Iterator src) { + this(Comparator.naturalOrder(), src); + } + + /** + * Ctor. + * @param src The underlying iterator + * @param cmp The comparator + */ + public SortedIterator(final Comparator cmp, final Iterator src) { + this.sorted = new UncheckedScalar<>( + new StickyScalar<>( + () -> { + final List items = new LinkedList<>(); + while (src.hasNext()) { + items.add(src.next()); + } + items.sort(cmp); + return items.iterator(); + } + ) + ); + } + + @Override + public boolean hasNext() { + return this.sorted.asValue().hasNext(); + } + + @Override + public T next() { + return this.sorted.asValue().next(); + } +} diff --git a/src/main/java/org/cactoos/list/StickyIterable.java b/src/main/java/org/cactoos/list/StickyIterable.java new file mode 100644 index 0000000000..3d6ab4e3a5 --- /dev/null +++ b/src/main/java/org/cactoos/list/StickyIterable.java @@ -0,0 +1,72 @@ +/** + * 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.list; + +import java.util.Collection; +import java.util.Iterator; +import java.util.LinkedList; +import org.cactoos.func.StickyScalar; +import org.cactoos.func.UncheckedScalar; + +/** + * Iterable that returns the same set of elements, always. + * + *

There is no thread-safety guarantee. + * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @param Type of item + * @since 0.1 + */ +public final class StickyIterable implements Iterable { + + /** + * The gate. + */ + private final UncheckedScalar> gate; + + /** + * Ctor. + * @param iterable The iterable + */ + public StickyIterable(final Iterable iterable) { + this.gate = new UncheckedScalar<>( + new StickyScalar<>( + () -> { + final Collection temp = new LinkedList<>(); + for (final X item : iterable) { + temp.add(item); + } + return temp; + } + ) + ); + } + + @Override + public Iterator iterator() { + return this.gate.asValue().iterator(); + } + +} diff --git a/src/main/java/org/cactoos/list/StickyIterator.java b/src/main/java/org/cactoos/list/StickyIterator.java new file mode 100644 index 0000000000..8fd13294e7 --- /dev/null +++ b/src/main/java/org/cactoos/list/StickyIterator.java @@ -0,0 +1,85 @@ +/** + * 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.list; + +import java.util.Collection; +import java.util.Iterator; +import java.util.LinkedList; +import org.cactoos.func.StickyScalar; +import org.cactoos.func.UncheckedScalar; + +/** + * Iterator that returns the same set of elements always. + * + *

There is no thread-safety guarantee. + * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @param Type of item + * @since 0.8 + */ +public final class StickyIterator implements Iterator { + + /** + * The gate. + */ + private final UncheckedScalar> gate; + + /** + * Ctor. + * @param items Items to iterate + */ + @SafeVarargs + public StickyIterator(final X... items) { + this(new ArrayAsIterable<>(items).iterator()); + } + + /** + * Ctor. + * @param src The iterable + */ + public StickyIterator(final Iterator src) { + this.gate = new UncheckedScalar<>( + new StickyScalar<>( + () -> { + final Collection temp = new LinkedList<>(); + while (src.hasNext()) { + temp.add(src.next()); + } + return temp.iterator(); + } + ) + ); + } + + @Override + public boolean hasNext() { + return this.gate.asValue().hasNext(); + } + + @Override + public X next() { + return this.gate.asValue().next(); + } +} diff --git a/src/main/java/org/cactoos/list/StickyList.java b/src/main/java/org/cactoos/list/StickyList.java new file mode 100644 index 0000000000..1927fc4769 --- /dev/null +++ b/src/main/java/org/cactoos/list/StickyList.java @@ -0,0 +1,221 @@ +/** + * 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.list; + +import java.util.Collection; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.ListIterator; +import org.cactoos.func.StickyScalar; +import org.cactoos.func.UncheckedScalar; + +/** + * List decorator that goes through the list only once. + * + *

There is no thread-safety guarantee. + * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @param Type of item + * @since 0.8 + */ +@SuppressWarnings("PMD.TooManyMethods") +public final class StickyList implements List { + + /** + * The gate. + */ + private final UncheckedScalar> gate; + + /** + * Ctor. + * @param items The array + */ + @SafeVarargs + public StickyList(final X... items) { + this(new ArrayAsIterable<>(items)); + } + + /** + * Ctor. + * @param items The array + */ + public StickyList(final Iterable items) { + this(new IterableAsList<>(items)); + } + + /** + * Ctor. + * @param list The iterable + */ + public StickyList(final Collection list) { + this.gate = new UncheckedScalar<>( + new StickyScalar<>( + () -> { + final List temp = new LinkedList<>(); + temp.addAll(list); + return temp; + } + ) + ); + } + + @Override + public int size() { + return this.gate.asValue().size(); + } + + @Override + public boolean isEmpty() { + return this.gate.asValue().isEmpty(); + } + + @Override + public boolean contains(final Object object) { + return this.gate.asValue().contains(object); + } + + @Override + public Iterator iterator() { + return this.gate.asValue().iterator(); + } + + @Override + public Object[] toArray() { + return this.gate.asValue().toArray(); + } + + @Override + @SuppressWarnings("PMD.UseVarargs") + public Y[] toArray(final Y[] array) { + return this.gate.asValue().toArray(array); + } + + @Override + public boolean add(final X element) { + throw new UnsupportedOperationException( + "#add(final T element) is not supported" + ); + } + + @Override + public boolean remove(final Object object) { + throw new UnsupportedOperationException( + "#remove(final Object object) is not supported" + ); + } + + @Override + public boolean containsAll(final Collection collection) { + return this.gate.asValue().containsAll(collection); + } + + @Override + public boolean addAll(final Collection collection) { + throw new UnsupportedOperationException( + "#addAll(final Collection collection) is not supported" + ); + } + + @Override + public boolean addAll(final int index, + final Collection collection) { + throw new UnsupportedOperationException( + "#addAll() is not supported" + ); + } + + @Override + public boolean removeAll(final Collection collection) { + throw new UnsupportedOperationException( + "#removeAll(final Collection collection) is not supported" + ); + } + + @Override + public boolean retainAll(final Collection collection) { + throw new UnsupportedOperationException( + "#retainAll(final Collection collection) is not supported" + ); + } + + @Override + public void clear() { + throw new UnsupportedOperationException( + "#clear() is not supported" + ); + } + + @Override + public X get(final int index) { + return this.gate.asValue().get(index); + } + + @Override + public X set(final int index, final X element) { + throw new UnsupportedOperationException( + "#set() is not supported" + ); + } + + @Override + public void add(final int index, final X element) { + throw new UnsupportedOperationException( + "#add(final int index, final T element) is not supported" + ); + } + + @Override + public X remove(final int index) { + throw new UnsupportedOperationException( + "#remove(final int index) is not supported" + ); + } + + @Override + public int indexOf(final Object object) { + return this.gate.asValue().indexOf(object); + } + + @Override + public int lastIndexOf(final Object object) { + return this.gate.asValue().lastIndexOf(object); + } + + @Override + public ListIterator listIterator() { + return this.gate.asValue().listIterator(); + } + + @Override + public ListIterator listIterator(final int index) { + return this.gate.asValue().listIterator(index); + } + + @Override + public List subList(final int fromindex, final int toindex) { + return this.gate.asValue().subList(fromindex, toindex); + } +} diff --git a/src/main/java/org/cactoos/list/StickyMap.java b/src/main/java/org/cactoos/list/StickyMap.java new file mode 100644 index 0000000000..ef8bd880ff --- /dev/null +++ b/src/main/java/org/cactoos/list/StickyMap.java @@ -0,0 +1,152 @@ +/** + * 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.list; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import org.cactoos.func.StickyScalar; +import org.cactoos.func.UncheckedScalar; + +/** + * Map decorator that goes through the map only once. + * + *

There is no thread-safety guarantee. + * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @param Type of key + * @param Type of value + * @since 0.8 + */ +public final class StickyMap implements Map { + + /** + * The gate. + */ + private final UncheckedScalar> gate; + + /** + * Ctor. + * @param list List of entries + */ + @SafeVarargs + public StickyMap(final Map.Entry... list) { + this(new ArrayAsIterable<>(list)); + } + + /** + * Ctor. + * @param list Entries for the entries + */ + public StickyMap(final Iterable> list) { + this(new IterableAsMap<>(list)); + } + + /** + * Ctor. + * @param map The map + */ + public StickyMap(final Map map) { + this.gate = new UncheckedScalar<>( + new StickyScalar<>( + () -> { + final Map temp = new HashMap<>(0); + temp.putAll(map); + return temp; + } + ) + ); + } + + @Override + public int size() { + return this.gate.asValue().size(); + } + + @Override + public boolean isEmpty() { + return this.gate.asValue().isEmpty(); + } + + @Override + public boolean containsKey(final Object key) { + return this.gate.asValue().containsKey(key); + } + + @Override + public boolean containsValue(final Object value) { + return this.gate.asValue().containsValue(value); + } + + @Override + public Y get(final Object key) { + return this.gate.asValue().get(key); + } + + @Override + public Y put(final X key, final Y value) { + throw new UnsupportedOperationException( + "#put() is not supported" + ); + } + + @Override + public Y remove(final Object key) { + throw new UnsupportedOperationException( + "#remove() is not supported" + ); + } + + @Override + public void putAll(final Map map) { + throw new UnsupportedOperationException( + "#putAll() is not supported" + ); + } + + @Override + public void clear() { + throw new UnsupportedOperationException( + "#clear() is not supported" + ); + } + + @Override + public Set keySet() { + return this.gate.asValue().keySet(); + } + + @Override + public Collection values() { + return this.gate.asValue().values(); + } + + @Override + public Set> entrySet() { + return this.gate.asValue().entrySet(); + } + +} diff --git a/src/main/java/org/cactoos/text/ArrayAsBytes.java b/src/main/java/org/cactoos/text/ArrayAsBytes.java index 6f545703e7..56f3b8dec8 100644 --- a/src/main/java/org/cactoos/text/ArrayAsBytes.java +++ b/src/main/java/org/cactoos/text/ArrayAsBytes.java @@ -45,8 +45,7 @@ public final class ArrayAsBytes implements Bytes { * Ctor. * @param bts Bytes to encapsulate */ - @SuppressWarnings("PMD.ArrayIsStoredDirectly") - public ArrayAsBytes(final byte[] bts) { + public ArrayAsBytes(final byte... bts) { this.bytes = bts; } diff --git a/src/main/java/org/cactoos/text/BytesAsText.java b/src/main/java/org/cactoos/text/BytesAsText.java index b76b49947a..481305da41 100644 --- a/src/main/java/org/cactoos/text/BytesAsText.java +++ b/src/main/java/org/cactoos/text/BytesAsText.java @@ -27,7 +27,9 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import org.cactoos.Bytes; +import org.cactoos.Input; import org.cactoos.Text; +import org.cactoos.io.InputAsBytes; /** * Bytes as Text. @@ -53,6 +55,15 @@ public final class BytesAsText implements Text { */ private final Charset charset; + /** + * Ctor. + * @param input Bytes from the input + * @since 0.8 + */ + public BytesAsText(final Input input) { + this(new InputAsBytes(input)); + } + /** * Ctor. * @param bts Bytes to encapsulate @@ -69,6 +80,16 @@ public BytesAsText(final Bytes bts) { this(bts, StandardCharsets.UTF_8); } + /** + * Ctor. + * @param input Input + * @param cset Charset + * @since 0.8 + */ + public BytesAsText(final Input input, final Charset cset) { + this(new InputAsBytes(input), cset); + } + /** * Ctor. * @param bts Bytes to encapsulate diff --git a/src/main/java/org/cactoos/text/FormattedText.java b/src/main/java/org/cactoos/text/FormattedText.java index 15bf90840c..9508203602 100644 --- a/src/main/java/org/cactoos/text/FormattedText.java +++ b/src/main/java/org/cactoos/text/FormattedText.java @@ -23,12 +23,13 @@ */ package org.cactoos.text; -import java.util.Arrays; +import java.io.IOException; import java.util.Collection; import java.util.Collections; import java.util.Formatter; import java.util.Locale; import org.cactoos.Text; +import org.cactoos.list.IterableAsList; /** * Text in Sprinf format. @@ -44,7 +45,7 @@ public final class FormattedText implements Text { /** * Pattern. */ - private final String pattern; + private final Text pattern; /** * Arguments. @@ -63,7 +64,17 @@ public final class FormattedText implements Text { * @param arguments Arguments */ public FormattedText(final String ptn, final Object... arguments) { - this(ptn, Arrays.asList(arguments)); + this(ptn, new IterableAsList<>(arguments)); + } + + /** + * New formatted string with default locale. + * + * @param ptn Pattern + * @param arguments Arguments + */ + public FormattedText(final Text ptn, final Object... arguments) { + this(ptn, new IterableAsList<>(arguments)); } /** @@ -78,7 +89,22 @@ public FormattedText( final Locale locale, final Object... arguments ) { - this(ptn, locale, Arrays.asList(arguments)); + this(ptn, locale, new IterableAsList<>(arguments)); + } + + /** + * New formatted string with specified locale. + * + * @param ptn Pattern + * @param locale Format locale + * @param arguments Arguments + */ + public FormattedText( + final Text ptn, + final Locale locale, + final Object... arguments + ) { + this(ptn, locale, new IterableAsList<>(arguments)); } /** @@ -91,6 +117,16 @@ public FormattedText(final String ptn, final Collection arguments) { this(ptn, Locale.getDefault(Locale.Category.FORMAT), arguments); } + /** + * New formatted string with default locale. + * + * @param ptn Pattern + * @param arguments Arguments + */ + public FormattedText(final Text ptn, final Collection arguments) { + this(ptn, Locale.getDefault(Locale.Category.FORMAT), arguments); + } + /** * New formatted string with specified locale. * @@ -102,6 +138,21 @@ public FormattedText( final String ptn, final Locale locale, final Collection arguments + ) { + this(new StringAsText(ptn), locale, arguments); + } + + /** + * New formatted string with specified locale. + * + * @param ptn Pattern + * @param locale Format locale + * @param arguments Arguments + */ + public FormattedText( + final Text ptn, + final Locale locale, + final Collection arguments ) { this.pattern = ptn; this.locale = locale; @@ -109,11 +160,12 @@ public FormattedText( } @Override - public String asString() { + public String asString() throws IOException { final StringBuilder out = new StringBuilder(0); try (final Formatter fmt = new Formatter(out, this.locale)) { fmt.format( - this.pattern, this.args.toArray(new Object[this.args.size()]) + this.pattern.asString(), + this.args.toArray(new Object[this.args.size()]) ); } return out.toString(); diff --git a/src/main/java/org/cactoos/text/JoinedText.java b/src/main/java/org/cactoos/text/JoinedText.java new file mode 100644 index 0000000000..b886bea385 --- /dev/null +++ b/src/main/java/org/cactoos/text/JoinedText.java @@ -0,0 +1,113 @@ +/** + * 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 java.util.StringJoiner; +import org.cactoos.Text; +import org.cactoos.list.ArrayAsIterable; +import org.cactoos.list.MappedIterable; + +/** + * Join a Text. + * + *

There is no thread-safety guarantee. + * + * @author Fabricio Cabral (fabriciofx@gmail.com) + * @version $Id$ + * @since 0.9 + */ +public final class JoinedText implements Text { + + /** + * The texts. + */ + private final Iterable texts; + + /** + * The delimiter. + */ + private final Text delimiter; + + /** + * Ctor. + * @param delimiter Delimit among texts + * @param texts Texts to be joined + */ + public JoinedText(final String delimiter, final String... texts) { + this( + new StringAsText(delimiter), + new MappedIterable<>( + new ArrayAsIterable<>(texts), + text -> new StringAsText(text) + ) + ); + } + + /** + * Ctor. + * @param delimiter Delimit among texts + * @param texts Texts to be joined + */ + public JoinedText(final String delimiter, final Text... texts) { + this(delimiter, new ArrayAsIterable<>(texts)); + } + + /** + * Ctor. + * @param delimiter Delimit among texts + * @param texts Texts to be joined + */ + public JoinedText(final String delimiter, final Iterable texts) { + this(new StringAsText(delimiter), texts); + } + + /** + * Ctor. + * @param delimiter Delimit among texts + * @param texts Texts to be joined + */ + public JoinedText(final Text delimiter, final Text... texts) { + this(delimiter, new ArrayAsIterable<>(texts)); + } + + /** + * Ctor. + * @param delimiter Delimit among texts + * @param texts Texts to be joined + */ + public JoinedText(final Text delimiter, final Iterable texts) { + this.delimiter = delimiter; + this.texts = texts; + } + + @Override + public String asString() throws IOException { + final StringJoiner joint = new StringJoiner(this.delimiter.asString()); + for (final Text text : this.texts) { + joint.add(text.asString()); + } + return joint.toString(); + } +} diff --git a/src/main/java/org/cactoos/text/NormalizedText.java b/src/main/java/org/cactoos/text/NormalizedText.java new file mode 100644 index 0000000000..72e237c0a1 --- /dev/null +++ b/src/main/java/org/cactoos/text/NormalizedText.java @@ -0,0 +1,65 @@ +/** + * 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; + +/** + * Normalize (replace sequences of whitespace characters by a single space) + * a Text. + * + * @author Fabricio Cabral (fabriciofx@gmail.com) + * @version $Id$ + * @since 0.9 + */ +public final class NormalizedText implements Text { + + /** + * The text. + */ + private final Text origin; + + /** + * Ctor. + * @param text A Text + */ + public NormalizedText(final String text) { + this(new StringAsText(text)); + } + + /** + * Ctor. + * @param text A Text + */ + public NormalizedText(final Text text) { + this.origin = text; + } + + @Override + public String asString() throws IOException { + return new TrimmedText(this.origin).asString().replaceAll("\\s+", " "); + } +} + diff --git a/src/main/java/org/cactoos/text/NotNullText.java b/src/main/java/org/cactoos/text/NotNullText.java new file mode 100644 index 0000000000..f47828fbcd --- /dev/null +++ b/src/main/java/org/cactoos/text/NotNullText.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.text; + +import java.io.IOException; +import org.cactoos.Text; + +/** + * A safe Text. + * + *

There is no thread-safety guarantee. + * + * @author Fabricio Cabral (fabriciofx@gmail.com) + * @version $Id$ + * @since 0.3 + */ +public final class NotNullText implements Text { + + /** + * The text. + */ + private final Text origin; + + /** + * Ctor. + * @param text The text + */ + public NotNullText(final Text text) { + this.origin = text; + } + + @Override + public String asString() throws IOException { + if (this.origin == null) { + throw new IOException("invalid text (null)"); + } + return this.origin.asString(); + } +} diff --git a/src/main/java/org/cactoos/text/RepeatedText.java b/src/main/java/org/cactoos/text/RepeatedText.java new file mode 100644 index 0000000000..ea09013f60 --- /dev/null +++ b/src/main/java/org/cactoos/text/RepeatedText.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; + +/** + * Repeat an text count times. + * + *

There is no thread-safety guarantee. + * + * @author Fabricio Cabral (fabriciofx@gmail.com) + * @version $Id$ + * @since 0.9 + */ +public final class RepeatedText implements Text { + + /** + * The text. + */ + private final Text origin; + + /** + * How many times repeat the Text. + */ + private final int count; + + /** + * Ctor. + * @param text A String + * @param count How many times repeat the Text + */ + public RepeatedText(final String text, final int count) { + this(new StringAsText(text), count); + } + + /** + * Ctor. + * @param text The Text + * @param count How many times repeat the Text + */ + public RepeatedText(final Text text, final int count) { + this.origin = text; + this.count = count; + } + + @Override + public String asString() throws IOException { + final StringBuilder out = new StringBuilder(); + for (int cnt = 0; cnt < this.count; ++cnt) { + out.append(this.origin.asString()); + } + return out.toString(); + } +} diff --git a/src/main/java/org/cactoos/text/ReversedText.java b/src/main/java/org/cactoos/text/ReversedText.java new file mode 100644 index 0000000000..e32e0be611 --- /dev/null +++ b/src/main/java/org/cactoos/text/ReversedText.java @@ -0,0 +1,56 @@ +/** + * 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; + +/** + * Reverse the Text. + * + * @author Mehmet Yildirim (memoyil@gmail.com) + * @version $Id$ + * @since 0.2 + */ +public final class ReversedText implements Text { + + /** + * The text. + */ + private final Text origin; + + /** + * Ctor. + * + * @param text The text + */ + public ReversedText(final Text text) { + this.origin = text; + } + + @Override + public String asString() throws IOException { + return new StringBuilder(this.origin.asString()).reverse().toString(); + } +} diff --git a/src/main/java/org/cactoos/text/StringAsUrl.java b/src/main/java/org/cactoos/text/StringAsUrl.java new file mode 100644 index 0000000000..502b4025bb --- /dev/null +++ b/src/main/java/org/cactoos/text/StringAsUrl.java @@ -0,0 +1,97 @@ +/** + * 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 java.net.URLEncoder; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import org.cactoos.Scalar; +import org.cactoos.Text; + +/** + * String as URL. + * + *

There is no thread-safety guarantee. + * + * @author Fabricio Cabral (fabriciofx@gmail.com) + * @version $Id$ + * @since 0.4 + */ +public final class StringAsUrl implements Scalar { + + /** + * The source. + */ + private final Text source; + + /** + * The encoding. + */ + private final Charset encoding; + + /** + * Ctor. + * @param url The URL as String + */ + public StringAsUrl(final String url) { + this(url, StandardCharsets.UTF_8); + } + + /** + * Ctor. + * @param url The URL as Text + */ + public StringAsUrl(final Text url) { + this(url, StandardCharsets.UTF_8); + } + + /** + * Ctor. + * @param url The URL as String + * @param enc The encoding + */ + public StringAsUrl(final String url, final Charset enc) { + this(new StringAsText(url), enc); + } + + /** + * Ctor. + * @param url The URL as Text + * @param enc The encoding + */ + public StringAsUrl(final Text url, final Charset enc) { + this.source = url; + this.encoding = enc; + } + + @Override + public String asValue() throws IOException { + return URLEncoder.encode( + this.source.asString(), + this.encoding.name() + ); + } + +} diff --git a/src/main/java/org/cactoos/text/UncheckedText.java b/src/main/java/org/cactoos/text/UncheckedText.java new file mode 100644 index 0000000000..aeb359f68f --- /dev/null +++ b/src/main/java/org/cactoos/text/UncheckedText.java @@ -0,0 +1,88 @@ +/** + * 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 java.io.UncheckedIOException; +import org.cactoos.Func; +import org.cactoos.Text; +import org.cactoos.func.UncheckedFunc; + +/** + * Text that doesn't throw checked {@link Exception}. + * + *

There is no thread-safety guarantee. + * + * @author Fabricio Cabral (fabriciofx@gmail.com) + * @version $Id$ + * @since 0.3 + */ +public final class UncheckedText implements Text { + + /** + * Original text. + */ + private final Text text; + + /** + * Fallback. + */ + private final Func fallback; + + /** + * Ctor. + * @param txt Encapsulated text + */ + public UncheckedText(final Text txt) { + this( + txt, + error -> { + throw new UncheckedIOException(error); + } + ); + } + + /** + * Ctor. + * @param txt Encapsulated text + * @param fbk Fallback func if {@link IOException} happens + * @since 0.5 + */ + public UncheckedText(final Text txt, final Func fbk) { + this.text = txt; + this.fallback = fbk; + } + + @Override + public String asString() { + String txt; + try { + txt = this.text.asString(); + } catch (final IOException ex) { + txt = new UncheckedFunc<>(this.fallback).apply(ex); + } + return txt; + } + +} diff --git a/src/main/java/org/cactoos/text/UrlAsString.java b/src/main/java/org/cactoos/text/UrlAsString.java new file mode 100644 index 0000000000..3bbff71c17 --- /dev/null +++ b/src/main/java/org/cactoos/text/UrlAsString.java @@ -0,0 +1,97 @@ +/** + * 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 java.net.URLDecoder; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import org.cactoos.Scalar; +import org.cactoos.Text; + +/** + * URL as String. + * + *

There is no thread-safety guarantee. + * + * @author Fabricio Cabral (fabriciofx@gmail.com) + * @version $Id$ + * @since 0.4 + */ +public final class UrlAsString implements Scalar { + + /** + * The source. + */ + private final Text source; + + /** + * The encoding. + */ + private final Charset encoding; + + /** + * Ctor. + * @param url The URL as String + */ + public UrlAsString(final String url) { + this(url, StandardCharsets.UTF_8); + } + + /** + * Ctor. + * @param url The URL as Text + */ + public UrlAsString(final Text url) { + this(url, StandardCharsets.UTF_8); + } + + /** + * Ctor. + * @param url The URL as String + * @param enc The encoding + */ + public UrlAsString(final String url, final Charset enc) { + this(new StringAsText(url), enc); + } + + /** + * Ctor. + * @param url The URL as Text + * @param enc The encoding + */ + public UrlAsString(final Text url, final Charset enc) { + this.source = url; + this.encoding = enc; + } + + @Override + public String asValue() throws IOException { + return URLDecoder.decode( + this.source.asString(), + this.encoding.name() + ); + } + +} diff --git a/src/test/java/org/cactoos/list/AllOfTest.java b/src/test/java/org/cactoos/func/AndTest.java similarity index 59% rename from src/test/java/org/cactoos/list/AllOfTest.java rename to src/test/java/org/cactoos/func/AndTest.java index baa1f2bb96..90dd7c896c 100644 --- a/src/test/java/org/cactoos/list/AllOfTest.java +++ b/src/test/java/org/cactoos/func/AndTest.java @@ -21,37 +21,85 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package org.cactoos.list; +package org.cactoos.func; import java.util.Collections; import java.util.LinkedList; import java.util.List; -import org.cactoos.Proc; +import org.cactoos.Scalar; import org.cactoos.ScalarHasValue; -import org.cactoos.func.AlwaysTrueFunc; -import org.cactoos.func.FuncAsMatcher; +import org.cactoos.list.ArrayAsIterable; +import org.cactoos.list.MappedIterable; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Test; /** - * Test case for {@link AllOf}. - * @author Yegor Bugayenko (yegor256@gmail.com) + * Test case for {@link And}. + * + * @author Vseslav Sekorin (vssekorin@gmail.com) * @version $Id$ - * @since 0.1 + * @since 0.8 * @checkstyle JavadocMethodCheck (500 lines) + * @checkstyle ClassDataAbstractionCouplingCheck (500 lines) */ -public final class AllOfTest { +public final class AndTest { + + @Test + public void allTrue() throws Exception { + MatcherAssert.assertThat( + new And( + new True(), + new True(), + new True() + ).asValue(), + Matchers.equalTo(true) + ); + } + + @Test + public void oneFalse() throws Exception { + MatcherAssert.assertThat( + new And( + new True(), + new False(), + new True() + ).asValue(), + Matchers.equalTo(false) + ); + } + + @Test + public void allFalse() throws Exception { + MatcherAssert.assertThat( + new And( + new ArrayAsIterable>( + new False(), + new False(), + new False() + ) + ).asValue(), + Matchers.equalTo(false) + ); + } + + @Test + public void emptyIterator() throws Exception { + MatcherAssert.assertThat( + new And(Collections.emptyList()).asValue(), + Matchers.equalTo(true) + ); + } @Test public void iteratesList() { final List list = new LinkedList<>(); MatcherAssert.assertThat( "Can't iterate a list with a procedure", - new AllOf( - new TransformedIterable<>( + new And( + new MappedIterable<>( new ArrayAsIterable<>("hello", "world"), - list::add + new ProcAsFunc<>(list::add, () -> true) ) ), new ScalarHasValue<>( @@ -70,12 +118,10 @@ public void iteratesEmptyList() { final List list = new LinkedList<>(); MatcherAssert.assertThat( "Can't iterate a list", - new AllOf( - new IterableAsBooleans<>( + new And( + new MappedIterable>( Collections.emptyList(), - new AlwaysTrueFunc<>( - (Proc) list::add - ) + new ProcAsFunc<>(list::add, () -> true) ) ), new ScalarHasValue<>( diff --git a/src/test/java/org/cactoos/func/FalseTest.java b/src/test/java/org/cactoos/func/FalseTest.java new file mode 100644 index 0000000000..9da6bf2454 --- /dev/null +++ b/src/test/java/org/cactoos/func/FalseTest.java @@ -0,0 +1,48 @@ +/** + * 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.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.Test; + +/** + * Test case for {@link False}. + * + * @author Vseslav Sekorin (vssekorin@gmail.com) + * @version $Id$ + * @since 0.7 + * @checkstyle JavadocMethodCheck (500 lines) + */ +public final class FalseTest { + + @Test + public void asValue() throws Exception { + MatcherAssert.assertThat( + new False().asValue(), + Matchers.equalTo(false) + ); + } + +} diff --git a/src/test/java/org/cactoos/func/FuncWithCallbackTest.java b/src/test/java/org/cactoos/func/FuncWithFallbackTest.java similarity index 80% rename from src/test/java/org/cactoos/func/FuncWithCallbackTest.java rename to src/test/java/org/cactoos/func/FuncWithFallbackTest.java index 44f4c89ff9..a734b4bc11 100644 --- a/src/test/java/org/cactoos/func/FuncWithCallbackTest.java +++ b/src/test/java/org/cactoos/func/FuncWithFallbackTest.java @@ -30,20 +30,20 @@ import org.junit.Test; /** - * Test case for {@link FuncWithCallback}. + * Test case for {@link FuncWithFallback}. * * @author Yegor Bugayenko (yegor256@gmail.com) * @version $Id$ * @since 0.2 * @checkstyle JavadocMethodCheck (500 lines) */ -public final class FuncWithCallbackTest { +public final class FuncWithFallbackTest { @Test public void usesMainFunc() throws Exception { MatcherAssert.assertThat( "Can't use the main function if no exception", - new FuncWithCallback<>( + new FuncWithFallback<>( input -> "It's success", ex -> "In case of failure..." ), @@ -55,7 +55,7 @@ public void usesMainFunc() throws Exception { public void usesCallback() throws Exception { MatcherAssert.assertThat( "Can't use the callback in case of exception", - new FuncWithCallback<>( + new FuncWithFallback<>( input -> { throw new IOException("Failure"); }, @@ -65,4 +65,17 @@ public void usesCallback() throws Exception { ); } + @Test + public void usesFollowUp() throws Exception { + MatcherAssert.assertThat( + "Can't use the follow-up func", + new FuncWithFallback<>( + input -> "works fine", + ex -> "won't happen", + input -> "follow up" + ), + new FuncApplies<>(1, Matchers.containsString("follow")) + ); + } + } diff --git a/src/test/java/org/cactoos/func/IoCheckedFuncTest.java b/src/test/java/org/cactoos/func/IoCheckedFuncTest.java new file mode 100644 index 0000000000..a2b1c0233c --- /dev/null +++ b/src/test/java/org/cactoos/func/IoCheckedFuncTest.java @@ -0,0 +1,58 @@ +/** + * 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.Func; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.Test; + +/** + * Test case for {@link IoCheckedFunc}. + * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @since 0.4 + * @checkstyle JavadocMethodCheck (500 lines) + */ +public final class IoCheckedFuncTest { + + @Test + public void rethrowsCheckedToUncheckedException() { + final IOException exception = new IOException("intended"); + try { + new IoCheckedFunc<>( + (Func) i -> { + throw exception; + } + ).apply(1); + } catch (final IOException ex) { + MatcherAssert.assertThat( + ex, Matchers.is(exception) + ); + } + } + +} diff --git a/src/test/java/org/cactoos/func/IoCheckedProcTest.java b/src/test/java/org/cactoos/func/IoCheckedProcTest.java new file mode 100644 index 0000000000..37185f4fb4 --- /dev/null +++ b/src/test/java/org/cactoos/func/IoCheckedProcTest.java @@ -0,0 +1,58 @@ +/** + * 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.Proc; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.Test; + +/** + * Test case for {@link IoCheckedProc}. + * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @since 0.4 + * @checkstyle JavadocMethodCheck (500 lines) + */ +public final class IoCheckedProcTest { + + @Test + public void rethrowsCheckedToUncheckedException() { + final IOException exception = new IOException("intended"); + try { + new IoCheckedProc<>( + (Proc) i -> { + throw exception; + } + ).exec(1); + } catch (final IOException ex) { + MatcherAssert.assertThat( + ex, Matchers.is(exception) + ); + } + } + +} diff --git a/src/test/java/org/cactoos/func/IoCheckedScalarTest.java b/src/test/java/org/cactoos/func/IoCheckedScalarTest.java new file mode 100644 index 0000000000..4c0b5e904f --- /dev/null +++ b/src/test/java/org/cactoos/func/IoCheckedScalarTest.java @@ -0,0 +1,58 @@ +/** + * 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.Scalar; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.Test; + +/** + * Test case for {@link IoCheckedScalar}. + * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @since 0.4 + * @checkstyle JavadocMethodCheck (500 lines) + */ +public final class IoCheckedScalarTest { + + @Test + public void rethrowsCheckedToUncheckedException() { + final IOException exception = new IOException("intended"); + try { + new IoCheckedScalar<>( + (Scalar) () -> { + throw exception; + } + ).asValue(); + } catch (final IOException ex) { + MatcherAssert.assertThat( + ex, Matchers.is(exception) + ); + } + } + +} diff --git a/src/test/java/org/cactoos/func/NegTest.java b/src/test/java/org/cactoos/func/NegTest.java new file mode 100644 index 0000000000..0fcccc08e8 --- /dev/null +++ b/src/test/java/org/cactoos/func/NegTest.java @@ -0,0 +1,55 @@ +/** + * 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.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.Test; + +/** + * Test case for {@link Neg}. + * + * @author Vseslav Sekorin (vssekorin@gmail.com) + * @version $Id$ + * @since 0.7 + * @checkstyle JavadocMethodCheck (500 lines) + */ +public final class NegTest { + + @Test + public void trueToFalse() throws Exception { + MatcherAssert.assertThat( + new Neg(new True()).asValue(), + Matchers.equalTo(new False().asValue()) + ); + } + + @Test + public void falseToTrue() throws Exception { + MatcherAssert.assertThat( + new Neg(new False()).asValue(), + Matchers.equalTo(new True().asValue()) + ); + } +} diff --git a/src/test/java/org/cactoos/func/OrTest.java b/src/test/java/org/cactoos/func/OrTest.java new file mode 100644 index 0000000000..ca5219cbdb --- /dev/null +++ b/src/test/java/org/cactoos/func/OrTest.java @@ -0,0 +1,94 @@ +/** + * 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.util.Collections; +import org.cactoos.Scalar; +import org.cactoos.list.ArrayAsIterable; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.Test; + +/** + * Test case for {@link Or}. + * + * @author Vseslav Sekorin (vssekorin@gmail.com) + * @version $Id$ + * @since 0.8 + * @checkstyle JavadocMethodCheck (500 lines) + */ +public final class OrTest { + + @Test + public void allFalse() throws Exception { + MatcherAssert.assertThat( + new Or( + new False(), + new False(), + new False(), + new False(), + new False() + ).asValue(), + Matchers.equalTo(false) + ); + } + + @Test + public void oneTrue() throws Exception { + MatcherAssert.assertThat( + new Or( + new False(), + new True(), + new False(), + new False(), + new False() + ).asValue(), + Matchers.equalTo(true) + ); + } + + @Test + public void allTrue() throws Exception { + MatcherAssert.assertThat( + new Or( + new ArrayAsIterable>( + new True(), + new True(), + new True(), + new True(), + new True() + ) + ).asValue(), + Matchers.equalTo(true) + ); + } + + @Test + public void emptyIterator() throws Exception { + MatcherAssert.assertThat( + new Or(Collections.emptyList()).asValue(), + Matchers.equalTo(false) + ); + } +} diff --git a/src/test/java/org/cactoos/func/RepeatedFuncTest.java b/src/test/java/org/cactoos/func/RepeatedFuncTest.java new file mode 100644 index 0000000000..6542189169 --- /dev/null +++ b/src/test/java/org/cactoos/func/RepeatedFuncTest.java @@ -0,0 +1,54 @@ +/** + * 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.security.SecureRandom; +import org.cactoos.Func; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.Test; + +/** + * Test case for {@link RepeatedFunc}. + * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @since 0.6 + * @checkstyle JavadocMethodCheck (500 lines) + */ +public final class RepeatedFuncTest { + + @Test + public void runsFuncMultipleTimes() throws Exception { + final Func func = new RepeatedFunc<>( + input -> new SecureRandom().nextInt(), + 2 + ); + MatcherAssert.assertThat( + func.apply(true), + Matchers.not(Matchers.equalTo(func.apply(true))) + ); + } + +} diff --git a/src/test/java/org/cactoos/func/RetryFuncTest.java b/src/test/java/org/cactoos/func/RetryFuncTest.java new file mode 100644 index 0000000000..3afbd601cc --- /dev/null +++ b/src/test/java/org/cactoos/func/RetryFuncTest.java @@ -0,0 +1,58 @@ +/** + * 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.security.SecureRandom; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.Test; + +/** + * Test case for {@link RetryFunc}. + * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @since 0.8 + * @checkstyle JavadocMethodCheck (500 lines) + */ +public final class RetryFuncTest { + + @Test + public void runsFuncMultipleTimes() throws Exception { + MatcherAssert.assertThat( + new RetryFunc<>( + input -> { + // @checkstyle MagicNumberCheck (1 line) + if (new SecureRandom().nextDouble() > 0.3d) { + throw new IllegalArgumentException("May happen"); + } + return 0; + }, + Integer.MAX_VALUE + ).apply(true), + Matchers.equalTo(0) + ); + } + +} diff --git a/src/test/java/org/cactoos/func/RetryScalarTest.java b/src/test/java/org/cactoos/func/RetryScalarTest.java new file mode 100644 index 0000000000..40b6d5c7bc --- /dev/null +++ b/src/test/java/org/cactoos/func/RetryScalarTest.java @@ -0,0 +1,58 @@ +/** + * 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.security.SecureRandom; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.Test; + +/** + * Test case for {@link RetryScalar}. + * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @since 0.9 + * @checkstyle JavadocMethodCheck (500 lines) + */ +public final class RetryScalarTest { + + @Test + public void runsScalarMultipleTimes() throws Exception { + MatcherAssert.assertThat( + new RetryScalar<>( + () -> { + // @checkstyle MagicNumberCheck (1 line) + if (new SecureRandom().nextDouble() > 0.3d) { + throw new IllegalArgumentException("May happen"); + } + return 0; + }, + Integer.MAX_VALUE + ).asValue(), + Matchers.equalTo(0) + ); + } + +} diff --git a/src/test/java/org/cactoos/func/RunnableWithFallbackTest.java b/src/test/java/org/cactoos/func/RunnableWithFallbackTest.java new file mode 100644 index 0000000000..0d3b4ecb6f --- /dev/null +++ b/src/test/java/org/cactoos/func/RunnableWithFallbackTest.java @@ -0,0 +1,76 @@ +/** + * 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.FuncApplies; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.Test; + +/** + * Test case for {@link RunnableWithFallback}. + * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @since 0.6 + * @checkstyle JavadocMethodCheck (500 lines) + */ +public final class RunnableWithFallbackTest { + + @Test + public void usesMainFunc() throws Exception { + MatcherAssert.assertThat( + "Can't use the main function if no exception", + new RunnableAsFunc<>( + new RunnableWithFallback( + () -> { + }, + input -> { + throw new IOException(input); + } + ) + ), + new FuncApplies<>(true, Matchers.nullValue()) + ); + } + + @Test + public void usesFallback() throws Exception { + MatcherAssert.assertThat( + "Can't use the fallback function if there is exception", + new RunnableAsFunc<>( + new RunnableWithFallback( + () -> { + throw new IllegalStateException("intended"); + }, + input -> { + } + ) + ), + new FuncApplies<>(true, Matchers.nullValue()) + ); + } + +} diff --git a/src/test/java/org/cactoos/func/StickyFuncTest.java b/src/test/java/org/cactoos/func/StickyFuncTest.java new file mode 100644 index 0000000000..94da814cbd --- /dev/null +++ b/src/test/java/org/cactoos/func/StickyFuncTest.java @@ -0,0 +1,53 @@ +/** + * 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.security.SecureRandom; +import org.cactoos.Func; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.Test; + +/** + * Test case for {@link StickyFunc}. + * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @since 0.4 + * @checkstyle JavadocMethodCheck (500 lines) + */ +public final class StickyFuncTest { + + @Test + public void cachesFuncResults() throws Exception { + final Func func = new StickyFunc<>( + input -> new SecureRandom().nextInt() + ); + MatcherAssert.assertThat( + func.apply(true) + func.apply(true), + Matchers.equalTo(func.apply(true) + func.apply(true)) + ); + } + +} diff --git a/src/test/java/org/cactoos/func/StickyScalarTest.java b/src/test/java/org/cactoos/func/StickyScalarTest.java new file mode 100644 index 0000000000..0e16476e24 --- /dev/null +++ b/src/test/java/org/cactoos/func/StickyScalarTest.java @@ -0,0 +1,53 @@ +/** + * 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.security.SecureRandom; +import org.cactoos.Scalar; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.Test; + +/** + * Test case for {@link StickyScalar}. + * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @since 0.4 + * @checkstyle JavadocMethodCheck (500 lines) + */ +public final class StickyScalarTest { + + @Test + public void cachesScalarResults() throws Exception { + final Scalar scalar = new StickyScalar<>( + () -> new SecureRandom().nextInt() + ); + MatcherAssert.assertThat( + scalar.asValue() + scalar.asValue(), + Matchers.equalTo(scalar.asValue() + scalar.asValue()) + ); + } + +} diff --git a/src/test/java/org/cactoos/func/TernaryTest.java b/src/test/java/org/cactoos/func/TernaryTest.java new file mode 100644 index 0000000000..873c7b92d3 --- /dev/null +++ b/src/test/java/org/cactoos/func/TernaryTest.java @@ -0,0 +1,64 @@ +/** + * 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.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.Test; + +/** + * Test case for {@link Ternary}. + * + * @author Vseslav Sekorin (vssekorin@gmail.com) + * @version $Id$ + * @since 0.8 + * @checkstyle JavadocMethodCheck (500 lines) + * @checkstyle MagicNumberCheck (500 lines) + */ +public final class TernaryTest { + + @Test + public void conditionTrue() throws Exception { + MatcherAssert.assertThat( + new Ternary<>( + new True(), + 6, + 16 + ).asValue(), + Matchers.equalTo(6) + ); + } + + @Test + public void conditionFalse() throws Exception { + MatcherAssert.assertThat( + new Ternary<>( + new False(), + 6, + 16 + ).asValue(), + Matchers.equalTo(16) + ); + } +} diff --git a/src/test/java/org/cactoos/func/TrueTest.java b/src/test/java/org/cactoos/func/TrueTest.java new file mode 100644 index 0000000000..cd446c6612 --- /dev/null +++ b/src/test/java/org/cactoos/func/TrueTest.java @@ -0,0 +1,47 @@ +/** + * 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.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.Test; + +/** + * Test case for {@link True}. + * + * @author Vseslav Sekorin (vssekorin@gmail.com) + * @version $Id$ + * @since 0.7 + * @checkstyle JavadocMethodCheck (500 lines) + */ +public final class TrueTest { + + @Test + public void asValue() throws Exception { + MatcherAssert.assertThat( + new True().asValue(), + Matchers.equalTo(true) + ); + } +} diff --git a/src/test/java/org/cactoos/func/UncheckedFuncTest.java b/src/test/java/org/cactoos/func/UncheckedFuncTest.java index 1ec4ee5fa8..c6da6ab170 100644 --- a/src/test/java/org/cactoos/func/UncheckedFuncTest.java +++ b/src/test/java/org/cactoos/func/UncheckedFuncTest.java @@ -24,6 +24,7 @@ package org.cactoos.func; import java.io.IOException; +import java.io.UncheckedIOException; import org.cactoos.Func; import org.junit.Test; @@ -37,7 +38,7 @@ */ public final class UncheckedFuncTest { - @Test(expected = RuntimeException.class) + @Test(expected = UncheckedIOException.class) public void rethrowsCheckedToUncheckedException() { new UncheckedFunc<>( (Func) i -> { diff --git a/src/test/java/org/cactoos/func/UncheckedProcTest.java b/src/test/java/org/cactoos/func/UncheckedProcTest.java index 5e0c7d1699..59361df323 100644 --- a/src/test/java/org/cactoos/func/UncheckedProcTest.java +++ b/src/test/java/org/cactoos/func/UncheckedProcTest.java @@ -24,6 +24,7 @@ package org.cactoos.func; import java.io.IOException; +import java.io.UncheckedIOException; import org.junit.Test; /** @@ -36,7 +37,7 @@ */ public final class UncheckedProcTest { - @Test(expected = RuntimeException.class) + @Test(expected = UncheckedIOException.class) public void rethrowsCheckedToUncheckedException() { new UncheckedProc<>( input -> { diff --git a/src/test/java/org/cactoos/func/UncheckedScalarTest.java b/src/test/java/org/cactoos/func/UncheckedScalarTest.java new file mode 100644 index 0000000000..55d5766236 --- /dev/null +++ b/src/test/java/org/cactoos/func/UncheckedScalarTest.java @@ -0,0 +1,49 @@ +/** + * 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 java.io.UncheckedIOException; +import org.junit.Test; + +/** + * Test case for {@link UncheckedScalar}. + * + * @author Fabricio Cabral (fabriciofx@gmail.com) + * @version $Id$ + * @since 0.3 + * @checkstyle JavadocMethodCheck (500 lines) + */ +public final class UncheckedScalarTest { + + @Test(expected = UncheckedIOException.class) + public void rethrowsCheckedToUncheckedException() { + new UncheckedScalar<>( + () -> { + throw new IOException("intended"); + } + ).asValue(); + } + +} diff --git a/src/test/java/org/cactoos/io/InputAsBytesTest.java b/src/test/java/org/cactoos/io/InputAsBytesTest.java index 9268b1740f..202807517d 100644 --- a/src/test/java/org/cactoos/io/InputAsBytesTest.java +++ b/src/test/java/org/cactoos/io/InputAsBytesTest.java @@ -23,8 +23,13 @@ */ package org.cactoos.io; +import java.io.ByteArrayInputStream; import java.io.IOException; +import java.io.InputStream; import java.nio.charset.StandardCharsets; +import java.util.concurrent.atomic.AtomicBoolean; +import org.cactoos.func.FuncAsMatcher; +import org.cactoos.text.BytesAsText; import org.cactoos.text.StringAsText; import org.cactoos.text.TextAsBytes; import org.hamcrest.MatcherAssert; @@ -38,6 +43,7 @@ * @version $Id$ * @since 0.1 * @checkstyle JavadocMethodCheck (500 lines) + * @checkstyle ClassDataAbstractionCouplingCheck (500 lines) */ public final class InputAsBytesTest { @@ -84,4 +90,36 @@ public void readsInputIntoBytesWithSmallBuffer() throws IOException { ); } + @Test + public void closesInputStream() throws IOException { + final AtomicBoolean closed = new AtomicBoolean(); + final InputStream input = new ByteArrayInputStream( + "how are you?".getBytes() + ); + MatcherAssert.assertThat( + "Can't close InputStream correctly", + new BytesAsText( + new InputAsBytes( + new InputStreamAsInput( + new InputStream() { + @Override + public int read() throws IOException { + return input.read(); + } + @Override + public void close() throws IOException { + input.close(); + closed.set(true); + } + } + ) + ).asBytes(), + StandardCharsets.UTF_8 + ).asString(), + new FuncAsMatcher<>( + text -> closed.get() + ) + ); + } + } diff --git a/src/test/java/org/cactoos/io/InputAsPropertiesTest.java b/src/test/java/org/cactoos/io/InputAsPropertiesTest.java new file mode 100644 index 0000000000..b4938f1445 --- /dev/null +++ b/src/test/java/org/cactoos/io/InputAsPropertiesTest.java @@ -0,0 +1,56 @@ +/** + * 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.io; + +import java.util.Properties; +import org.cactoos.ScalarHasValue; +import org.cactoos.func.FuncAsMatcher; +import org.hamcrest.MatcherAssert; +import org.junit.Test; + +/** + * Test case for {@link InputAsProperties}. + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @since 0.8 + * @checkstyle JavadocMethodCheck (500 lines) + */ +public final class InputAsPropertiesTest { + + @Test + public void readsInputContent() { + MatcherAssert.assertThat( + "Can't read properties from an input", + new InputAsProperties( + "foo=Hello, world!\nbar=works fine?\n" + ), + new ScalarHasValue<>( + new FuncAsMatcher( + props -> "Hello, world!".equals(props.getProperty("foo")) + ) + ) + ); + } + +} diff --git a/src/test/java/org/cactoos/io/LengthOfInputTest.java b/src/test/java/org/cactoos/io/LengthOfInputTest.java index 1e34a08b31..ace424e8c6 100644 --- a/src/test/java/org/cactoos/io/LengthOfInputTest.java +++ b/src/test/java/org/cactoos/io/LengthOfInputTest.java @@ -23,11 +23,13 @@ */ package org.cactoos.io; +import java.io.IOException; import java.nio.charset.StandardCharsets; import org.cactoos.ScalarHasValue; import org.cactoos.text.StringAsText; import org.cactoos.text.TextAsBytes; import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; import org.junit.Test; /** @@ -66,4 +68,19 @@ public void calculatesZeroLength() { ); } + @Test + public void readsRealUrl() throws IOException { + MatcherAssert.assertThat( + "Can't calculate length of a real page at the URL", + new LengthOfInput( + new UrlAsInput( + // @checkstyle LineLength (1 line) + "file:src/test/resources/org/cactoos/large-text.txt" + ) + ).asValue(), + // @checkstyle MagicNumber (1 line) + Matchers.equalTo(73471L) + ); + } + } diff --git a/src/test/java/org/cactoos/io/NotNullInputTest.java b/src/test/java/org/cactoos/io/NotNullInputTest.java new file mode 100644 index 0000000000..fe64040b24 --- /dev/null +++ b/src/test/java/org/cactoos/io/NotNullInputTest.java @@ -0,0 +1,43 @@ +/** + * 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.io; + +import java.io.IOException; +import org.junit.Test; + +/** + * Test case for {@link NotNullInput}. + * @author Fabricio Cabral (fabriciofx@gmail.com) + * @version $Id$ + * @since 0.3 + * @checkstyle JavadocMethodCheck (500 lines) + */ +public final class NotNullInputTest { + + @Test(expected = IOException.class) + public void failForNullInput() throws IOException { + new NotNullInput(null).stream(); + } + +} diff --git a/src/test/java/org/cactoos/io/NotNullOutputTest.java b/src/test/java/org/cactoos/io/NotNullOutputTest.java new file mode 100644 index 0000000000..4004e7e748 --- /dev/null +++ b/src/test/java/org/cactoos/io/NotNullOutputTest.java @@ -0,0 +1,43 @@ +/** + * 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.io; + +import java.io.IOException; +import org.junit.Test; + +/** + * Test case for {@link NotNullInput}. + * @author Fabricio Cabral (fabriciofx@gmail.com) + * @version $Id$ + * @since 0.3 + * @checkstyle JavadocMethodCheck (500 lines) + */ +public final class NotNullOutputTest { + + @Test(expected = IOException.class) + public void failForNullOutput() throws IOException { + new NotNullOutput(null).stream(); + } + +} diff --git a/src/test/java/org/cactoos/io/ResourceAsInputTest.java b/src/test/java/org/cactoos/io/ResourceAsInputTest.java index 20e2e9474e..cf3a7e9d25 100644 --- a/src/test/java/org/cactoos/io/ResourceAsInputTest.java +++ b/src/test/java/org/cactoos/io/ResourceAsInputTest.java @@ -23,7 +23,9 @@ */ package org.cactoos.io; +import java.io.IOException; import java.util.Arrays; +import org.cactoos.text.BytesAsText; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Test; @@ -39,7 +41,7 @@ public final class ResourceAsInputTest { @Test - public void readResourceTest() throws Exception { + public void readsBinaryResource() throws Exception { MatcherAssert.assertThat( "Can't read bytes from a classpath resource", Arrays.copyOfRange( @@ -61,4 +63,46 @@ public void readResourceTest() throws Exception { ); } + @Test + public void readsTextResource() throws Exception { + MatcherAssert.assertThat( + "Can't read a text resource from classpath", + new BytesAsText( + new InputAsBytes( + new ResourceAsInput( + "org/cactoos/large-text.txt" + ) + ) + ).asString(), + Matchers.endsWith("est laborum.\n") + ); + } + + @Test + public void readAbsentResourceTest() throws Exception { + MatcherAssert.assertThat( + "Can't replace an absent resource with a text", + new BytesAsText( + new InputAsBytes( + new ResourceAsInput( + "foo/this-resource-is-definitely-absent.txt", + "the replacement" + ) + ) + ).asString(), + Matchers.endsWith("replacement") + ); + } + + @Test(expected = IOException.class) + public void throwsWhenResourceIsAbsent() throws Exception { + new BytesAsText( + new InputAsBytes( + new ResourceAsInput( + "bar/this-resource-is-definitely-absent.txt" + ) + ) + ).asString(); + } + } diff --git a/src/test/java/org/cactoos/io/StickyInputTest.java b/src/test/java/org/cactoos/io/StickyInputTest.java new file mode 100644 index 0000000000..6fb0a631bd --- /dev/null +++ b/src/test/java/org/cactoos/io/StickyInputTest.java @@ -0,0 +1,86 @@ +/** + * 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.io; + +import org.cactoos.Input; +import org.cactoos.TextHasString; +import org.cactoos.func.FuncAsMatcher; +import org.cactoos.func.RepeatedFunc; +import org.cactoos.text.BytesAsText; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.Test; + +/** + * Test case for {@link StickyInput}. + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @since 0.6 + * @checkstyle JavadocMethodCheck (500 lines) + * @checkstyle ClassDataAbstractionCouplingCheck (500 lines) + */ +public final class StickyInputTest { + + @Test + public void readsFileContent() { + MatcherAssert.assertThat( + "Can't read bytes from a file", + new StickyInput( + new ResourceAsInput( + "org/cactoos/large-text.txt" + ) + ), + new FuncAsMatcher<>( + new RepeatedFunc( + input -> new InputAsBytes( + new TeeInput(input, new DeadOutput()) + // @checkstyle MagicNumber (2 lines) + ).asBytes().length == 73471, + 10 + ) + ) + ); + } + + @Test + public void readsRealUrl() { + MatcherAssert.assertThat( + "Can't fetch text page from the URL", + new BytesAsText( + new InputAsBytes( + new StickyInput( + new UrlAsInput( + // @checkstyle LineLength (1 line) + "file:src/test/resources/org/cactoos/large-text.txt" + ) + ) + ) + ), + new TextHasString( + Matchers.endsWith("est laborum.\n") + ) + ); + } + +} diff --git a/src/test/java/org/cactoos/io/TeeInputStreamTest.java b/src/test/java/org/cactoos/io/TeeInputStreamTest.java new file mode 100644 index 0000000000..11f12c4376 --- /dev/null +++ b/src/test/java/org/cactoos/io/TeeInputStreamTest.java @@ -0,0 +1,81 @@ +/** + * 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.io; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.Test; + +/** + * Test case for {@link TeeInputStream}. + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @since 0.1 + * @checkstyle JavadocMethodCheck (500 lines) + * @checkstyle ClassDataAbstractionCouplingCheck (500 lines) + */ +public final class TeeInputStreamTest { + + @Test + public void copiesContentByteByByte() throws IOException { + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + final String content = "Hello, товарищ!"; + MatcherAssert.assertThat( + "Can't copy InputStream to OutputStream byte by byte", + TeeInputStreamTest.asString( + new TeeInputStream( + new ByteArrayInputStream( + content.getBytes(StandardCharsets.UTF_8) + ), + baos + ) + ), + Matchers.allOf( + Matchers.equalTo(content), + Matchers.equalTo( + new String(baos.toByteArray(), StandardCharsets.UTF_8) + ) + ) + ); + } + + private static String asString(final InputStream input) throws IOException { + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + while (true) { + final int data = input.read(); + if (data < 0) { + break; + } + baos.write(data); + } + input.close(); + return new String(baos.toByteArray(), StandardCharsets.UTF_8); + } + +} diff --git a/src/test/java/org/cactoos/io/TeeInputTest.java b/src/test/java/org/cactoos/io/TeeInputTest.java index ca14a5550c..93914a8e30 100644 --- a/src/test/java/org/cactoos/io/TeeInputTest.java +++ b/src/test/java/org/cactoos/io/TeeInputTest.java @@ -31,7 +31,6 @@ import org.cactoos.TextHasString; import org.cactoos.func.FuncAsMatcher; import org.cactoos.text.BytesAsText; -import org.cactoos.text.StringAsText; import org.cactoos.text.TextAsBytes; import org.hamcrest.MatcherAssert; import org.junit.Test; @@ -79,14 +78,7 @@ public void copiesToFile() throws IOException { "Can't copy Input to File and return content", new BytesAsText( new InputAsBytes( - new TeeInput( - new BytesAsInput( - new TextAsBytes( - new StringAsText("Hello, друг!") - ) - ), - new PathAsOutput(temp) - ) + new TeeInput("Hello, друг!", temp) ) ), new TextHasString( diff --git a/src/test/java/org/cactoos/io/UncheckedBytesTest.java b/src/test/java/org/cactoos/io/UncheckedBytesTest.java new file mode 100644 index 0000000000..11d1641b65 --- /dev/null +++ b/src/test/java/org/cactoos/io/UncheckedBytesTest.java @@ -0,0 +1,48 @@ +/** + * 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.io; + +import java.io.IOException; +import org.junit.Test; + +/** + * Test case for {@link UncheckedBytes}. + * + * @author Fabricio Cabral (fabriciofx@gmail.com) + * @version $Id$ + * @since 0.3 + * @checkstyle JavadocMethodCheck (500 lines) + */ +public final class UncheckedBytesTest { + + @Test(expected = RuntimeException.class) + public void rethrowsCheckedToUncheckedException() { + new UncheckedBytes( + () -> { + throw new IOException("intended"); + } + ).asBytes(); + } + +} diff --git a/src/test/java/org/cactoos/io/UrlAsInputTest.java b/src/test/java/org/cactoos/io/UrlAsInputTest.java index 3a011ccfa4..dc5583708f 100644 --- a/src/test/java/org/cactoos/io/UrlAsInputTest.java +++ b/src/test/java/org/cactoos/io/UrlAsInputTest.java @@ -63,9 +63,7 @@ public void readsRealUrl() throws IOException { "Can't fetch bytes from the URL", new BytesAsText( new InputAsBytes( - new UrlAsInput( - home.toURL() - ) + new UrlAsInput(home) ) ), new TextHasString( @@ -78,4 +76,20 @@ public void readsRealUrl() throws IOException { ); } + @Test + public void readsStringUrl() { + MatcherAssert.assertThat( + "Can't fetch bytes from the HTTPS URL", + new BytesAsText( + new InputAsBytes( + new UrlAsInput( + // @checkstyle LineLength (1 line) + "file:src/test/resources/org/cactoos/large-text.txt" + ) + ) + ), + new TextHasString(Matchers.containsString("Lorem ipsum")) + ); + } + } diff --git a/src/test/java/org/cactoos/list/AnyOfTest.java b/src/test/java/org/cactoos/list/ArrayAsIterableTest.java similarity index 77% rename from src/test/java/org/cactoos/list/AnyOfTest.java rename to src/test/java/org/cactoos/list/ArrayAsIterableTest.java index 884478e128..2e5ea64713 100644 --- a/src/test/java/org/cactoos/list/AnyOfTest.java +++ b/src/test/java/org/cactoos/list/ArrayAsIterableTest.java @@ -23,30 +23,27 @@ */ package org.cactoos.list; -import org.cactoos.ScalarHasValue; import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; import org.junit.Test; /** - * Test case for {@link AnyOf}. + * Test case for {@link ArrayAsIterable}. * @author Yegor Bugayenko (yegor256@gmail.com) * @version $Id$ - * @since 0.1 + * @since 0.7 * @checkstyle JavadocMethodCheck (500 lines) */ -public final class AnyOfTest { +public final class ArrayAsIterableTest { @Test - public void iteratesList() { + public void convertsArrayToIterable() { MatcherAssert.assertThat( - "Can't iterate a list", - new AnyOf( - new TransformedIterable<>( - new ArrayAsIterable<>("a", "file", "is", "corrupt"), - txt -> txt.length() > 2 - ) + "Can't convert array to iterable", + new ArrayAsIterable<>( + "hello", "world" ), - new ScalarHasValue<>(true) + Matchers.iterableWithSize(2) ); } diff --git a/src/test/java/org/cactoos/list/ConcatenatedIterableTest.java b/src/test/java/org/cactoos/list/ConcatIterableTest.java similarity index 91% rename from src/test/java/org/cactoos/list/ConcatenatedIterableTest.java rename to src/test/java/org/cactoos/list/ConcatIterableTest.java index 4cd4662c36..04ecce3b8b 100644 --- a/src/test/java/org/cactoos/list/ConcatenatedIterableTest.java +++ b/src/test/java/org/cactoos/list/ConcatIterableTest.java @@ -28,21 +28,20 @@ import org.junit.Test; /** - * Test case for {@link ConcatenatedIterable}. + * Test case for {@link ConcatIterable}. * @author Yegor Bugayenko (yegor256@gmail.com) * @version $Id$ * @since 0.1 * @checkstyle JavadocMethodCheck (500 lines) */ -public final class ConcatenatedIterableTest { +public final class ConcatIterableTest { @Test - @SuppressWarnings("unchecked") public void transformsList() { MatcherAssert.assertThat( "Can't concatenate iterables together", new LengthOfIterable( - new ConcatenatedIterable<>( + new ConcatIterable( new ArrayAsIterable<>("hello", "world", "друг"), new ArrayAsIterable<>("how", "are", "you"), new ArrayAsIterable<>("what's", "up") diff --git a/src/test/java/org/cactoos/list/CycledIterableTest.java b/src/test/java/org/cactoos/list/CycledIterableTest.java new file mode 100644 index 0000000000..503d471f03 --- /dev/null +++ b/src/test/java/org/cactoos/list/CycledIterableTest.java @@ -0,0 +1,72 @@ +/** + * 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.list; + +import java.util.Collections; +import org.cactoos.ScalarHasValue; +import org.hamcrest.MatcherAssert; +import org.junit.Test; + +/** + * Test Case for {@link CycledIterable}. + * @author Ilia Rogozhin (ilia.rogozhin@gmail.com) + * @version $Id$ + * @since 0.8 + * @checkstyle JavadocMethodCheck (500 lines) + */ +public final class CycledIterableTest { + + @Test + public void repeatIterableTest() throws Exception { + final String expected = "two"; + MatcherAssert.assertThat( + "Can't repeat iterable", + new ItemOfIterable<>( + new CycledIterable<>( + new ArrayAsIterable<>( + "one", expected, "three" + ) + ), + // @checkstyle MagicNumberCheck (1 line)< + 7 + ), + new ScalarHasValue<>( + expected + ) + ); + } + + @Test() + public void notCycledEmptyTest() throws Exception { + MatcherAssert.assertThat( + "Can't generate an empty iterable", + new LengthOfIterable( + new CycledIterable<>( + Collections::emptyIterator + ) + ), + new ScalarHasValue<>(0) + ); + } +} diff --git a/src/test/java/org/cactoos/list/CycledIteratorTest.java b/src/test/java/org/cactoos/list/CycledIteratorTest.java new file mode 100644 index 0000000000..e60efa0763 --- /dev/null +++ b/src/test/java/org/cactoos/list/CycledIteratorTest.java @@ -0,0 +1,67 @@ +/** + * 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.list; + +import java.util.Collections; +import java.util.NoSuchElementException; +import org.cactoos.ScalarHasValue; +import org.hamcrest.MatcherAssert; +import org.junit.Test; + +/** + * Test Case for {@link CycledIterator}. + * @author Ilia Rogozhin (ilia.rogozhin@gmail.com) + * @version $Id$ + * @since 0.8 + * @checkstyle JavadocMethodCheck (500 lines) + */ +public final class CycledIteratorTest { + + @Test + public void repeatIteratorTest() throws Exception { + final String expected = "two"; + MatcherAssert.assertThat( + "Can't repeat iterator", + new ItemOfIterator<>( + new CycledIterator<>( + new ArrayAsIterable<>( + "one", expected, "three" + ) + ), + // @checkstyle MagicNumberCheck (1 line) + 7 + ), + new ScalarHasValue<>( + expected + ) + ); + } + + @Test(expected = NoSuchElementException.class) + public void notCycledEmptyTest() throws Exception { + new CycledIterator<>( + Collections::emptyIterator + ).next(); + } +} diff --git a/src/test/java/org/cactoos/list/ItemOfIterableTest.java b/src/test/java/org/cactoos/list/ItemOfIterableTest.java new file mode 100644 index 0000000000..d2222a61dd --- /dev/null +++ b/src/test/java/org/cactoos/list/ItemOfIterableTest.java @@ -0,0 +1,84 @@ +/** + * 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.list; + +import java.io.IOException; +import java.util.Collections; +import org.cactoos.ScalarHasValue; +import org.hamcrest.MatcherAssert; +import org.junit.Test; + +/** + * Test case for {@link ItemOfIterable}. + * + * @author Kirill (g4s8.public@gmail.com) + * @version $Id$ + * @since 0.7 + * @checkstyle JavadocMethodCheck (500 lines) + */ +public final class ItemOfIterableTest { + + @Test + public void firstElementTest() throws Exception { + MatcherAssert.assertThat( + "Can't take the first item from the iterable", + new ItemOfIterable<>( + // @checkstyle MagicNumber (1 line) + new ArrayAsIterable<>(1, 2, 3) + ), + new ScalarHasValue<>(1) + ); + } + + @Test + public void elementByPosTest() throws Exception { + MatcherAssert.assertThat( + "Can't take the item by position from the iterable", + new ItemOfIterable<>( + // @checkstyle MagicNumber (1 line) + new ArrayAsIterable<>(1, 2, 3), + 1 + ), + new ScalarHasValue<>(2) + ); + } + + @Test(expected = IOException.class) + public void failForEmptyCollectionTest() throws Exception { + new ItemOfIterable<>(Collections.emptyList()).asValue(); + } + + @Test + public void fallbackTest() throws Exception { + final String fallback = "fallback"; + MatcherAssert.assertThat( + "Can't fallback to default value", + new ItemOfIterable<>( + Collections.emptyList(), + fallback + ), + new ScalarHasValue<>(fallback) + ); + } +} diff --git a/src/test/java/org/cactoos/list/ItemOfIteratorTest.java b/src/test/java/org/cactoos/list/ItemOfIteratorTest.java new file mode 100644 index 0000000000..d103b16dd7 --- /dev/null +++ b/src/test/java/org/cactoos/list/ItemOfIteratorTest.java @@ -0,0 +1,101 @@ +/** + * 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.list; + +import java.io.IOException; +import java.util.Collections; +import org.cactoos.ScalarHasValue; +import org.hamcrest.MatcherAssert; +import org.junit.Test; + +/** + * Test Case for {@link ItemOfIterator}. + * @author Ilia Rogozhin (ilia.rogozhin@gmail.com) + * @version $Id$ + * @since 0.7 + * @checkstyle JavadocMethodCheck (500 lines) + */ +public final class ItemOfIteratorTest { + + @Test + public void firstElementTest() throws Exception { + MatcherAssert.assertThat( + "Can't take the first item from the iterator", + new ItemOfIterator<>( + // @checkstyle MagicNumber (1 line) + new ArrayAsIterable<>(1, 2, 3).iterator() + ), + new ScalarHasValue<>(1) + ); + } + + @Test + public void elementByPosTest() throws Exception { + MatcherAssert.assertThat( + "Can't take the item by position from the iterator", + new ItemOfIterator<>( + // @checkstyle MagicNumber (1 line) + new ArrayAsIterable<>(1, 2, 3).iterator(), + 1 + ), + new ScalarHasValue<>(2) + ); + } + + @Test(expected = IOException.class) + public void failForEmptyCollectionTest() throws Exception { + new ItemOfIterator<>(Collections.emptyIterator()).asValue(); + } + + @Test(expected = IOException.class) + public void failForNegativePositionTest() throws Exception { + new ItemOfIterator<>( + // @checkstyle MagicNumber (1 line) + new ArrayAsIterable<>(1, 2, 3).iterator(), + -1 + ).asValue(); + } + + @Test + public void fallbackTest() throws Exception { + final String fallback = "fallback"; + MatcherAssert.assertThat( + "Can't fallback to default value", + new ItemOfIterator<>( + Collections.emptyIterator(), + fallback + ), + new ScalarHasValue<>(fallback) + ); + } + + @Test(expected = IOException.class) + public void failForPosMoreLengthTest() throws Exception { + new ItemOfIterator<>( + // @checkstyle MagicNumberCheck (2 lines) + new ArrayAsIterable<>(1, 2, 3).iterator(), + 3 + ).asValue(); + } +} diff --git a/src/test/java/org/cactoos/list/IterableAsListTest.java b/src/test/java/org/cactoos/list/IterableAsListTest.java index 53ccd5a1ce..393b1a1d6a 100644 --- a/src/test/java/org/cactoos/list/IterableAsListTest.java +++ b/src/test/java/org/cactoos/list/IterableAsListTest.java @@ -24,6 +24,8 @@ package org.cactoos.list; import java.util.Collections; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Test; @@ -43,10 +45,7 @@ public void elementAtIndexTest() throws Exception { final int num = 345; MatcherAssert.assertThat( "Can't convert an iterable to a list", - new IterableAsList<>( - // @checkstyle MagicNumber (2 lines) - new ArrayAsIterable<>(0, 1, 2, num, 3, 4) - ).get(3), + new IterableAsList<>(-1, num, 0, 1).get(1), Matchers.equalTo(num) ); } @@ -85,4 +84,18 @@ public void highBoundTest() throws Exception { // @checkstyle MagicNumber (1 line) new IterableAsList<>(Collections.nCopies(10, 0)).get(11); } + + @Test + public void sensesChangesInIterable() throws Exception { + final AtomicInteger size = new AtomicInteger(2); + final List list = new IterableAsList<>( + () -> Collections.nCopies(size.incrementAndGet(), 0).iterator() + ); + MatcherAssert.assertThat( + "Can't sense the changes in the underlying iterable", + list.size(), + Matchers.not(Matchers.equalTo(list.size())) + ); + } + } diff --git a/src/test/java/org/cactoos/list/IterableAsMapTest.java b/src/test/java/org/cactoos/list/IterableAsMapTest.java new file mode 100644 index 0000000000..4f99ff62ce --- /dev/null +++ b/src/test/java/org/cactoos/list/IterableAsMapTest.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.list; + +import java.security.SecureRandom; +import java.util.AbstractMap; +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.Test; + +/** + * Test case for {@link IterableAsMap}. + * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @since 0.4 + * @checkstyle JavadocMethodCheck (500 lines) + */ +public final class IterableAsMapTest { + + @Test + public void convertsIterableToMap() { + MatcherAssert.assertThat( + "Can't convert iterable to map", + new IterableAsMap( + new AbstractMap.SimpleEntry<>(0, "hello, "), + new AbstractMap.SimpleEntry<>(1, "world!") + ), + Matchers.hasEntry( + Matchers.equalTo(0), + Matchers.startsWith("hello") + ) + ); + } + + @Test + public void sensesChangesInMap() throws Exception { + final AtomicInteger size = new AtomicInteger(2); + final Map map = new IterableAsMap<>( + () -> new RepeatIterator<>( + () -> new AbstractMap.SimpleEntry<>( + new SecureRandom().nextInt(), + 1 + ), + size.incrementAndGet() + ) + ); + MatcherAssert.assertThat( + "Can't sense the changes in the underlying map", + map.size(), + Matchers.not(Matchers.equalTo(map.size())) + ); + } + +} diff --git a/src/test/java/org/cactoos/list/LimitedIterableTest.java b/src/test/java/org/cactoos/list/LimitedIterableTest.java new file mode 100644 index 0000000000..0032496bf3 --- /dev/null +++ b/src/test/java/org/cactoos/list/LimitedIterableTest.java @@ -0,0 +1,104 @@ +/** + * 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.list; + +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.Test; + +/** + * Test case for {@link LimitedIterable}. + * + * @author Dusan Rychnovsky (dusan.rychnovsky@gmail.com) + * @version $Id$ + * @since 0.6 + * @checkstyle JavadocMethodCheck (500 lines) + */ +public final class LimitedIterableTest { + + @Test + public void iteratesOverPrefixOfGivenLength() { + // @checkstyle MagicNumber (7 lines) + MatcherAssert.assertThat( + "Can't limit an iterable with more items", + new LimitedIterable<>( + new ArrayAsIterable<>(0, 1, 2, 3, 4), + 3 + ), + Matchers.contains(0, 1, 2) + ); + } + + @Test + public void iteratesOverWholeIterableIfThereAreNotEnoughItems() { + // @checkstyle MagicNumber (7 lines) + MatcherAssert.assertThat( + "Can't limit an iterable with less items", + new LimitedIterable<>( + new ArrayAsIterable<>(0, 1, 2, 3, 4), + 10 + ), + Matchers.contains(0, 1, 2, 3, 4) + ); + } + + @Test + public void limitOfZeroProducesEmptyIterable() { + // @checkstyle MagicNumber (7 lines) + MatcherAssert.assertThat( + "Can't limit an iterable to zero items", + new LimitedIterable<>( + new ArrayAsIterable<>(0, 1, 2, 3, 4), + 0 + ), + Matchers.iterableWithSize(0) + ); + } + + @Test + public void negativeLimitProducesEmptyIterable() { + // @checkstyle MagicNumber (7 lines) + MatcherAssert.assertThat( + "Can't limit an iterable to negative number of items", + new LimitedIterable<>( + new ArrayAsIterable<>(0, 1, 2, 3, 4), + -1 + ), + Matchers.iterableWithSize(0) + ); + } + + @Test + public void emptyIterableProducesEmptyIterable() { + // @checkstyle MagicNumber (7 lines) + MatcherAssert.assertThat( + "Can't limit an empty iterable", + new LimitedIterable<>( + new ArrayAsIterable<>(), + 10 + ), + Matchers.iterableWithSize(0) + ); + } +} diff --git a/src/test/java/org/cactoos/list/MapAsPropertiesTest.java b/src/test/java/org/cactoos/list/MapAsPropertiesTest.java new file mode 100644 index 0000000000..75cf15409a --- /dev/null +++ b/src/test/java/org/cactoos/list/MapAsPropertiesTest.java @@ -0,0 +1,88 @@ +/** + * 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.list; + +import java.security.SecureRandom; +import java.util.AbstractMap; +import java.util.Properties; +import java.util.concurrent.atomic.AtomicInteger; +import org.cactoos.ScalarHasValue; +import org.cactoos.func.FuncAsMatcher; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.Test; + +/** + * Test case for {@link MapAsProperties}. + * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @since 0.7 + * @checkstyle JavadocMethodCheck (500 lines) + * @checkstyle ClassDataAbstractionCouplingCheck (500 lines) + */ +public final class MapAsPropertiesTest { + + @Test + public void convertsMapToProperties() { + MatcherAssert.assertThat( + "Can't convert map to properties", + new MapAsProperties( + new StickyMap<>( + new IterableAsMap( + new AbstractMap.SimpleEntry<>(0, "hello, world"), + new AbstractMap.SimpleEntry<>(1, "how are you?") + ) + ) + ), + new ScalarHasValue<>( + new FuncAsMatcher( + props -> props.getProperty("0").endsWith(", world") + ) + ) + ); + } + + @Test + public void sensesChangesInMap() throws Exception { + final AtomicInteger size = new AtomicInteger(2); + final MapAsProperties props = new MapAsProperties( + new IterableAsMap<>( + () -> new RepeatIterator<>( + () -> new AbstractMap.SimpleEntry<>( + new SecureRandom().nextInt(), + 1 + ), + size.incrementAndGet() + ) + ) + ); + MatcherAssert.assertThat( + "Can't sense the changes in the underlying map", + props.asValue().size(), + Matchers.not(Matchers.equalTo(props.asValue().size())) + ); + } + +} diff --git a/src/test/java/org/cactoos/list/TransformedIterableTest.java b/src/test/java/org/cactoos/list/MappedIterableTest.java similarity index 92% rename from src/test/java/org/cactoos/list/TransformedIterableTest.java rename to src/test/java/org/cactoos/list/MappedIterableTest.java index b2e8cf1153..2f0fa290e8 100644 --- a/src/test/java/org/cactoos/list/TransformedIterableTest.java +++ b/src/test/java/org/cactoos/list/MappedIterableTest.java @@ -33,19 +33,19 @@ import org.junit.Test; /** - * Test case for {@link TransformedIterable}. + * Test case for {@link MappedIterable}. * @author Yegor Bugayenko (yegor256@gmail.com) * @version $Id$ * @since 0.1 * @checkstyle JavadocMethodCheck (500 lines) */ -public final class TransformedIterableTest { +public final class MappedIterableTest { @Test public void transformsList() throws IOException { MatcherAssert.assertThat( "Can't transform an iterable", - new TransformedIterable( + new MappedIterable( new ArrayAsIterable<>( "hello", "world", "друг" ), @@ -59,7 +59,7 @@ public void transformsList() throws IOException { public void transformsEmptyList() { MatcherAssert.assertThat( "Can't transform an empty iterable", - new TransformedIterable( + new MappedIterable( Collections.emptyList(), input -> new UpperText(new StringAsText(input)) ), diff --git a/src/test/java/org/cactoos/list/NaturalNumbersTest.java b/src/test/java/org/cactoos/list/NaturalNumbersTest.java new file mode 100644 index 0000000000..5a442f1371 --- /dev/null +++ b/src/test/java/org/cactoos/list/NaturalNumbersTest.java @@ -0,0 +1,59 @@ +/** + * 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.list; + +import org.cactoos.ScalarHasValue; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.Test; + +/** + * Test case for {@link NaturalNumbers}. + * + * @author Tim Hinkes (timmeey@timmeey.de) + * @version $Id$ + * @since 0.7 + * @checkstyle JavadocMethodCheck (500 lines) + */ +public final class NaturalNumbersTest { + + @Test + public void containsSequentialNaturalNumbers() { + MatcherAssert.assertThat( + "Can't get sequential natural numbers", + new NaturalNumbers(), + // @checkstyle MagicNumber (1 line) + Matchers.hasItems(0L, 1L, 5L, 10L) + ); + } + + @Test + public void notStartsWithNegativeNumbers() { + MatcherAssert.assertThat( + "Contains negative Numbers", + new ItemOfIterable(new NaturalNumbers(), 0), + new ScalarHasValue<>(0L) + ); + } +} diff --git a/src/test/java/org/cactoos/list/RepeatTest.java b/src/test/java/org/cactoos/list/RepeatIterableTest.java similarity index 92% rename from src/test/java/org/cactoos/list/RepeatTest.java rename to src/test/java/org/cactoos/list/RepeatIterableTest.java index b459d49cd9..93ad2fe43a 100644 --- a/src/test/java/org/cactoos/list/RepeatTest.java +++ b/src/test/java/org/cactoos/list/RepeatIterableTest.java @@ -28,14 +28,14 @@ import org.junit.Test; /** - * Test case for {@link Repeat}. + * Test case for {@link RepeatIterable}. * * @author Kirill (g4s8.public@gmail.com) * @version $Id$ * @since 0.1 * @checkstyle JavadocMethodCheck (500 lines) */ -public final class RepeatTest { +public final class RepeatIterableTest { @Test public void allSameTest() throws Exception { @@ -45,7 +45,7 @@ public void allSameTest() throws Exception { "Can't generate an iterable with fixed size", new LengthOfIterable( new FilteredIterable<>( - new Repeat<>( + new RepeatIterable<>( element, size ), @@ -61,7 +61,7 @@ public void emptyTest() throws Exception { MatcherAssert.assertThat( "Can't generate an empty iterable", new LengthOfIterable( - new Repeat<>(0, 0) + new RepeatIterable<>(0, 0) ), new ScalarHasValue<>(0) ); diff --git a/src/test/java/org/cactoos/list/RepeatIteratorTest.java b/src/test/java/org/cactoos/list/RepeatIteratorTest.java new file mode 100644 index 0000000000..0ade5e6dfe --- /dev/null +++ b/src/test/java/org/cactoos/list/RepeatIteratorTest.java @@ -0,0 +1,65 @@ +/** + * 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.list; + +import org.cactoos.ScalarHasValue; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.Test; + +/** + * Test case for {@link RepeatIterator}. + * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @since 0.4 + * @checkstyle JavadocMethodCheck (500 lines) + */ +public final class RepeatIteratorTest { + + @Test + public void allSameTest() throws Exception { + final int size = 42; + final int element = 11; + MatcherAssert.assertThat( + "Can't generate an iterable with fixed size", + new LengthOfIterator( + new RepeatIterator<>( + element, + size + ) + ), + new ScalarHasValue<>(size) + ); + } + + @Test + public void emptyTest() throws Exception { + MatcherAssert.assertThat( + "Can't generate an empty iterator", + (Iterable) () -> new RepeatIterator<>(0, 0), + Matchers.iterableWithSize(0) + ); + } +} diff --git a/src/test/java/org/cactoos/list/SkippedIterableTest.java b/src/test/java/org/cactoos/list/SkippedIterableTest.java new file mode 100644 index 0000000000..be13d8ce58 --- /dev/null +++ b/src/test/java/org/cactoos/list/SkippedIterableTest.java @@ -0,0 +1,57 @@ +/** + * 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.list; + +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.Test; + +/** + * Test Case for {@link SkippedIterable}. + * @author Ilia Rogozhin (ilia.rogozhin@gmail.com) + * @version $Id$ + * @since 0.8 + * @checkstyle JavadocMethodCheck (500 lines) + */ +public final class SkippedIterableTest { + + @Test + @SuppressWarnings("PMD.AvoidDuplicateLiterals") + public void skipIterable() throws Exception { + MatcherAssert.assertThat( + "Can't skip elements in iterable", + new SkippedIterable<>( + new ArrayAsIterable<>( + "one", "two", "three", "four" + ), + 2 + ), + Matchers.contains( + "three", + "four" + ) + ); + } + +} diff --git a/src/test/java/org/cactoos/list/SkippedIteratorTest.java b/src/test/java/org/cactoos/list/SkippedIteratorTest.java new file mode 100644 index 0000000000..1bbd485af6 --- /dev/null +++ b/src/test/java/org/cactoos/list/SkippedIteratorTest.java @@ -0,0 +1,67 @@ +/** + * 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.list; + +import java.util.NoSuchElementException; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.Test; + +/** + * Test Case for {@link SkippedIterator}. + * @author Ilia Rogozhin (ilia.rogozhin@gmail.com) + * @version $Id$ + * @since 0.8 + * @checkstyle JavadocMethodCheck (500 lines) + */ +public final class SkippedIteratorTest { + + @Test + @SuppressWarnings("PMD.AvoidDuplicateLiterals") + public void skipIterator() throws Exception { + MatcherAssert.assertThat( + "Can't skip elements in iterator", + () -> new SkippedIterator<>( + new ArrayAsIterable<>( + "one", "two", "three", "four" + ).iterator(), + 2 + ), + Matchers.contains( + "three", + "four" + ) + ); + } + + @Test(expected = NoSuchElementException.class) + public void errorSkippedMoreThanExists() throws Exception { + new SkippedIterator<>( + new ArrayAsIterable<>( + "one", "two" + ).iterator(), + 2 + ).next(); + } +} diff --git a/src/test/java/org/cactoos/list/SortedIterableTest.java b/src/test/java/org/cactoos/list/SortedIterableTest.java new file mode 100644 index 0000000000..afce12b66f --- /dev/null +++ b/src/test/java/org/cactoos/list/SortedIterableTest.java @@ -0,0 +1,82 @@ +/** + * 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.list; + +import java.util.Collections; +import java.util.Comparator; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.Test; + +/** + * Test case for {@link SortedIterable}. + * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @since 0.7 + * @checkstyle JavadocMethodCheck (500 lines) + * @checkstyle MagicNumberCheck (500 lines) + */ +public final class SortedIterableTest { + + @Test + public void sortsAnArray() throws Exception { + MatcherAssert.assertThat( + "Can't sort an iterable", + new SortedIterable<>( + new ArrayAsIterable<>( + 3, 2, 10, 44, -6, 0 + ) + ), + Matchers.hasItems(-6, 0, 2, 3, 10, 44) + ); + } + + @Test + @SuppressWarnings("PMD.AvoidDuplicateLiterals") + public void sortsAnArrayWithComparator() throws Exception { + MatcherAssert.assertThat( + "Can't sort an iterable with a comparator", + new SortedIterable<>( + Comparator.reverseOrder(), + new ArrayAsIterable<>( + "a", "c", "hello", "dude", "Friend" + ) + ), + Matchers.hasItems("hello", "dude", "c", "a", "Friend") + ); + } + + @Test + public void sortsAnEmptyArray() throws Exception { + MatcherAssert.assertThat( + "Can't sort an empty iterable", + new SortedIterable( + Collections.emptyList() + ), + Matchers.iterableWithSize(0) + ); + } + +} diff --git a/src/test/java/org/cactoos/list/StickyIterableTest.java b/src/test/java/org/cactoos/list/StickyIterableTest.java new file mode 100644 index 0000000000..f42e358e51 --- /dev/null +++ b/src/test/java/org/cactoos/list/StickyIterableTest.java @@ -0,0 +1,57 @@ +/** + * 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.list; + +import java.util.Collections; +import java.util.concurrent.atomic.AtomicInteger; +import org.cactoos.ScalarHasValue; +import org.hamcrest.MatcherAssert; +import org.junit.Test; + +/** + * Test case for {@link StickyIterable}. + * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @since 0.8 + * @checkstyle JavadocMethodCheck (500 lines) + */ +public final class StickyIterableTest { + + @Test + public void ignoresChangesInIterable() throws Exception { + final AtomicInteger size = new AtomicInteger(2); + final Iterable list = new StickyIterable<>( + new IterableAsList<>( + () -> Collections.nCopies(size.incrementAndGet(), 0).iterator() + ) + ); + MatcherAssert.assertThat( + "Can't ignore the changes in the underlying iterable", + new LengthOfIterable(list), + new ScalarHasValue<>(new LengthOfIterable(list).asValue()) + ); + } + +} diff --git a/src/test/java/org/cactoos/list/StickyIteratorTest.java b/src/test/java/org/cactoos/list/StickyIteratorTest.java new file mode 100644 index 0000000000..99a3aab6db --- /dev/null +++ b/src/test/java/org/cactoos/list/StickyIteratorTest.java @@ -0,0 +1,68 @@ +/** + * 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.list; + +import java.util.concurrent.atomic.AtomicInteger; +import org.cactoos.Text; +import org.cactoos.TextHasString; +import org.cactoos.text.FormattedText; +import org.hamcrest.MatcherAssert; +import org.junit.Test; + +/** + * Test case for {@link StickyIterator}. + * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @since 0.8 + * @checkstyle JavadocMethodCheck (500 lines) + */ +public final class StickyIteratorTest { + + @Test + public void ignoresChangesInIterable() throws Exception { + final AtomicInteger count = new AtomicInteger(2); + final Text text = new FormattedText( + "%s", + String.join( + ", ", + () -> new MappedIterator<>( + new StickyIterator<>( + new LimitedIterator<>( + new EndlessIterator<>(count::incrementAndGet), + 2 + ) + ), + Object::toString + ) + ) + ); + MatcherAssert.assertThat( + "Can't ignore the changes in the underlying iterator", + text, + new TextHasString(text.asString()) + ); + } + +} diff --git a/src/test/java/org/cactoos/list/StickyListTest.java b/src/test/java/org/cactoos/list/StickyListTest.java new file mode 100644 index 0000000000..b62dfa3a58 --- /dev/null +++ b/src/test/java/org/cactoos/list/StickyListTest.java @@ -0,0 +1,67 @@ +/** + * 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.list; + +import java.util.Collections; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.Test; + +/** + * Test case for {@link StickyList}. + * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @since 0.8 + * @checkstyle JavadocMethodCheck (500 lines) + */ +public final class StickyListTest { + + @Test + public void ignoresChangesInIterable() throws Exception { + final AtomicInteger size = new AtomicInteger(2); + final List list = new StickyList<>( + new IterableAsList<>( + () -> Collections.nCopies(size.incrementAndGet(), 0).iterator() + ) + ); + MatcherAssert.assertThat( + "Can't ignore the changes in the underlying iterable", + list.size(), + Matchers.equalTo(list.size()) + ); + } + + @Test + public void decoratesArray() throws Exception { + MatcherAssert.assertThat( + "Can't decorate an array of numbers", + new StickyList<>(-1, 0).size(), + Matchers.equalTo(2) + ); + } + +} diff --git a/src/test/java/org/cactoos/list/StickyMapTest.java b/src/test/java/org/cactoos/list/StickyMapTest.java new file mode 100644 index 0000000000..a37fbd7cb5 --- /dev/null +++ b/src/test/java/org/cactoos/list/StickyMapTest.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.list; + +import java.security.SecureRandom; +import java.util.AbstractMap; +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.Test; + +/** + * Test case for {@link StickyMap}. + * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @since 0.8 + * @checkstyle JavadocMethodCheck (500 lines) + */ +public final class StickyMapTest { + + @Test + public void ignoresChangesInMap() throws Exception { + final AtomicInteger size = new AtomicInteger(2); + final Map map = new StickyMap<>( + new IterableAsMap<>( + () -> new RepeatIterator<>( + () -> new AbstractMap.SimpleEntry<>( + new SecureRandom().nextInt(), + 1 + ), + size.incrementAndGet() + ) + ) + ); + MatcherAssert.assertThat( + "Can't ignore the changes in the underlying map", + map.size(), + Matchers.equalTo(map.size()) + ); + } + + @Test + public void decoratesEntries() throws Exception { + MatcherAssert.assertThat( + "Can't decorate a list of entries", + new StickyMap( + new AbstractMap.SimpleEntry<>("first", "Jeffrey"), + new AbstractMap.SimpleEntry<>("last", "Lebowski") + ), + Matchers.hasValue(Matchers.endsWith("ski")) + ); + } + +} diff --git a/src/test/java/org/cactoos/text/JoinedTextTest.java b/src/test/java/org/cactoos/text/JoinedTextTest.java new file mode 100644 index 0000000000..b5f971781c --- /dev/null +++ b/src/test/java/org/cactoos/text/JoinedTextTest.java @@ -0,0 +1,62 @@ +/** + * 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.TextHasString; +import org.hamcrest.MatcherAssert; +import org.junit.Test; + +/** + * Test case for {@link JoinedText}. + * @author Fabricio Cabral (fabriciofx@gmail.com) + * @version $Id$ + * @since 0.9 + * @checkstyle JavadocMethodCheck (500 lines) + */ +public final class JoinedTextTest { + + @Test + public void joinsStrings() throws IOException { + MatcherAssert.assertThat( + "Can't join strings", + new JoinedText(" ", "hello", "world"), + new TextHasString("hello world") + ); + } + + @Test + public void joinsTexts() throws IOException { + MatcherAssert.assertThat( + "Can't join texts", + new JoinedText( + " ", + new StringAsText("foo"), + new StringAsText("bar") + ), + new TextHasString("foo bar") + ); + } + +} diff --git a/src/test/java/org/cactoos/text/NormalizedTextTest.java b/src/test/java/org/cactoos/text/NormalizedTextTest.java new file mode 100644 index 0000000000..cb3bbfb81b --- /dev/null +++ b/src/test/java/org/cactoos/text/NormalizedTextTest.java @@ -0,0 +1,49 @@ +/** + * 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.TextHasString; +import org.hamcrest.MatcherAssert; +import org.junit.Test; + +/** + * Test case for {@link NormalizedText}. + * @author Fabricio Cabral (fabriciofx@gmail.com) + * @version $Id$ + * @since 0.9 + * @checkstyle JavadocMethodCheck (500 lines) + */ +public final class NormalizedTextTest { + + @Test + public void normalizesText() throws IOException { + MatcherAssert.assertThat( + "Can't normalize a text", + new NormalizedText(" \t hello \t\tworld \t"), + new TextHasString("hello world") + ); + } + +} diff --git a/src/test/java/org/cactoos/list/FirstOfTest.java b/src/test/java/org/cactoos/text/NotNullTextTest.java similarity index 69% rename from src/test/java/org/cactoos/list/FirstOfTest.java rename to src/test/java/org/cactoos/text/NotNullTextTest.java index 0ee7e79a22..76fca6fa16 100644 --- a/src/test/java/org/cactoos/list/FirstOfTest.java +++ b/src/test/java/org/cactoos/text/NotNullTextTest.java @@ -21,39 +21,37 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package org.cactoos.list; +package org.cactoos.text; import java.io.IOException; -import java.util.Arrays; -import java.util.Collections; -import org.cactoos.ScalarHasValue; +import org.cactoos.TextHasString; import org.hamcrest.MatcherAssert; import org.junit.Test; /** - * Test case for {@link FirstOf}. - * - * @author Kirill (g4s8.public@gmail.com) + * Test case for {@link NotNullText}. + * @author Fabricio Cabral (fabriciofx@gmail.com) * @version $Id$ - * @since 0.1 + * @since 0.3 * @checkstyle JavadocMethodCheck (500 lines) */ -public final class FirstOfTest { +public final class NotNullTextTest { + + @Test(expected = IOException.class) + public void failForNullText() throws IOException { + new NotNullText(null).asString(); + } @Test - public void firstElementTest() throws Exception { + public void checkForNullText() throws Exception { + final String message = "Hello"; MatcherAssert.assertThat( - "Can't take the first item from the iterable", - new FirstOf<>( - // @checkstyle MagicNumber (1 line) - Arrays.asList(1, 2, 3) + "Can't work with null text", + new NotNullText( + new StringAsText(message) ), - new ScalarHasValue<>(1) + new TextHasString(message) ); } - @Test(expected = IOException.class) - public void failForEmptyCollectionTest() throws Exception { - new FirstOf<>(Collections.emptyList()).asValue(); - } } diff --git a/src/test/java/org/cactoos/text/RepeatedTextTest.java b/src/test/java/org/cactoos/text/RepeatedTextTest.java new file mode 100644 index 0000000000..75971ba590 --- /dev/null +++ b/src/test/java/org/cactoos/text/RepeatedTextTest.java @@ -0,0 +1,58 @@ +/** + * 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 org.cactoos.TextHasString; +import org.hamcrest.MatcherAssert; +import org.junit.Test; + +/** + * Test case for {@link RepeatedText}. + * @author Fabricio Cabral (fabriciofx@gmail.com) + * @version $Id$ + * @since 0.9 + * @checkstyle JavadocMethodCheck (500 lines) + */ +public final class RepeatedTextTest { + + @Test + public void repeatsWordsText() { + MatcherAssert.assertThat( + "Can't repeats a text", + // @checkstyle MagicNumber (1 line) + new RepeatedText("hello", 2), + new TextHasString("hellohello") + ); + } + + @Test + public void repeatsCharText() { + MatcherAssert.assertThat( + "Can't repeats a char", + // @checkstyle MagicNumber (1 line) + new RepeatedText("A", 5), + new TextHasString("AAAAA") + ); + } +} diff --git a/src/test/java/org/cactoos/text/ReplacedTextTest.java b/src/test/java/org/cactoos/text/ReplacedTextTest.java index 345360294c..211f5f742c 100644 --- a/src/test/java/org/cactoos/text/ReplacedTextTest.java +++ b/src/test/java/org/cactoos/text/ReplacedTextTest.java @@ -61,4 +61,17 @@ public void notReplaceTextWhenSubstringNotFound() { new TextHasString(text) ); } + + @Test + public void replacesAllOccurrences() { + MatcherAssert.assertThat( + "Can't replace a text with multiple needle occurrences", + new ReplacedText( + new StringAsText("one cat, two cats, three cats"), + "cat", + "dog" + ), + new TextHasString("one dog, two dogs, three dogs") + ); + } } diff --git a/src/test/java/org/cactoos/text/ReversedTextTest.java b/src/test/java/org/cactoos/text/ReversedTextTest.java new file mode 100644 index 0000000000..3f688656d6 --- /dev/null +++ b/src/test/java/org/cactoos/text/ReversedTextTest.java @@ -0,0 +1,61 @@ +/** + * 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 org.cactoos.TextHasString; +import org.hamcrest.MatcherAssert; +import org.junit.Test; + +/** + * Test case for {@link ReversedText}. + * + * @author Mehmet Yildirim (memoyil@gmail.com) + * @version $Id$ + * @since 0.2 + * @checkstyle JavadocMethodCheck (500 lines) + */ +public final class ReversedTextTest { + + @Test + public void reverseText() { + MatcherAssert.assertThat( + "Can't reverse a text", + new ReversedText( + new StringAsText("Hello!") + ), + new TextHasString("!olleH") + ); + } + + @Test + public void reversedEmptyTextIsEmptyText() { + MatcherAssert.assertThat( + "Can't reverse empty text", + new ReversedText( + new StringAsText("") + ), + new TextHasString("") + ); + } +} diff --git a/src/test/java/org/cactoos/text/StringAsUrlTest.java b/src/test/java/org/cactoos/text/StringAsUrlTest.java new file mode 100644 index 0000000000..6f2f04266f --- /dev/null +++ b/src/test/java/org/cactoos/text/StringAsUrlTest.java @@ -0,0 +1,48 @@ +/** + * 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 org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.Test; + +/** + * Test case for {@link StringAsUrl}. + * @author Fabricio Cabral (fabriciofx@gmail.com) + * @version $Id$ + * @since 0.4 + * @checkstyle JavadocMethodCheck (500 lines) + */ +public final class StringAsUrlTest { + + @Test + public void encodeStringToUrl() throws Exception { + MatcherAssert.assertThat( + "Can't encode a string as URL", + new StringAsUrl("друг").asValue(), + Matchers.equalTo("%D0%B4%D1%80%D1%83%D0%B3") + ); + } + +} diff --git a/src/test/java/org/cactoos/text/TextAsBoolTest.java b/src/test/java/org/cactoos/text/TextAsBoolTest.java index 0d8281a303..5ddb3265a8 100644 --- a/src/test/java/org/cactoos/text/TextAsBoolTest.java +++ b/src/test/java/org/cactoos/text/TextAsBoolTest.java @@ -55,4 +55,13 @@ public void falseTest() throws IOException { Matchers.equalTo(false) ); } + + @Test + public void isFalseIfTextDoesNotRepresentABoolean() throws IOException { + MatcherAssert.assertThat( + "Can't parse a non-boolean string", + new TextAsBool("abc").asValue(), + Matchers.equalTo(false) + ); + } } diff --git a/src/test/java/org/cactoos/text/TextAsDoubleTest.java b/src/test/java/org/cactoos/text/TextAsDoubleTest.java index 367a6b5e1a..bd8f5d1cf0 100644 --- a/src/test/java/org/cactoos/text/TextAsDoubleTest.java +++ b/src/test/java/org/cactoos/text/TextAsDoubleTest.java @@ -47,4 +47,9 @@ public strictfp void numberTest() throws IOException { Matchers.equalTo(185.65156465123) ); } + + @Test(expected = NumberFormatException.class) + public void failsIfTextDoesNotRepresentADouble() throws IOException { + new TextAsDouble("abc").asValue(); + } } diff --git a/src/test/java/org/cactoos/text/TextAsFloatTest.java b/src/test/java/org/cactoos/text/TextAsFloatTest.java index af0a634578..c6fbebed01 100644 --- a/src/test/java/org/cactoos/text/TextAsFloatTest.java +++ b/src/test/java/org/cactoos/text/TextAsFloatTest.java @@ -47,4 +47,9 @@ public strictfp void numberTest() throws IOException { Matchers.equalTo(1656.894F) ); } + + @Test(expected = NumberFormatException.class) + public void failsIfTextDoesNotRepresentAFloat() throws IOException { + new TextAsFloat("abc").asValue(); + } } diff --git a/src/test/java/org/cactoos/text/TextAsIntTest.java b/src/test/java/org/cactoos/text/TextAsIntTest.java index cf4b162afb..d999ff2da2 100644 --- a/src/test/java/org/cactoos/text/TextAsIntTest.java +++ b/src/test/java/org/cactoos/text/TextAsIntTest.java @@ -47,4 +47,9 @@ public void numberTest() throws IOException { Matchers.equalTo(1867892354) ); } + + @Test(expected = NumberFormatException.class) + public void failsIfTextDoesNotRepresentAnInt() throws IOException { + new TextAsDouble("abc").asValue(); + } } diff --git a/src/test/java/org/cactoos/text/TextAsLongTest.java b/src/test/java/org/cactoos/text/TextAsLongTest.java index b3a2749a9f..1a8ae4334f 100644 --- a/src/test/java/org/cactoos/text/TextAsLongTest.java +++ b/src/test/java/org/cactoos/text/TextAsLongTest.java @@ -47,4 +47,9 @@ public void numberTest() throws IOException { Matchers.equalTo(186789235425346L) ); } + + @Test(expected = NumberFormatException.class) + public void failsIfTextDoesNotRepresentALong() throws IOException { + new TextAsLong("abc").asValue(); + } } diff --git a/src/test/java/org/cactoos/text/TrimmedTextTest.java b/src/test/java/org/cactoos/text/TrimmedTextTest.java index 2225c1c454..c97ed4096e 100644 --- a/src/test/java/org/cactoos/text/TrimmedTextTest.java +++ b/src/test/java/org/cactoos/text/TrimmedTextTest.java @@ -45,4 +45,12 @@ public void convertsText() { ); } + @Test + public void trimmedBlankTextIsEmptyText() { + MatcherAssert.assertThat( + "Can't trim a blank text", + new TrimmedText(new StringAsText(" \t ")), + new TextHasString("") + ); + } } diff --git a/src/test/java/org/cactoos/text/UncheckedTextTest.java b/src/test/java/org/cactoos/text/UncheckedTextTest.java new file mode 100644 index 0000000000..339dff67eb --- /dev/null +++ b/src/test/java/org/cactoos/text/UncheckedTextTest.java @@ -0,0 +1,48 @@ +/** + * 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.junit.Test; + +/** + * Test case for {@link UncheckedText}. + * + * @author Fabricio Cabral (fabriciofx@gmail.com) + * @version $Id$ + * @since 0.3 + * @checkstyle JavadocMethodCheck (500 lines) + */ +public final class UncheckedTextTest { + + @Test(expected = RuntimeException.class) + public void rethrowsCheckedToUncheckedException() { + new UncheckedText( + () -> { + throw new IOException("intended"); + } + ).asString(); + } + +} diff --git a/src/test/java/org/cactoos/text/UrlAsStringTest.java b/src/test/java/org/cactoos/text/UrlAsStringTest.java new file mode 100644 index 0000000000..f90b23a106 --- /dev/null +++ b/src/test/java/org/cactoos/text/UrlAsStringTest.java @@ -0,0 +1,48 @@ +/** + * 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 org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.Test; + +/** + * Test case for {@link UrlAsString}. + * @author Fabricio Cabral (fabriciofx@gmail.com) + * @version $Id$ + * @since 0.4 + * @checkstyle JavadocMethodCheck (500 lines) + */ +public final class UrlAsStringTest { + + @Test + public void decodeUrlToString() throws Exception { + MatcherAssert.assertThat( + "Can't convert a string to URL", + new UrlAsString("%D0%B0%20%D1%8F").asValue(), + Matchers.equalTo("а я") + ); + } + +} diff --git a/src/test/resources/org/cactoos/large-text.txt b/src/test/resources/org/cactoos/large-text.txt new file mode 100644 index 0000000000..35e7dc4868 --- /dev/null +++ b/src/test/resources/org/cactoos/large-text.txt @@ -0,0 +1,1147 @@ +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum.