/
ColumnConfiguration.java
65 lines (57 loc) · 2.38 KB
/
ColumnConfiguration.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
*
* Copyright (c) 2023 Contributors to the Eclipse Foundation
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Apache License v2.0 which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
*
* You may elect to redistribute this code under either of these licenses.
*
* Contributors:
*
* Otavio Santana
*
*/
package org.eclipse.jnosql.communication.semistructured;
import org.eclipse.jnosql.communication.CommunicationException;
import org.eclipse.jnosql.communication.Settings;
import java.util.ServiceLoader;
import java.util.function.Function;
/**
* It is a function that reads from {@link Settings} and then creates a manager factory instance.
* It should return a {@link NullPointerException} when the {@link Settings} parameter is null.
*
* @see ColumnManagerFactory
* @see ColumnManager
*/
public interface ColumnConfiguration extends Function<Settings, ColumnManagerFactory> {
/**
* creates and returns a {@link ColumnConfiguration} instance from {@link ServiceLoader}
*
* @param <T> the configuration type
* @return {@link ColumnConfiguration} instance
*/
static <T extends ColumnConfiguration> T getConfiguration() {
return (T) ServiceLoader.load(ColumnConfiguration.class)
.stream()
.map(ServiceLoader.Provider::get)
.findFirst().orElseThrow(() -> new CommunicationException("No ColumnConfiguration implementation found!"));
}
/**
* creates and returns a {@link ColumnConfiguration} instance from {@link ServiceLoader}
* for a particular provider implementation.
*
* @param <T> the configuration type
* @param type the particular provider
* @return {@link ColumnConfiguration} instance
*/
static <T extends ColumnConfiguration> T getConfiguration(Class<T> type) {
return (T) ServiceLoader.load(ColumnConfiguration.class)
.stream()
.map(ServiceLoader.Provider::get)
.filter(type::isInstance)
.findFirst().orElseThrow(() -> new CommunicationException("No ColumnConfiguration implementation found!"));
}
}