de.tk.opensource.secon.SideEffect Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of secon-tool Show documentation
Show all versions of secon-tool Show documentation
A library for secure communication in the German health care and social affairs sector. Based on specifications in 'GKV Anlage 16 SECON'
The newest version!
/*
* Copyright © 2020 Techniker Krankenkasse
* Copyright © 2020 BITMARCK Service GmbH
*
* This file is part of secon-tool
* (see https://github.com/DieTechniker/secon-tool).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
package de.tk.opensource.secon;
/**
* @author Christian Schlichtherle
*/
@FunctionalInterface
interface SideEffect {
@SafeVarargs
static void runAll(final SideEffect first, final SideEffect... others) throws X {
SideEffect acc = first;
for (SideEffect other : others) {
acc = acc.andThen(other);
}
acc.run();
}
void run() throws X;
default SideEffect andThen(final SideEffect that) {
return () -> {
Throwable t1 = null;
try {
this.run();
} catch (final Throwable t) {
t1 = t;
throw t;
} finally {
try {
that.run();
} catch (final Throwable t) {
if (null == t1) {
throw t;
} else {
t1.addSuppressed(t);
}
}
}
};
}
}