jmms.core.MetaConfig Maven / Gradle / Ivy
/*
* Copyright 2019 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
*
* 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 jmms.core;
import leap.lang.Strings;
import leap.lang.Valued;
import java.util.HashMap;
import java.util.Map;
public class MetaConfig {
private static MetaConfig INST = new MetaConfig();
public static MetaConfig get() {
return INST;
}
public static void set(MetaConfig inst) {
INST = inst;
}
public enum ExtendStrategy implements Valued {
MERGE("merge"),
OVERRIDE("override"),
DEFAULT("default");
private final String value;
ExtendStrategy(String value) {
this.value = value;
}
public boolean isMerge() {
return this == MERGE;
}
public boolean isOverride() {
return this == OVERRIDE;
}
@Override
public String getValue() {
return value;
}
}
protected ExtendStrategies extendStrategies = new ExtendStrategies();
public ExtendStrategy getAttrsExtendStrategyOf(Object o) {
String name = Strings.lowerCamel(Strings.removeStart(o.getClass().getSimpleName(), "Meta"));
Map attrs = extendStrategies.getAttrs();
ExtendStrategy strategy = attrs.get(name);
if (null == strategy) {
strategy = attrs.get("default");
}
if (null == strategy) {
strategy = ExtendStrategy.DEFAULT;
}
return strategy;
}
public ExtendStrategies getExtendStrategies() {
return extendStrategies;
}
public void setExtendStrategies(ExtendStrategies extendStrategies) {
this.extendStrategies = extendStrategies;
}
public static class ExtendStrategies {
protected Map attrs = new HashMap<>();
public Map getAttrs() {
return attrs;
}
public void setAttrs(Map attrs) {
this.attrs = attrs;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy