Skip to content

Commit

Permalink
Merge pull request yegor256#1 from yegor256/master
Browse files Browse the repository at this point in the history
Up
  • Loading branch information
bedward70 authored Nov 9, 2017
2 parents 377b5e6 + f806833 commit 9c912b3
Show file tree
Hide file tree
Showing 46 changed files with 1,192 additions and 323 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[![Build Status](https://travis-ci.org/yegor256/cactoos.svg?branch=master)](https://travis-ci.org/yegor256/cactoos)
[![Build status](https://ci.appveyor.com/api/projects/status/8vs8huy61og6jwif?svg=true)](https://ci.appveyor.com/project/yegor256/cactoos)
[![Javadoc](https://javadoc-emblem.rhcloud.com/doc/org.cactoos/cactoos/badge.svg?color=blue&prefix=v)](http://www.javadoc.io/doc/org.cactoos/cactoos)
[![Javadoc](http://www.javadoc.io/badge/org.cactoos/cactoos.svg)](http://www.javadoc.io/doc/org.cactoos/cactoos)
[![PDD status](http://www.0pdd.com/svg?name=yegor256/cactoos)](http://www.0pdd.com/p?name=yegor256/cactoos)
[![Maven Central](https://img.shields.io/maven-central/v/org.cactoos/cactoos.svg)](https://maven-badges.herokuapp.com/maven-central/org.cactoos/cactoos)
[![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/yegor256/cactoos/blob/master/LICENSE.txt)
Expand Down Expand Up @@ -242,6 +242,10 @@ Cactoos | Guava | Apache Commons | JDK 8
`TrimmedText` | - | `StringUtils.stripAll()` | `String#trim()`
`UpperText` | - | - | `String#toUpperCase()`

## Questions

Ask your questions related to cactoos library on [Stackoverflow](https://stackoverflow.com/questions/ask) with [cactoos](https://stackoverflow.com/tags/cactoos/info) tag.

## How to contribute?

Just fork the repo and send us a pull request.
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/cactoos/BiFunc.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
/**
* Function that accepts two arguments.
*
* <p>If you don't want to have any checked exceptions being thrown
* out of your {@link BiFunc}, you can use
* {@link org.cactoos.func.UncheckedBiFunc} decorator. Also
* you may try {@link org.cactoos.func.IoCheckedBiFunc}.</p>
*
* <p>There is no thread-safety guarantee.
*
* @author Yegor Bugayenko (yegor256@gmail.com)
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/cactoos/BiProc.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
/**
* Proc that accepts two arguments.
*
* <p>If you don't want to have any checked exceptions being thrown
* out of your {@link BiProc}, you can use
* {@link org.cactoos.func.UncheckedBiProc} decorator. Also
* you may try {@link org.cactoos.func.IoCheckedBiProc}.</p>
*
* <p>There is no thread-safety guarantee.
*
* @author Yegor Bugayenko (yegor256@gmail.com)
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/org/cactoos/Input.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,17 @@
* new InputOf(new File("/tmp/names.txt"))
* ).asString();</pre>
*
* <p>Here {@link InputOf} implements {@link Input} and behaves like
* one, providing read-only access to the encapsulated {@link java.io.File}.</p>
* <p>Here {@link org.cactoos.io.InputOf} implements
* {@link Input} and behaves like
* one, providing read-only access to
* the encapsulated {@link java.io.File}.</p>
*
* <p>There is no thread-safety guarantee.
*
* @author Yegor Bugayenko (yegor256@gmail.com)
* @author Fabricio Cabral (fabriciofx@gmail.com)
* @version $Id$
* @see InputOf
* @see org.cactoos.io.InputOf
* @since 0.1
*/
public interface Input {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/cactoos/Output.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
* @author Yegor Bugayenko (yegor256@gmail.com)
* @version $Id$
* @see OutputTo
* @see org.cactoos.io.OutputTo
* @since 0.1
*/
public interface Output {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/cactoos/Proc.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
/**
* Procedure.
*
* <p>If you don't want to have any checked exceptions being thrown
* out of your {@link Proc}, you can use
* {@link org.cactoos.func.UncheckedProc} decorator. Also
* you may try {@link org.cactoos.func.IoCheckedProc}.</p>
*
* <p>There is no thread-safety guarantee.
*
* @author Yegor Bugayenko (yegor256@gmail.com)
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/cactoos/Text.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
/**
* Text.
*
* <p>If you don't want to have any checked exceptions being thrown
* out of your {@link Text}, you can use
* {@link UncheckedText} decorator.</p>
*
* <p>There is no thread-safety guarantee.
*
* @author Yegor Bugayenko (yegor256@gmail.com)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,49 +21,38 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.cactoos.scalar;

package org.cactoos.bytes;

import java.io.IOException;
import org.cactoos.Scalar;
import org.cactoos.Text;
import org.cactoos.text.TextOf;
import java.util.Base64;
import org.cactoos.Bytes;

/**
* Text as {@link Long}.
*
* <p>There is no thread-safety guarantee.
* Decodes all origin bytes using the Base64 encoding scheme.
*
* @author Kirill (g4s8.public@gmail.com)
* @author Ilia Rogozhin (ilia.rogozhin@gmail.com)
* @version $Id$
* @since 0.2
* @since 0.20.2
*/
public final class LongOf implements Scalar<Long> {

/**
* Source text.
*/
private final Text origin;
public final class Base64Bytes implements Bytes {

/**
* Ctor.
*
* @param string Number-string
* Origin bytes.
*/
public LongOf(final String string) {
this(new TextOf(string));
}
private final Bytes origin;

/**
* Ctor.
*
* @param text Number-text
* @param origin Origin bytes
*/
public LongOf(final Text text) {
this.origin = text;
public Base64Bytes(final Bytes origin) {
this.origin = origin;
}

@Override
public Long value() throws IOException {
return Long.valueOf(this.origin.asString());
public byte[] asBytes() throws IOException {
return Base64.getDecoder().decode(this.origin.asBytes());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,49 +21,37 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.cactoos.scalar;

package org.cactoos.bytes;

import java.io.IOException;
import org.cactoos.Scalar;
import org.cactoos.Text;
import org.cactoos.text.TextOf;
import java.util.Base64;
import org.cactoos.Bytes;

/**
* Text as {@link Float}.
*
* <p>There is no thread-safety guarantee.
* Encodes all origin bytes using the Base64 encoding scheme.
*
* @author Kirill (g4s8.public@gmail.com)
* @author Ilia Rogozhin (ilia.rogozhin@gmail.com)
* @version $Id$
* @since 0.2
* @since 0.20.2
*/
public final class FloatOf implements Scalar<Float> {
public final class BytesBase64 implements Bytes {

/**
* Source text.
* Origin bytes.
*/
private final Text origin;

/**
* Ctor.
*
* @param string Number-string
*/
public FloatOf(final String string) {
this(new TextOf(string));
}
private final Bytes origin;

/**
* Ctor.
*
* @param text Number-text
* @param origin Origin bytes.
*/
public FloatOf(final Text text) {
this.origin = text;
public BytesBase64(final Bytes origin) {
this.origin = origin;
}

@Override
public Float value() throws IOException {
return Float.valueOf(this.origin.asString());
public byte[] asBytes() throws IOException {
return Base64.getEncoder().encode(this.origin.asBytes());
}
}
32 changes: 32 additions & 0 deletions src/main/java/org/cactoos/bytes/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2017 Yegor Bugayenko
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

/**
* Bytes.
*
* @author Ilia Rogozhin (ilia.rogozhin@gmail.com)
* @version $Id$
* @since 0.20.2
*/
package org.cactoos.bytes;
78 changes: 78 additions & 0 deletions src/main/java/org/cactoos/func/IoCheckedBiProc.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2017 Yegor Bugayenko
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.cactoos.func;

import java.io.IOException;
import org.cactoos.BiProc;

/**
* BiProc that doesn't throw checked {@link Exception}, but throws
* {@link IOException} instead.
*
* <p>There is no thread-safety guarantee.
*
* @author Yegor Bugayenko (yegor256@gmail.com)
* @version $Id$
* @param <X> Type of input
* @param <Y> Type of input
* @since 0.22
*/
public final class IoCheckedBiProc<X, Y> implements BiProc<X, Y> {

/**
* Original proc.
*/
private final BiProc<X, Y> proc;

/**
* Ctor.
* @param prc Encapsulated func
*/
public IoCheckedBiProc(final BiProc<X, Y> prc) {
this.proc = prc;
}

@Override
@SuppressWarnings
(
{
"PMD.AvoidCatchingGenericException",
"PMD.AvoidRethrowingException"
}
)
public void exec(final X first, final Y second) throws IOException {
try {
this.proc.exec(first, second);
} catch (final IOException ex) {
throw ex;
} catch (final InterruptedException ex) {
Thread.currentThread().interrupt();
throw new IOException(ex);
// @checkstyle IllegalCatchCheck (1 line)
} catch (final Exception ex) {
throw new IOException(ex);
}
}

}
45 changes: 45 additions & 0 deletions src/main/java/org/cactoos/func/MaxFunc.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2017 Yegor Bugayenko
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.cactoos.func;

import org.cactoos.BiFunc;

/**
* Function, finding max among two items.
*
* @author Alexander Dyadyushenko (gookven@gmail.com)
* @version $Id$
* @param <T> comparable type
* @since 0.9
*/
public final class MaxFunc<T extends Comparable<T>> implements BiFunc<T, T, T> {
@Override
public T apply(final T first, final T second) throws Exception {
T max = first;
if (second.compareTo(max) > 0) {
max = second;
}
return max;
}
}
Loading

0 comments on commit 9c912b3

Please sign in to comment.