当前位置: 首页>>代码示例>>Java>>正文


Java Config类代码示例

本文整理汇总了Java中org.aeonbits.owner.Config的典型用法代码示例。如果您正苦于以下问题:Java Config类的具体用法?Java Config怎么用?Java Config使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Config类属于org.aeonbits.owner包,在下文中一共展示了Config类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getSourcesAnnotationPathVariables

import org.aeonbits.owner.Config; //导入依赖的package包/类
/**
 * Get a list of the config file variables from the given {@link Config} class.
 * @param configClass A configuration class from which to extract variable names in its {@link org.aeonbits.owner.Config.Sources}.
 * @return A list of variables in the {@link org.aeonbits.owner.Config.Sources} of the given {@code configClass}
 */
@VisibleForTesting
<T extends Config> List<String> getSourcesAnnotationPathVariables(final Class<? extends T> configClass) {

    final List<String> configPathVariableNames = new ArrayList<>();

    final Config.Sources annotation = configClass.getAnnotation(Config.Sources.class);

    if ( annotation != null ) {
        for (final String val : annotation.value()) {

            final Matcher m = sourcesAnnotationPathVariablePattern.matcher(val);
            if (m.find()) {
                configPathVariableNames.add(m.group(1));
            }
        }
    }

    return configPathVariableNames;
}
 
开发者ID:broadinstitute,项目名称:gatk,代码行数:25,代码来源:ConfigFactory.java

示例2: dumpConfigSettings

import org.aeonbits.owner.Config; //导入依赖的package包/类
/**
 * Dump the configuration to a file that can be easily read into {@link Properties}.
 * @param config Configuration instance to dump.
 * @param outFilePath {@link Path} to output location.
 * @param <T> Some configuration class that extends {@link Config}.
 */
public static <T extends Config> void dumpConfigSettings(final T config, final Path outFilePath ) {
    final LinkedHashMap<String, Object> configMap = getConfigMap(config, false);

    final Properties properties = new Properties();
    properties.putAll(convertConfigMapToStringStringMap(configMap));

    final Date d = new Date();

    try ( final OutputStream outputStream = Files.newOutputStream(outFilePath, StandardOpenOption.CREATE_NEW) ) {
        properties.store(outputStream, "Created from " + config.getClass().getSimpleName() + " at " +
                new SimpleDateFormat("HH.mm.ss").format(d) + " on " +
                new SimpleDateFormat("yyyy.MM.dd").format(d));
    }
    catch (final Exception ex) {
        throw new GATKException("Could not write config (" + config.getClass().getTypeName() + ") to file: " + outFilePath, ex);
    }
}
 
开发者ID:broadinstitute,项目名称:gatk,代码行数:24,代码来源:ConfigFactory.java

示例3: initializeConfigurationsFromCommandLineArgs

import org.aeonbits.owner.Config; //导入依赖的package包/类
/**
 * Get the configuration from filename the command-line (if it exists) and create a configuration for it of the given type.
 * Also sets system-level properties from the system config file.
 * @param argList The list of arguments from which to read the config file.
 * @param configFileOption The command-line option specifying the main configuration file.
 * @param configClass The class of the configuration file to instantiate.
 */
public synchronized <T extends Config> void initializeConfigurationsFromCommandLineArgs(final String[] argList,
                                                                                        final String configFileOption,
                                                                                        final Class<? extends T> configClass) {
    Utils.nonNull(argList);
    Utils.nonNull(configFileOption);
    Utils.nonNull(configClass);

    // Get main config from args:
    final String configFileName = getConfigFilenameFromArgs( argList, configFileOption );

    // Load the configuration from the given file:
    final T configuration = getOrCreateConfigFromFile(configFileName, configClass);

    // To start with we inject our system properties to ensure they are defined for downstream components:
    injectSystemPropertiesFromConfig( configuration );
}
 
开发者ID:broadinstitute,项目名称:gatk,代码行数:24,代码来源:ConfigFactory.java

示例4: logConfigFields

import org.aeonbits.owner.Config; //导入依赖的package包/类
/**
 * Logs all the parameters in the given {@link Config} object at the given {@link Log.LogLevel}
 * @param config A {@link Config} object from which to log all parameters and values.
 * @param logLevel The log {@link htsjdk.samtools.util.Log.LogLevel} at which to log the data in {@code config}
 * @param <T> any {@link Config} type to use to log all configuration information.
 */
public static <T extends Config> void logConfigFields(final T config, final Log.LogLevel logLevel) {

    Utils.nonNull(config);
    Utils.nonNull(logLevel);

    final Level level = LoggingUtils.levelToLog4jLevel(logLevel);

    // Only continue in this method here if we would log the given level:
    if ( !logger.isEnabled(level) ) {
        return;
    }

    logger.log(level, "Configuration file values: ");
    for ( final Map.Entry<String, Object> entry : getConfigMap(config, false).entrySet() ) {
        logger.log(level, "\t" + entry.getKey() + " = " + entry.getValue());
    }
}
 
