/
ImmutableHeadersPlaceholder.java
51 lines (41 loc) · 1.47 KB
/
ImmutableHeadersPlaceholder.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
/*
* Copyright (c) 2017-2018 Bosch Software Innovations GmbH.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/index.php
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.ditto.services.models.connectivity.placeholder;
import java.util.Map;
import java.util.Optional;
import org.eclipse.ditto.model.base.common.ConditionChecker;
/**
* Placeholder implementation that replaces {@code header:*} from a headers map of {@code Map<String, String>}.
*/
final class ImmutableHeadersPlaceholder implements HeadersPlaceholder {
private static final String PREFIX = "header";
static final ImmutableHeadersPlaceholder INSTANCE = new ImmutableHeadersPlaceholder();
private ImmutableHeadersPlaceholder() {
}
@Override
public String getPrefix() {
return PREFIX;
}
@Override
public boolean supports(final String name) {
return true;
}
@Override
public Optional<String> apply(final Map<String, String> headers, final String header) {
ConditionChecker.argumentNotEmpty(header, "header");
ConditionChecker.argumentNotNull(headers, "headers");
return Optional.ofNullable(headers.get(header));
}
@Override
public String toString() {
return getClass().getSimpleName() + "[]";
}
}