Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Jan 31, 2021
2 parents 0fb468c + 49ead45 commit 2eef5c9
Show file tree
Hide file tree
Showing 10 changed files with 232 additions and 65 deletions.
55 changes: 55 additions & 0 deletions src/main/java/org/cactoos/func/BiFuncEnveloppe.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2017-2020 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;

/**
* Enveloppe of {@link BiFunc}.
*
* @param <X> Type of input
* @param <Y> Type of input
* @param <Z> Type of output
* @since 0.50
*/
public abstract class BiFuncEnveloppe<X, Y, Z> implements BiFunc<X, Y, Z> {

/**
* BiFunc to decorate.
*/
private final BiFunc<X, Y, Z> origin;

/**
* Ctor.
* @param func The function
*/
public BiFuncEnveloppe(final BiFunc<X, Y, Z> func) {
this.origin = func;
}

@Override
public final Z apply(final X first, final Y second) throws Exception {
return this.origin.apply(first, second);
}
}
20 changes: 7 additions & 13 deletions src/main/java/org/cactoos/func/BiFuncOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@
* @param <Z> Type of output
* @since 0.20
*/
public final class BiFuncOf<X, Y, Z> implements BiFunc<X, Y, Z> {

/**
* The func.
*/
private final BiFunc<X, Y, Z> func;
public final class BiFuncOf<X, Y, Z> extends BiFuncEnveloppe<X, Y, Z> {

/**
* Ctor.
Expand Down Expand Up @@ -92,14 +87,13 @@ public BiFuncOf(final BiProc<X, Y> proc, final Z result) {

/**
* Ctor.
* @param fnc Func
* @param fnc The func
*/
public BiFuncOf(final BiFunc<X, Y, Z> fnc) {
this.func = fnc;
}

@Override
public Z apply(final X first, final Y second) throws Exception {
return this.func.apply(first, second);
super(
(first, second) -> {
return fnc.apply(first, second);
}
);
}
}
14 changes: 2 additions & 12 deletions src/main/java/org/cactoos/func/SolidBiFunc.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,7 @@
* @param <Z> Type of output
* @since 0.24
*/
public final class SolidBiFunc<X, Y, Z> implements BiFunc<X, Y, Z> {

/**
* Original func.
*/
private final BiFunc<X, Y, Z> func;
public final class SolidBiFunc<X, Y, Z> extends BiFuncEnveloppe<X, Y, Z> {

/**
* Ctor.
Expand All @@ -57,11 +52,6 @@ public SolidBiFunc(final BiFunc<X, Y, Z> fnc) {
* @since 0.26
*/
public SolidBiFunc(final BiFunc<X, Y, Z> fnc, final int max) {
this.func = new SyncBiFunc<>(new StickyBiFunc<>(fnc, max));
}

@Override
public Z apply(final X first, final Y second) throws Exception {
return this.func.apply(first, second);
super(new SyncBiFunc<>(new StickyBiFunc<>(fnc, max)));
}
}
4 changes: 0 additions & 4 deletions src/main/java/org/cactoos/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,5 @@
* @since 0.1
* @see <a href="http://www.cactoos.org">Project site www.cactoos.org</a>
* @see <a href="https://github.com/yegor256/cactoos">GitHub repository</a>
* @todo #1445:30min For consistency sake with Func, let's
* - introduce envelopes for Proc, BiProc, BiFunc, Runnable and Callable
* - have FuncOf, ProcOf, etc extend their envelope to simplify their code
* - apply on other classes that could benefit from it
*/
package org.cactoos;
55 changes: 55 additions & 0 deletions src/main/java/org/cactoos/proc/ProcEnvelope.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2017-2020 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.proc;

import org.cactoos.Proc;

/**
* Envelope for {@link Proc}.
*
* <p>There is no thread-safety guarantee.
*
* @param <X> Type of input
* @since 0.50
*/
public abstract class ProcEnvelope<X> implements Proc<X> {

/**
* Proc to decorate.
*/
private final Proc<X> origin;

/**
* Ctor.
* @param origin The procedure
*/
public ProcEnvelope(final Proc<X> origin) {
this.origin = origin;
}

@Override
public final void exec(final X input) throws Exception {
this.origin.exec(input);
}
}
14 changes: 2 additions & 12 deletions src/main/java/org/cactoos/proc/ProcOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,7 @@
* @param <X> Type of input
* @since 0.12
*/
public final class ProcOf<X> implements Proc<X> {

/**
* The proc.
*/
private final Proc<X> proc;
public final class ProcOf<X> extends ProcEnvelope<X> {

/**
* Ctor.
Expand All @@ -58,11 +53,6 @@ public ProcOf(final Func<X, ?> fnc) {
* @param prc The proc
*/
public ProcOf(final Proc<X> prc) {
this.proc = prc;
}

@Override
public void exec(final X input) throws Exception {
this.proc.exec(input);
super(prc);
}
}
52 changes: 52 additions & 0 deletions src/main/java/org/cactoos/proc/RunnableEnvelope.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2017-2020 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.proc;

/**
* Envelope for Runnable.
*
* <p>There is no thread-safety guarantee.
*
* @since 0.50
*/
public abstract class RunnableEnvelope implements Runnable {

/**
* Runnable to decorate.
*/
private final Runnable origin;

/**
* Ctor.
* @param runnable The Runnable
*/
public RunnableEnvelope(final Runnable runnable) {
this.origin = runnable;
}

@Override
public final void run() {
this.origin.run();
}
}
14 changes: 2 additions & 12 deletions src/main/java/org/cactoos/proc/RunnableOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,7 @@
*
* @since 0.12
*/
public final class RunnableOf implements Runnable {

/**
* Runnable.
*/
private final Runnable runnable;
public final class RunnableOf extends RunnableEnvelope {

/**
* Ctor.
Expand Down Expand Up @@ -75,11 +70,6 @@ public RunnableOf(final Scalar<?> scalar) {
* @since 0.49
*/
public RunnableOf(final Runnable runnable) {
this.runnable = runnable;
}

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

import java.util.concurrent.Callable;

/**
* Envelope for Callable.
*
* <p>There is no thread-safety guarantee.
*
* @param <T> Type of output
* @since 0.50
*/
public abstract class CallableEnvelope<T> implements Callable<T> {

/**
* Callable to decorate.
*/
private final Callable<T> origin;

/**
* Ctor.
* @param callable The Callable
*/
public CallableEnvelope(final Callable<T> callable) {
this.origin = callable;
}

@Override
public final T call() throws Exception {
return this.origin.call();
}
}
14 changes: 2 additions & 12 deletions src/main/java/org/cactoos/scalar/CallableOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,14 @@
* @param <T> Type of output
* @since 0.12
*/
public final class CallableOf<T> implements Callable<T> {

/**
* Original callable.
*/
private final Scalar<T> scalar;
public final class CallableOf<T> extends CallableEnvelope<T> {

/**
* Ctor.
* @param slr Encapsulated scalar
* @since 0.41
*/
public CallableOf(final Scalar<T> slr) {
this.scalar = slr;
}

@Override
public T call() throws Exception {
return this.scalar.value();
super(() -> slr.value());
}
}

1 comment on commit 2eef5c9

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 2eef5c9 Jan 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 1445-4c312276 disappeared from src/main/java/org/cactoos/package-info.java, that's why I closed #1526. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

Please sign in to comment.