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