forked from yegor256/cactoos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master' into padded-text-start
* upstream/master: yegor256#123: fixed yegor256#123: bug yegor256#121: fixed yegor256#121: bug doc doc blog names yegor256#116 package removed yegor256#119: StickyScalar fixed yegor256#116: IterableAsMap Switched to non Cached size Refactored IterableAsList to remove unnecessary call to size() and remove not working cache
- Loading branch information
Showing
11 changed files
with
478 additions
and
69 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,7 +53,7 @@ Java version required: 1.8+. | |
|
||
## Input/Output | ||
|
||
To read a file: | ||
To read a text file in UTF-8: | ||
|
||
```java | ||
String text = new BytesAsText( | ||
|
@@ -86,7 +86,7 @@ To read a binary file from classpath: | |
|
||
```java | ||
byte[] data = new InputAsBytes( | ||
new ResourceAsInput("/foo/img.jpg") | ||
new ResourceAsInput("foo/img.jpg") | ||
).asBytes(); | ||
``` | ||
|
||
|
@@ -145,12 +145,11 @@ To iterate a collection: | |
new AllOf( | ||
new TransformedIterable<>( | ||
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(); | ||
``` | ||
|
@@ -160,7 +159,9 @@ Or even more compact: | |
```java | ||
new IterableAsBoolean( | ||
new ArrayAsIterable<>("how", "are", "you"), | ||
(Func.Quiet<String>) i -> System.out.printf("Item: %s\n", i) | ||
new ProcAsFunc<>( | ||
input -> System.out.printf("Item: %s\n", i) | ||
) | ||
).asValue(); | ||
``` | ||
|
||
|
@@ -246,13 +247,15 @@ Note: [Checkstyle](https://en.wikipedia.org/wiki/Checkstyle) is used as a static | |
|
||
## Contributors | ||
|
||
- [Yegor Bugayenko](https://github.com/yegor256) | ||
- [Kirill Che.](https://github.com/g4s8) [email protected] | ||
- [Fabrício Cabral](https://github.com/fabriciofx) | ||
- [Andriy Kryvtsun](https://github.com/englishman) | ||
- [Vseslav Sekorin](https://github.com/VsSekorin) | ||
- [Andrey Valyaev](https://github.com/DronMDF) | ||
- [Dušan Rychnovský](https://github.com/dusan-rychnovsky) [Blog](http://blog.dusanrychnovsky.cz/) | ||
- [@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 |
---|---|---|
|
@@ -23,8 +23,7 @@ | |
*/ | ||
package org.cactoos.func; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.cactoos.Func; | ||
import org.cactoos.Scalar; | ||
|
||
/** | ||
|
@@ -33,36 +32,30 @@ | |
* <p>There is no thread-safety guarantee. | ||
* | ||
* @author Tim Hinkes ([email protected]) | ||
* @author Yegor Bugayenko ([email protected]) | ||
* @version $Id$ | ||
* @param <T> Type of result | ||
* @since 0.3 | ||
*/ | ||
public final class StickyScalar<T> implements Scalar<T> { | ||
|
||
/** | ||
* The scalar to cache. | ||
* Func. | ||
*/ | ||
private final Scalar<T> source; | ||
|
||
/** | ||
* The list used as a optional value. | ||
*/ | ||
private final List<T> cache; | ||
private final Func<Boolean, T> func; | ||
|
||
/** | ||
* Ctor. | ||
* @param src The Scalar to cache | ||
*/ | ||
public StickyScalar(final Scalar<T> src) { | ||
this.source = src; | ||
this.cache = new ArrayList<>(1); | ||
this.func = new StickyFunc<>( | ||
input -> src.asValue() | ||
); | ||
} | ||
|
||
@Override | ||
public T asValue() throws Exception { | ||
if (this.cache.isEmpty()) { | ||
this.cache.add(this.source.asValue()); | ||
} | ||
return this.cache.get(0); | ||
return this.func.apply(true); | ||
} | ||
} |
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
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.