com.typesafe.config.Config.getAnyRef()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(183)

本文整理了Java中com.typesafe.config.Config.getAnyRef()方法的一些代码示例,展示了Config.getAnyRef()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Config.getAnyRef()方法的具体详情如下:
包路径:com.typesafe.config.Config
类名称:Config
方法名:getAnyRef

Config.getAnyRef介绍

[英]Gets the value at the path as an unwrapped Java boxed value ( java.lang.Boolean, java.lang.Integer, and so on - see ConfigValue#unwrapped()).
[中]获取路径处的值作为未包装的Java装箱值(Java.lang.Boolean、Java.lang.Integer等-请参阅ConfigValue#unwrapped()。

代码示例

代码示例来源:origin: kairosdb/kairosdb

@Override
  public Object extractValue(Config config, String path)
  {
    return config.getAnyRef(path);
  }
},

代码示例来源:origin: ethereum/ethereumj

@Test
  public void simpleTest() {
    Config config = ConfigFactory.parseResources("ethereumj.conf");
    System.out.println(config.root().render(ConfigRenderOptions.defaults().setComments(false)));
    for (Map.Entry<String, ConfigValue> entry : config.entrySet()) {
//            System.out.println("Name:  " + entry.getKey());
//            System.out.println(entry);
    }
    System.out.println("peer.listen.port: " + config.getInt("peer.listen.port"));
    System.out.println("peer.discovery.ip.list: " + config.getAnyRefList("peer.discovery.ip.list"));
    System.out.println("peer.discovery.ip.list: " + config.getAnyRefList("peer.active"));
    List<? extends ConfigObject> list = config.getObjectList("peer.active");
    for (ConfigObject configObject : list) {
      if (configObject.get("url") != null) {
        System.out.println("URL: " + configObject.get("url"));
      }
      if (configObject.get("ip") != null) {
        System.out.println("IP: " + configObject);
      }
    }

    System.out.println("blocks.loader = " + config.hasPath("blocks.loader"));
    System.out.println("blocks.loader = " + config.getAnyRef("blocks.loader"));
  }

代码示例来源:origin: apache/drill

@Override
public Object getAnyRef(String path) {
 return c.getAnyRef(path);
}

代码示例来源:origin: jooby-project/jooby

@Override
public Object resolve(final Object context, final String name) {
 if (context instanceof Config) {
  Config config = (Config) context;
  if (config.hasPath(name)) {
   return config.getAnyRef(name);
  }
 }
 return UNRESOLVED;
}

代码示例来源:origin: jooby-project/jooby

@SuppressWarnings("unchecked")
public <T> T get(final String name) {
 requireNonNull(name, "Option's name is required.");
 if (options.hasPath(name)) {
  return (T) options.getAnyRef(name);
 }
 return null;
}

代码示例来源:origin: ethereum/ethereumj

public <T> T getProperty(String propName, T defaultValue) {
  if (!config.hasPath(propName)) return defaultValue;
  String string = config.getString(propName);
  if (string.trim().isEmpty()) return defaultValue;
  return (T) config.getAnyRef(propName);
}

代码示例来源:origin: jooby-project/jooby

@SuppressWarnings("rawtypes")
private void list(final Config conf, final String name, final Throwing.Consumer<Object> callback) {
 if (conf.hasPath(name)) {
  Object value = conf.getAnyRef(name);
  List values = value instanceof List ? (List) value : ImmutableList.of(value);
  for (Object it : values) {
   callback.accept(it);
  }
 }
}

代码示例来源:origin: jooby-project/jooby

private List<String> strList(final String p) {
 Object list = mail.getAnyRef(p);
 if (list instanceof String) {
  return ImmutableList.of(list.toString());
 }
 return mail.getStringList(p);
}

代码示例来源:origin: jooby-project/jooby

private static Predicate<String> predicate(final Config fileset, final String... extension) {
 String path = "assets" + extension[0];
 Set<String> extensions = new HashSet<>(Arrays.asList(extension));
 if (fileset.hasPath(path)) {
  extensions.addAll(strlist(fileset.getAnyRef(path)));
 }
 return file -> {
  for (String ext : extensions) {
   if (file.endsWith(ext)) {
    return true;
   }
  }
  return false;
 };
}

代码示例来源:origin: jooby-project/jooby

@SuppressWarnings("unchecked")
 private static Iterable<Command> commands(final Config config) {
  Object value = config.getAnyRef("flyway.run");
  List<String> commands = new ArrayList<>();
  if (value instanceof List) {
   commands.addAll((List<? extends String>) value);
  } else {
   Stream.of(value.toString().split(","))
     .map(String::trim)
     .forEach(commands::add);
  }
  return commands.stream()
    .map(command -> Command.valueOf(command.toLowerCase()))
    .collect(Collectors.toList());
 }
}

代码示例来源:origin: jooby-project/jooby

/**
 * Scan the packages defined by <code>hibernate.packagesToScan</code> property or the application
 * package (that's the package where you application was defined) and discover persistent classes
 * (annotated with Entity).
 *
 * @return This module.
 */
public Hbm scan() {
 sources.add((m, conf) ->
   Stream.of(conf.getAnyRef("hibernate.packagesToScan"))
     .flatMap(it -> {
      if (it instanceof List) {
       return ((List) it).stream();
      }
      return Stream.of(it);
     })
     .forEach(it -> m.addPackage(it.toString()))
 );
 return this;
}

代码示例来源:origin: jooby-project/jooby

@SuppressWarnings("unchecked")
@Override
public void configure(final Env env, final Config conf, final Binder binder) {
 Config $memcached = conf.getConfig("memcached")
   .withFallback(conf.getConfig("memcached"));
 ConnectionFactoryBuilder builder = newConnectionFactoryBuilder($memcached);
 if (configurer != null) {
  configurer.accept(builder, conf);
 }
 List<String> servers = new ArrayList<>();
 Object $servers = conf.getAnyRef("memcached.server");
 if ($servers instanceof List) {
  servers.addAll((Collection<? extends String>) $servers);
 } else {
  servers.add($servers.toString());
 }
 MemcachedClientProvider provider = new MemcachedClientProvider(
   builder,
   AddrUtil.getAddresses(servers),
   $memcached.getDuration("shutdownTimeout", TimeUnit.MILLISECONDS));
 env.onStop(provider::destroy);
 binder
   .bind(MemcachedClient.class)
   .toProvider(provider)
   .asEagerSingleton();
}

代码示例来源:origin: jooby-project/jooby

private void tryOption(final Object source, final Config config, final Method option) {
 Try.run(() -> {
  String optionName = option.getName().replace("set", "");
  Object optionValue = config.getAnyRef(optionName);
  Class<?> optionType = Primitives.wrap(option.getParameterTypes()[0]);
  if (Number.class.isAssignableFrom(optionType) && optionValue instanceof String) {
   // either a byte or time unit
   try {
    optionValue = config.getBytes(optionName);
   } catch (ConfigException.BadValue ex) {
    optionValue = config.getDuration(optionName, TimeUnit.MILLISECONDS);
   }
   if (optionType == Integer.class) {
    // to int
    optionValue = ((Number) optionValue).intValue();
   }
  }
  log.debug("{}.{}({})", source.getClass().getSimpleName(), option.getName(), optionValue);
  option.invoke(source, optionValue);
 }).unwrap(InvocationTargetException.class)
   .throwException();
}

代码示例来源:origin: jooby-project/jooby

/**
 * Creates {@link Cors} options from {@link Config}:
 *
 * <pre>
 *  origin: "*"
 *  credentials: true
 *  allowedMethods: [GET, POST]
 *  allowedHeaders: [X-Requested-With, Content-Type, Accept, Origin]
 *  exposedHeaders: []
 * </pre>
 *
 * @param config Config to use.
 */
@Inject
public Cors(@Named("cors") final Config config) {
 requireNonNull(config, "Config is required.");
 this.enabled = config.hasPath("enabled") ? config.getBoolean("enabled") : true;
 withOrigin(list(config.getAnyRef("origin")));
 this.credentials = config.getBoolean("credentials");
 withMethods(list(config.getAnyRef("allowedMethods")));
 withHeaders(list(config.getAnyRef("allowedHeaders")));
 withMaxAge((int) config.getDuration("maxAge", TimeUnit.SECONDS));
 withExposedHeaders(config.hasPath("exposedHeaders")
   ? list(config.getAnyRef("exposedHeaders"))
   : Collections.emptyList());
}

代码示例来源:origin: jooby-project/jooby

private Configuration lessConf(final Config conf) {
 Configuration configuration = new Configuration();
 configuration.setCompressing(get("compressing"));
 SourceMapConfiguration sourceMap = configuration.getSourceMapConfiguration();
 Map<String, Object> map = get("sourceMap");
 if (map == null) {
  sourceMap.setLinkSourceMap(false);
 } else {
  sourceMap.setEncodingCharset(
    map.getOrDefault("encodingCharset", conf.getAnyRef("application.charset")).toString());
  sourceMap.setIncludeSourcesContent((Boolean) map.getOrDefault("includeSourcesContent", true));
  sourceMap.setInline((Boolean) map.getOrDefault("inline", true));
  sourceMap.setRelativizePaths((Boolean) map.getOrDefault("relativizePaths", true));
  sourceMap.setLinkSourceMap((Boolean) map.getOrDefault("linkSourceMap", true));
 }
 return configuration;
}

代码示例来源:origin: jooby-project/jooby

private Config dbConfig(final String key, final Config source) {
 Object db = source.getAnyRef(key);
 if (db instanceof String) {
  // embedded db?
  return Try.apply(() -> source.getConfig("databases." + db))
    .map(it -> {
     // Rewrite embedded db
     it = it.getConfig("dataSource");
     Config dbtree = it.withValue("url", ConfigValueFactory.fromAnyRef(
       it.getString("url").replace("{mem.seed}", System.currentTimeMillis() + "")));
     // write embedded with current key
     return ConfigFactory.empty()
       .withValue(key, dbtree.root())
       .withFallback(source);
    }).orElseGet(() -> {
     // assume it is a just the url
     return ConfigFactory.empty()
       .withValue(key + ".url", ConfigValueFactory.fromAnyRef(db.toString()))
       .withFallback(source);
    });
 } else {
  return source;
 }
}

代码示例来源:origin: atomix/atomix

return new MemorySize(size.toBytes());
} else if (parameterClass == Object.class) {
 return config.getAnyRef(configPropName);
} else if (parameterClass == List.class || parameterClass == Collection.class) {
 return getListValue(beanClass, parameterType, parameterClass, config, configPath, configPropName);

代码示例来源:origin: jooby-project/jooby

.orElse($session.getBoolean("cookie.httpOnly")));
Object maxAge = $session.getAnyRef("cookie.maxAge");
if (maxAge instanceof String) {
 maxAge = $session.getDuration("cookie.maxAge", TimeUnit.SECONDS);

代码示例来源:origin: mpusher/mpush

return config.getMemorySize(configPropName);
} else if (parameterClass == Object.class) {
  return config.getAnyRef(configPropName);
} else if (parameterClass == List.class) {
  return getListValue(beanClass, parameterType, parameterClass, config, configPropName);

代码示例来源:origin: mpusher/mpush

return CC.cfg.getAnyRef(args).toString();

相关文章