1 /*******************************************************************************
\r
2 * Copyright (c) 2016 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * Semantum Oy - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.db.function;
\r
14 import java.util.Objects;
\r
15 import java.util.function.Consumer;
\r
17 import org.simantics.db.exception.DatabaseException;
\r
20 * Represents a database operation that accepts a single input argument and
\r
21 * returns no result and can throw database exceptions. Unlike most other
\r
22 * functional interfaces, {@code DbConsumer} is expected to operate via
\r
26 * This is a functional interface whose functional method is
\r
27 * {@link #accept(Object)}. The only difference to {@link Consumer} is that this
\r
28 * allows throwing DatabaseException.
\r
31 * the type of the input to the operation
\r
33 * @author Tuukka Lehtonen
\r
36 @FunctionalInterface
\r
37 public interface DbConsumer<T> {
\r
40 * Performs this operation on the given argument.
\r
42 * @param t the input argument
\r
44 void accept(T t) throws DatabaseException;
\r
47 * Returns a composed {@code Consumer} that performs, in sequence, this
\r
48 * operation followed by the {@code after} operation. If performing either
\r
49 * operation throws an exception, it is relayed to the caller of the
\r
50 * composed operation. If performing this operation throws an exception,
\r
51 * the {@code after} operation will not be performed.
\r
53 * @param after the operation to perform after this operation
\r
54 * @return a composed {@code Consumer} that performs in sequence this
\r
55 * operation followed by the {@code after} operation
\r
56 * @throws NullPointerException if {@code after} is null
\r
58 default DbConsumer<T> andThen(DbConsumer<? super T> after) {
\r
59 Objects.requireNonNull(after);
\r
60 return (T t) -> { accept(t); after.accept(t); };
\r