io.undertow.httpcore.UndertowOptionMap Maven / Gradle / Ivy
/*
* JBoss, Home of Professional Open Source.
* Copyright 2018 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.undertow.httpcore;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class UndertowOptionMap implements Iterable, Object>> {
public static final UndertowOptionMap EMPTY = new UndertowOptionMap(Collections.emptyMap());
private final Map, Object> values;
UndertowOptionMap(Map, Object> values) {
this.values = values;
}
public T get(UndertowOption option, T defaultValue) {
return (T) values.getOrDefault(option, defaultValue);
}
public boolean get(UndertowOption option, boolean defaultValue) {
return (Boolean) values.getOrDefault(option, defaultValue);
}
public T get(UndertowOption option) {
return (T) values.get(option);
}
public boolean contains(UndertowOption> option) {
return values.containsKey(option);
}
public static Builder builder() {
return new Builder();
}
@Override
public Iterator, Object>> iterator() {
return values.entrySet().iterator();
}
public static UndertowOptionMap create(UndertowOption key, T val) {
return builder().set(key, val).getMap();
}
public static UndertowOptionMap create(UndertowOption key1, T1 val1, UndertowOption key2, T2 val2) {
return builder().set(key1, val1).set(key2, val2)
.getMap();
}
public static class Builder {
private final Map, Object> values = new HashMap<>();
public Builder set(UndertowOption option, T value) {
values.put(option, value);
return this;
}
public Builder addAll(UndertowOptionMap workerOptions) {
values.putAll(workerOptions.values);
return this;
}
public UndertowOptionMap getMap() {
return new UndertowOptionMap(new HashMap<>(values));
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy