]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db/src/org/simantics/db/function/DbConsumer.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.db / src / org / simantics / db / function / DbConsumer.java
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
8  *\r
9  * Contributors:\r
10  *     Semantum Oy - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.db.function;\r
13 \r
14 import java.util.Objects;\r
15 import java.util.function.Consumer;\r
16 \r
17 import org.simantics.db.exception.DatabaseException;\r
18 \r
19 /**\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
23  * side-effects.\r
24  *\r
25  * <p>\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
29  *\r
30  * @param <T>\r
31  *            the type of the input to the operation\r
32  *\r
33  * @author Tuukka Lehtonen\r
34  * @since 1.22\r
35  */\r
36 @FunctionalInterface\r
37 public interface DbConsumer<T> {\r
38 \r
39     /**\r
40      * Performs this operation on the given argument.\r
41      *\r
42      * @param t the input argument\r
43      */\r
44     void accept(T t) throws DatabaseException;\r
45 \r
46     /**\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
52      *\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
57      */\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
61     }\r
62 }\r