开发者ID:broadinstitute,项目名称:gatk,代码行数:24,代码来源:ConfigFactory.java

示例5: getConfigPathVariableNamesFromConfigClasses

import org.aeonbits.owner.Config; //导入依赖的package包/类
/**
 * Get a list of the config file variables from the given {@link Config} classes.
 * @param configurationClasses A list of configuration classes from which to extract variable names in their {@link org.aeonbits.owner.Config.Sources}.
 * @return A list of variables in the {@link org.aeonbits.owner.Config.Sources} of the given {@code configurationClasses}
 */
@VisibleForTesting
List<String> getConfigPathVariableNamesFromConfigClasses(final List<Class<?>> configurationClasses) {

    final List<String> configPathVariableNames = new ArrayList<>();

    // Loop through our classes and grab any sources with variables in there:
    for ( final Class<?> clazz : ClassUtils.getClassesOfType(Config.class, configurationClasses) ) {
        @SuppressWarnings("unchecked")
        final Class<? extends Config> castedClass = (Class<? extends Config>) clazz;
        configPathVariableNames.addAll( getSourcesAnnotationPathVariables(castedClass));
    }

    return configPathVariableNames;
}
 
开发者ID:broadinstitute,项目名称:gatk,代码行数:20,代码来源:ConfigFactory.java

示例6: resolvePathVariables

import org.aeonbits.owner.Config; //导入依赖的package包/类
private synchronized <T extends Config> void resolvePathVariables(final Class<? extends T> clazz) {
    if ( !alreadyResolvedPathVariables.contains(clazz) ) {
        checkFileNamePropertyExistenceAndSetConfigFactoryProperties(
                getSourcesAnnotationPathVariables(clazz)
        );

        alreadyResolvedPathVariables.add(clazz);
    }
}
 
开发者ID:broadinstitute,项目名称:gatk,代码行数:10,代码来源:ConfigFactory.java

示例7: getOrCreateConfigFromFile

import org.aeonbits.owner.Config; //导入依赖的package包/类
@VisibleForTesting
synchronized <T extends Config> T getOrCreateConfigFromFile(final String configFileName, final Class<? extends T> configClass) {

    // Set the config path if we've specified it:
    if ( configFileName != null ){
        org.aeonbits.owner.ConfigFactory.setProperty( GATKConfig.CONFIG_FILE_VARIABLE_FILE_NAME, configFileName );
    }

    // Set the config file to be the one we want to use from the command-line:
    return ConfigFactory.getInstance().getOrCreate(configClass);
}
 
开发者ID:broadinstitute,项目名称:gatk,代码行数:12,代码来源:ConfigFactory.java

示例8: createConfigFromFile

import org.aeonbits.owner.Config; //导入依赖的package包/类
@VisibleForTesting
synchronized <T extends Config> T createConfigFromFile(final String configFileName, final Class<? extends T> configClass) {

    // Set the config path if we've specified it:
    if ( configFileName != null ){
        org.aeonbits.owner.ConfigFactory.setProperty( GATKConfig.CONFIG_FILE_VARIABLE_FILE_NAME, configFileName );
    }

    // Set the config file to be the one we want to use from the command-line:
    return ConfigFactory.getInstance().create(configClass);
}
 
开发者ID:broadinstitute,项目名称:gatk,代码行数:12,代码来源:ConfigFactory.java

示例9: injectSystemPropertiesFromConfig

import org.aeonbits.owner.Config; //导入依赖的package包/类
/**
 * Injects system properties from the given configuration file.
 * System properties are specified by the presence of the {@link SystemProperty} annotation.
 * @param config The {@link GATKConfig} object from which to inject system properties.
 */
public synchronized <T extends Config> void injectSystemPropertiesFromConfig(final T config) {
    
    Utils.nonNull(config);

    // Get our system properties:
    final Map<String, String> properties = getSystemPropertiesFromConfig(config);

    // Set our properties:
    injectToSystemProperties(properties);
}
 
开发者ID:broadinstitute,项目名称:gatk,代码行数:16,代码来源:ConfigFactory.java

示例10: getSystemPropertiesFromConfig

import org.aeonbits.owner.Config; //导入依赖的package包/类
/**
 * Gets all system properties from the given {@link Config}-derived object.
 * System properties are denoted via the presence of the {@link SystemProperty} annotation.
 * @param config A {@link Config}-derived object from which to read system properties.
 * @param <T> A {@link Config}-derived type from which to read System Properties.
 * @return A properties {@link Map} representing all System Properties in the given {@code config}.
 */
@VisibleForTesting
static <T extends Config> LinkedHashMap<String, String> getSystemPropertiesFromConfig(final T config) {

    Utils.nonNull(config);

    final LinkedHashMap<String, String> properties = new LinkedHashMap<>();

    for ( final Map.Entry<String, Object> entry : getConfigMap(config, true).entrySet() ) {
        properties.put(entry.getKey(), String.valueOf(entry.getValue()));
    }

    return properties;
}
 
开发者ID:broadinstitute,项目名称:gatk,代码行数:21,代码来源:ConfigFactory.java

示例11: getDefaultValuesFromConfig

import org.aeonbits.owner.Config; //导入依赖的package包/类
private Map<String, String> getDefaultValuesFromConfig(final Class<GATKConfig> gatkConfigClass) {

        final Map<String, String> defaultValueMap = new HashMap<>();

        // Now we cycle through our interface methods, resolve parameter names,
        // and log their values at the given level:
        for (final Method propertyMethod : gatkConfigClass.getDeclaredMethods()) {

            final String defaultValue;
            final Config.DefaultValue defVal = propertyMethod.getAnnotation( Config.DefaultValue.class );
            if (defVal != null) {

                defaultValue = defVal.value();

                // Get the property name:
                String propertyName = propertyMethod.getName();

                // Get the real property name if we've overwritten it with a key:
                final Config.Key key = propertyMethod.getAnnotation(Config.Key.class);
                if ( key != null ) {
                    propertyName = key.value();
                }

                defaultValueMap.put(propertyName, defaultValue);
            }
        }

        return defaultValueMap;
    }
 
开发者ID:broadinstitute,项目名称:gatk,代码行数:30,代码来源:ConfigUnitTest.java

示例12: getFieldDelimiterFromGATKConfig

import org.aeonbits.owner.Config; //导入依赖的package包/类
private String getFieldDelimiterFromGATKConfig(final String parameterName) {

        String delimiter = ",";

        for (final Method propertyMethod : GATKConfig.class.getDeclaredMethods()) {

            // Get the property name:
            String propertyName = propertyMethod.getName();

            // Get the real property name if we've overwritten it with a key:
            final Config.Key key = propertyMethod.getAnnotation(Config.Key.class);
            if ( key != null ) {
                propertyName = key.value();
            }

            // Check to see if this is the property we're interested in:
            if ( parameterName.equals(propertyName) ) {
                // Get the delimiter:
                final Config.Separator separator = propertyMethod.getAnnotation(Config.Separator.class);
                if ( separator != null ) {
                    delimiter = separator.value();
                }
            }
        }

        return delimiter;
    }
 
开发者ID:broadinstitute,项目名称:gatk,代码行数:28,代码来源:ConfigUnitTest.java

示例13: testGetSourcesAnnotationPathVariables

import org.aeonbits.owner.Config; //导入依赖的package包/类
@Test(dataProvider = "createConfigFileAndVariableNames")
public void testGetSourcesAnnotationPathVariables(final Class<? extends Config> configClass, final List<String> expectedFilePathVariables ) {
        Assert.assertEquals( ConfigFactory.getInstance().getSourcesAnnotationPathVariables(configClass), expectedFilePathVariables );
}
 
开发者ID:broadinstitute,项目名称:gatk,代码行数:5,代码来源:ConfigUnitTest.java

示例14: getOrCreate

import org.aeonbits.owner.Config; //导入依赖的package包/类
/**
 * Wrapper around {@link ConfigCache#getOrCreate(Factory, Object, Class, Map[])} which will ensure that
 * path variables specified in {@link org.aeonbits.owner.Config.Sources} annotations are resolved prior
 * to creation.
 *
 * @param factory   the factory to use to eventually create the instance.
 * @param key       the key object to be used to identify the instance in the cache.
 * @param clazz     the interface extending from {@link Config} that you want to instantiate.
 * @param imports   additional variables to be used to resolve the properties.
 * @param <T>       type of the interface.
 * @return          an object implementing the given interface, that can be taken from the cache,
 *                  which maps methods to property values.
 */
public <T extends Config> T getOrCreate(final Factory factory, final Object key,
                                               final Class<? extends T> clazz, final Map<?, ?>... imports) {

    Utils.nonNull(factory);
    Utils.nonNull(key);
    Utils.nonNull(clazz);

    resolvePathVariables(clazz);

    return ConfigCache.getOrCreate(key, clazz, imports);
}
 
开发者ID:broadinstitute,项目名称:gatk,代码行数:25,代码来源:ConfigFactory.java

示例15: get

import org.aeonbits.owner.Config; //导入依赖的package包/类
/**
 * Wrapper around {@link ConfigCache#get(Object)}.
 * This method is here to complete the interface for getting {@link Config} objects.
 *
 * Gets from the cache the {@link Config} instance identified by the given key.
 *
 * @param key       the key object to be used to identify the instance in the cache.
 * @param <T>       type of the interface.
 * @return          the {@link Config} object from the cache if exists, or <tt>null</tt> if it doesn't.
 */
public <T extends Config> T get(final Object key) {
    Utils.nonNull(key);
    return ConfigCache.get(key);
}
 
开发者ID:broadinstitute,项目名称:gatk,代码行数:15,代码来源:ConfigFactory.java


注:本文中的org.aeonbits.owner.Config类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。