Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2014-2023 the original author or authors.
*
* 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
*
* https://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 org.grails.config;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.Set;
import grails.config.Config;
/**
* A config that accepts a prefix
*
* @author Graeme Rocher
* @since 3.0
*/
public class PrefixedConfig implements Config {
protected String prefix;
protected String[] prefixTokens;
protected Config delegate;
public PrefixedConfig(String prefix, Config delegate) {
this.prefix = prefix;
this.prefixTokens = prefix.split("\\.");
this.delegate = delegate;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
PrefixedConfig entries = (PrefixedConfig) o;
if (!Objects.equals(this.delegate, entries.delegate)) {
return false;
}
return Objects.equals(this.prefix, entries.prefix);
}
@Override
public int hashCode() {
int result = this.prefix != null ? this.prefix.hashCode() : 0;
result = 31 * result + (this.delegate != null ? this.delegate.hashCode() : 0);
return result;
}
@Override
@Deprecated
public Map flatten() {
Map flattened = this.delegate.flatten();
Map map = new LinkedHashMap<>(flattened.size());
for (String key : flattened.keySet()) {
map.put(formulateKey(key), flattened.get(key));
}
return map;
}
@Override
public Properties toProperties() {
Map flattened = flatten();
Properties properties = new Properties();
properties.putAll(flattened);
return properties;
}
@Override
public Object getAt(Object key) {
return get(key);
}
@Override
public Object navigate(String... path) {
List tokens = new ArrayList<>();
tokens.addAll(Arrays.asList(this.prefixTokens));
tokens.addAll(Arrays.asList(path));
return this.delegate.navigate(tokens.toArray(new String[0]));
}
@Override
public Iterator> iterator() {
return entrySet().iterator();
}
@Override
public int size() {
return this.delegate.size();
}
@Override
public boolean isEmpty() {
return this.delegate.isEmpty();
}
@Override
public boolean containsKey(Object key) {
return containsProperty(key.toString());
}
@Override
public boolean containsValue(Object value) {
return values().contains(value);
}
@Override
public Object get(Object key) {
return getProperty(key.toString(), Object.class);
}
@Override
public Set keySet() {
Set keys = this.delegate.keySet();
Set newKeys = new HashSet<>();
for (String key : keys) {
newKeys.add(formulateKey(key));
}
return newKeys;
}
@Override
public Collection