-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from yegor256/master
Update
- Loading branch information
Showing
164 changed files
with
9,572 additions
and
528 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,25 +145,24 @@ new IterableAsCollection<>( | |
To iterate a collection: | ||
|
||
```java | ||
new AllOf( | ||
new TransformedIterable<>( | ||
new And( | ||
new MappedIterable<>( | ||
new ArrayAsIterable<>("how", "are", "you"), | ||
new Func.Quiet<String>() { | ||
@Override | ||
public void exec(final String input) throws Exception { | ||
new ProcAsFunc<>( | ||
input -> { | ||
System.out.printf("Item: %s\n", input); | ||
} | ||
} | ||
) | ||
) | ||
).asValue(); | ||
``` | ||
|
||
Or even more compact: | ||
|
||
```java | ||
new IterableAsBoolean( | ||
new ArrayAsIterable<>("how", "are", "you"), | ||
(Func.Quiet<String>) 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<String> 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) [email protected] | ||
- [@yegor256](https://github.com/yegor256) as Yegor Bugayenko ([Blog](http://www.yegor256.com)) | ||
- [@g4s8](https://github.com/g4s8) as Kirill Che. ([email protected]) | ||
- [@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) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ | |
* | ||
* @author Yegor Bugayenko ([email protected]) | ||
* @version $Id$ | ||
* @see org.cactoos.text.TextAsBytes | ||
* @since 0.1 | ||
*/ | ||
public interface Bytes { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,12 +26,24 @@ | |
/** | ||
* Function. | ||
* | ||
* <p>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}.</p> | ||
* | ||
* <p>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.</p> | ||
* | ||
* <p>There is no thread-safety guarantee. | ||
* | ||
* @author Yegor Bugayenko ([email protected]) | ||
* @version $Id$ | ||
* @param <X> Type of input | ||
* @param <Y> Type of output | ||
* @see org.cactoos.func.StickyFunc | ||
* @see org.cactoos.func.UncheckedFunc | ||
* @see org.cactoos.func.IoCheckedFunc | ||
* @since 0.1 | ||
*/ | ||
public interface Func<X, Y> { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,9 @@ | |
* | ||
* @author Yegor Bugayenko ([email protected]) | ||
* @version $Id$ | ||
* @see org.cactoos.io.BytesAsInput | ||
* @see FileAsInput | ||
* @see org.cactoos.io.PathAsInput | ||
* @since 0.1 | ||
*/ | ||
public interface Input { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,8 @@ | |
* | ||
* @author Yegor Bugayenko ([email protected]) | ||
* @version $Id$ | ||
* @see FileAsOutput | ||
* @see org.cactoos.io.PathAsOutput | ||
* @since 0.1 | ||
*/ | ||
public interface Output { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ | |
* @author Yegor Bugayenko ([email protected]) | ||
* @version $Id$ | ||
* @param <X> Type of input | ||
* @see org.cactoos.func.ProcAsFunc | ||
* @since 0.1 | ||
*/ | ||
public interface Proc<X> { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,25 +23,35 @@ | |
*/ | ||
package org.cactoos; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Scalar. | ||
* | ||
* <p>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}.</p> | ||
* | ||
* <p>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.</p> | ||
* | ||
* <p>There is no thread-safety guarantee. | ||
* | ||
* @author Yegor Bugayenko ([email protected]) | ||
* @version $Id$ | ||
* @param <T> Type of result | ||
* @see org.cactoos.func.StickyScalar | ||
* @see org.cactoos.func.UncheckedScalar | ||
* @see org.cactoos.func.IoCheckedScalar | ||
* @since 0.1 | ||
*/ | ||
public interface Scalar<T> { | ||
|
||
/** | ||
* Convert it to the value. | ||
* @return The value | ||
* @throws IOException If fails | ||
* @throws Exception If fails | ||
*/ | ||
T asValue() throws IOException; | ||
T asValue() throws Exception; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ | |
* | ||
* @author Yegor Bugayenko ([email protected]) | ||
* @version $Id$ | ||
* @see org.cactoos.text.StringAsText | ||
* @since 0.1 | ||
*/ | ||
public interface Text { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.