com.typesafe.config.ConfigMemorySize Java Examples

The following examples show how to use com.typesafe.config.ConfigMemorySize. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultScopedConfig.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public ConfigMemorySize getMemorySize(final String path) {
    try {
        return config.getMemorySize(path);
    } catch (final ConfigException.Missing | ConfigException.WrongType e) {
        final String msgPattern = "Failed to get memory size for path <{0}>!";
        throw new DittoConfigError(MessageFormat.format(msgPattern, appendToConfigPath(path)), e);
    }
}
 
Example #2
Source File: DefaultScopedConfig.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public List<ConfigMemorySize> getMemorySizeList(final String path) {
    try {
        return config.getMemorySizeList(path);
    } catch (final ConfigException.Missing | ConfigException.WrongType e) {
        final String msgPattern = "Failed to get List of memory sizes for path <{0}>!";
        throw new DittoConfigError(MessageFormat.format(msgPattern, appendToConfigPath(path)), e);
    }
}
 
Example #3
Source File: ConfigBeanImpl.java    From mpush with Apache License 2.0 5 votes vote down vote up
private static Object getListValue(Class<?> beanClass, Type parameterType, Class<?> parameterClass, Config config, String configPropName) {
    Type elementType = ((ParameterizedType) parameterType).getActualTypeArguments()[0];

    if (elementType == Boolean.class) {
        return config.getBooleanList(configPropName);
    } else if (elementType == Integer.class) {
        return config.getIntList(configPropName);
    } else if (elementType == Double.class) {
        return config.getDoubleList(configPropName);
    } else if (elementType == Long.class) {
        return config.getLongList(configPropName);
    } else if (elementType == String.class) {
        return config.getStringList(configPropName);
    } else if (elementType == Duration.class) {
        return config.getDurationList(configPropName);
    } else if (elementType == ConfigMemorySize.class) {
        return config.getMemorySizeList(configPropName);
    } else if (elementType == Object.class) {
        return config.getAnyRefList(configPropName);
    } else if (elementType == Config.class) {
        return config.getConfigList(configPropName);
    } else if (elementType == ConfigObject.class) {
        return config.getObjectList(configPropName);
    } else if (elementType == ConfigValue.class) {
        return config.getList(configPropName);
    } else {
        throw new ConfigException.BadBean("Bean property '" + configPropName + "' of class " + beanClass.getName() + " has unsupported list element type " + elementType);
    }
}
 
Example #4
Source File: ConfigBeanImpl.java    From mpush with Apache License 2.0 5 votes vote down vote up
private static ConfigValueType getValueTypeOrNull(Class<?> parameterClass) {
    if (parameterClass == Boolean.class || parameterClass == boolean.class) {
        return ConfigValueType.BOOLEAN;
    } else if (parameterClass == Integer.class || parameterClass == int.class) {
        return ConfigValueType.NUMBER;
    } else if (parameterClass == Double.class || parameterClass == double.class) {
        return ConfigValueType.NUMBER;
    } else if (parameterClass == Long.class || parameterClass == long.class) {
        return ConfigValueType.NUMBER;
    } else if (parameterClass == String.class) {
        return ConfigValueType.STRING;
    } else if (parameterClass == Duration.class) {
        return null;
    } else if (parameterClass == ConfigMemorySize.class) {
        return null;
    } else if (parameterClass == List.class) {
        return ConfigValueType.LIST;
    } else if (parameterClass == Map.class) {
        return ConfigValueType.OBJECT;
    } else if (parameterClass == Config.class) {
        return ConfigValueType.OBJECT;
    } else if (parameterClass == ConfigObject.class) {
        return ConfigValueType.OBJECT;
    } else if (parameterClass == ConfigList.class) {
        return ConfigValueType.LIST;
    } else {
        return null;
    }
}
 
Example #5
Source File: TypesafeConfigModuleTest.java    From typesafeconfig-guice with Apache License 2.0 5 votes vote down vote up
@Test
public void canGetFromInjector() {
	for (Injector injector : injectors) {
		Assert.assertTrue(injector.getInstance(Key.get(Boolean.class, TypesafeConfigs.forKeypath("provided.boolean"))));
		Assert.assertTrue(injector.getInstance(Key.get(Boolean.class, TypesafeConfigs.forKeypath("provided.yesBoolean"))));
		Assert.assertEquals(12345679123L, (long)injector.getInstance(Key.get(Long.class, TypesafeConfigs.forKeypath("provided.long"))));
		Assert.assertEquals(1, (int)injector.getInstance(Key.get(Integer.class, TypesafeConfigs.forKeypath("provided.int"))));
		Assert.assertEquals(123, (byte)injector.getInstance(Key.get(Byte.class, TypesafeConfigs.forKeypath("provided.byte"))));
		Assert.assertEquals(2.0, (float)injector.getInstance(Key.get(Float.class, TypesafeConfigs.forKeypath("provided.float"))), 0.001);
		Assert.assertEquals(2.0d, (double)injector.getInstance(Key.get(Double.class, TypesafeConfigs.forKeypath("provided.double"))), 0.001d);
		Assert.assertEquals("test", injector.getInstance(Key.get(String.class, TypesafeConfigs.forKeypath("provided.string"))));
		Assert.assertEquals(Duration.of(10, ChronoUnit.SECONDS), injector.getInstance(Key.get(Duration.class, TypesafeConfigs.forKeypath("provided.duration"))));
		Assert.assertEquals(ConfigMemorySize.ofBytes(524288), injector.getInstance(Key.get(ConfigMemorySize.class, TypesafeConfigs.forKeypath("provided.size"))));

		NestedPojo nestedListPojo = injector.getInstance(Key.get(new TypeLiteral<List<NestedPojo>>(){}, TypesafeConfigs.forKeypath("provided.list.nested"))).get(0);
		Assert.assertEquals(3, nestedListPojo.getNestInt());

		Map<String, Integer> testMap = injector.getInstance(Key.get(new TypeLiteral<Map<String, Integer>>(){}, TypesafeConfigs.forKeypath("provided.map")));
		Assert.assertEquals(1, testMap.get("one").intValue());

		Map<Integer, String> testMapIntkey = injector.getInstance(Key.get(new TypeLiteral<Map<Integer, String>>(){}, TypesafeConfigs.forKeypath("provided.map.intkey")));
		Assert.assertEquals("one", testMapIntkey.get("1"));

		Assert.assertEquals(Arrays.asList(true, false, true), injector.getInstance(Key.get(new TypeLiteral<List<Boolean>>(){}, TypesafeConfigs.forKeypath("provided.list.boolean"))));
		Assert.assertEquals(Arrays.asList(1, 2, 3), injector.getInstance(Key.get(new TypeLiteral<List<Integer>>(){}, TypesafeConfigs.forKeypath("provided.list.integer"))));
		Assert.assertEquals(Arrays.asList(1.1, 2.2, 3.3), injector.getInstance(Key.get(new TypeLiteral<List<Double>>(){}, TypesafeConfigs.forKeypath("provided.list.double"))));
		Assert.assertEquals(Arrays.asList(12345679121L, 12345679122L, 12345679123L), injector.getInstance(Key.get(new TypeLiteral<List<Long>>(){}, TypesafeConfigs.forKeypath("provided.list.long"))));
		Assert.assertEquals(Arrays.asList("a", "b", "c"), injector.getInstance(Key.get(new TypeLiteral<List<String>>(){}, TypesafeConfigs.forKeypath("provided.list.string"))));
		Assert.assertEquals(Arrays.asList(Duration.of(1, ChronoUnit.SECONDS), Duration.of(2, ChronoUnit.SECONDS), Duration.of(3, ChronoUnit.SECONDS)), injector.getInstance(Key.get(new TypeLiteral<List<Duration>>(){}, TypesafeConfigs.forKeypath("provided.list.duration"))));
		Assert.assertEquals(Arrays.asList(ConfigMemorySize.ofBytes(524288), ConfigMemorySize.ofBytes(1048576), ConfigMemorySize.ofBytes(1073741824)), injector.getInstance(Key.get(new TypeLiteral<List<ConfigMemorySize>>(){}, TypesafeConfigs.forKeypath("provided.list.size"))));
	}
}
 
Example #6
Source File: TypesafeConfigModuleTest.java    From typesafeconfig-guice with Apache License 2.0 5 votes vote down vote up
private void assertPojoIsCorrect(TestPojo pojo) {
	Assert.assertTrue(pojo.isTestBoolean());
	Assert.assertTrue(pojo.isTestYesBoolean());
	Assert.assertEquals(12345679123l, pojo.getTestLong());
	Assert.assertEquals(1, pojo.getTestInt());
	Assert.assertEquals(123, pojo.getTestByte());
	Assert.assertEquals(2.0, pojo.getTestDouble(), 0.001);
	Assert.assertEquals(2.0f, pojo.getTestFloat(), 0.001);
	Assert.assertEquals("test", pojo.getTestString());
	Assert.assertEquals(Duration.of(10, ChronoUnit.SECONDS), pojo.getTestDuration());
	Assert.assertEquals(ConfigMemorySize.ofBytes(524288), pojo.getTestSize());
	
	NestedPojo nestedListPojo = pojo.getTestListOfNested().get(0);
	Assert.assertEquals(3, nestedListPojo.getNestInt());
	
	Map<String, Integer> testMap = pojo.getTestMap();
	Assert.assertEquals(1, testMap.get("one").intValue());

	Map<Integer, String> testMapIntkey = pojo.getTestMapIntkey();
	Assert.assertEquals("one", testMapIntkey.get("1"));
	
	Assert.assertEquals(Arrays.asList(true, false, true), pojo.getTestListOfBoolean());
	Assert.assertEquals(Arrays.asList(1, 2, 3), pojo.getTestListOfInteger());
	Assert.assertEquals(Arrays.asList(1.1, 2.2, 3.3), pojo.getTestListOfDouble());
	Assert.assertEquals(Arrays.asList(12345679121L, 12345679122L, 12345679123L), pojo.getTestListOfLong());
	Assert.assertEquals(Arrays.asList("a", "b", "c"), pojo.getTestListOfString());
	Assert.assertEquals(Arrays.asList(Duration.of(1, ChronoUnit.SECONDS), Duration.of(2, ChronoUnit.SECONDS), Duration.of(3, ChronoUnit.SECONDS)), pojo.getTestListOfDuration());
	Assert.assertEquals(Arrays.asList(ConfigMemorySize.ofBytes(524288), ConfigMemorySize.ofBytes(1048576), ConfigMemorySize.ofBytes(1073741824)), pojo.getTestListOfSize());
}
 
Example #7
Source File: DittoServiceConfig.java    From ditto with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public List<ConfigMemorySize> getMemorySizeList(final String path) {
    return serviceScopedConfig.getMemorySizeList(path);
}
 
Example #8
Source File: ConstructorInjectedPojo.java    From typesafeconfig-guice with Apache License 2.0 4 votes vote down vote up
public ConfigMemorySize getTestSize() {
	return testSize;
}
 
Example #9
Source File: ConstructorInjectedPojo.java    From typesafeconfig-guice with Apache License 2.0 4 votes vote down vote up
public List<ConfigMemorySize> getTestListOfSize() {
	return testListOfSize;
}
 
Example #10
Source File: ConstructorInjectedPojo.java    From typesafeconfig-guice with Apache License 2.0 4 votes vote down vote up
@Inject
public ConstructorInjectedPojo(
	@TypesafeConfig("constructor.boolean") boolean testBoolean,	
	@TypesafeConfig("constructor.boolean") boolean testBooleanAgain,	
	@TypesafeConfig("constructor.yesBoolean") boolean testYesBoolean,	
	@TypesafeConfig("constructor.long") long testLong,	
	@TypesafeConfig("constructor.byte") byte testByte,	
	@TypesafeConfig("constructor.int") int testInt,	
	@TypesafeConfig("constructor.double") double testDouble,
	@TypesafeConfig("constructor.float") float testFloat,
	@TypesafeConfig("constructor.string") String testString,
	@TypesafeConfig("constructor.list.boolean") List<Boolean> testListOfBoolean,
	@TypesafeConfig("constructor.list.integer") List<Integer> testListOfInteger,
	@TypesafeConfig("constructor.list.double") List<Double> testListOfDouble,
	@TypesafeConfig("constructor.list.long") List<Long> testListOfLong,
	@TypesafeConfig("constructor.list.string") List<String> testListOfString,
	@TypesafeConfig("constructor.list.duration") List<Duration> testListOfDuration,
	@TypesafeConfig("constructor.list.size") List<ConfigMemorySize> testListOfSize,
	@TypesafeConfig("constructor.list.nested") List<NestedPojo> testListOfNested,
	@TypesafeConfig("constructor.duration") Duration testDuration,
	@TypesafeConfig("constructor.size") ConfigMemorySize testSize,
	@TypesafeConfig("constructor.map") Map<String, Integer> testMap,
	@TypesafeConfig("constructor.map.intkey") Map<Integer, String> testMapIntkey,
	@TypesafeConfig("constructor.nested") NestedPojo testNestedPojo
) {
	this.testBoolean = testBoolean;
	this.testYesBoolean = testYesBoolean;
	this.testLong = testLong;
	this.testByte = testByte;
	this.testInt = testInt;
	this.testDouble = testDouble;
	this.testFloat = testFloat;
	this.testString = testString;
	this.testListOfBoolean = testListOfBoolean;
	this.testListOfInteger = testListOfInteger;
	this.testListOfDouble = testListOfDouble;
	this.testListOfLong = testListOfLong;
	this.testListOfString = testListOfString;
	this.testListOfDuration = testListOfDuration;
	this.testListOfSize = testListOfSize;
	this.testListOfNested = testListOfNested;
	this.testDuration = testDuration;
	this.testSize = testSize;
	this.testMap = testMap;
	this.testMapIntkey = testMapIntkey;
	this.testNestedPojo = testNestedPojo;
}
 
Example #11
Source File: FieldInjectedPojo.java    From typesafeconfig-guice with Apache License 2.0 4 votes vote down vote up
public ConfigMemorySize getTestSize() {
	return testSize;
}
 
Example #12
Source File: FieldInjectedPojo.java    From typesafeconfig-guice with Apache License 2.0 4 votes vote down vote up
public List<ConfigMemorySize> getTestListOfSize() {
	return testListOfSize;
}
 
Example #13
Source File: ProvidedPojo.java    From typesafeconfig-guice with Apache License 2.0 4 votes vote down vote up
public ConfigMemorySize getTestSize() {
	return testSize;
}
 
Example #14
Source File: ProvidedPojo.java    From typesafeconfig-guice with Apache License 2.0 4 votes vote down vote up
public List<ConfigMemorySize> getTestListOfSize() {
	return testListOfSize;
}
 
Example #15
Source File: ProvidedPojo.java    From typesafeconfig-guice with Apache License 2.0 4 votes vote down vote up
public ProvidedPojo(
	boolean testBoolean,                                                         
	boolean testYesBoolean,                                                      
	long testLong,                                                               
	byte testByte,                                                               
	int testInt,                                                                 
	double testDouble,                                                           
	float testFloat,                                                             
	String testString,                                                           
	List<Boolean> testListOfBoolean,                                             
	List<Integer> testListOfInteger,                                             
	List<Double> testListOfDouble,                                               
	List<Long> testListOfLong,                                                   
	List<String> testListOfString,                                               
	List<Duration> testListOfDuration,                                           
	List<ConfigMemorySize> testListOfSize,                                       
	List<NestedPojo> testListOfNested,                                           
	Duration testDuration,                                                       
	ConfigMemorySize testSize,                                                   
	Map<String, Integer> testMap,                                                
	Map<Integer, String> testMapIntkey,                                          
	NestedPojo testNestedPojo                                  
) {
	this.testBoolean = testBoolean;
	this.testYesBoolean = testYesBoolean;
	this.testLong = testLong;
	this.testByte = testByte;
	this.testInt = testInt;
	this.testDouble = testDouble;
	this.testFloat = testFloat;
	this.testString = testString;
	this.testListOfBoolean = testListOfBoolean;
	this.testListOfInteger = testListOfInteger;
	this.testListOfDouble = testListOfDouble;
	this.testListOfLong = testListOfLong;
	this.testListOfString = testListOfString;
	this.testListOfDuration = testListOfDuration;
	this.testListOfSize = testListOfSize;
	this.testListOfNested = testListOfNested;
	this.testDuration = testDuration;
	this.testSize = testSize;
	this.testMap = testMap;
	this.testMapIntkey = testMapIntkey;
	this.testNestedPojo = testNestedPojo;
}
 
Example #16
Source File: MethodInjectedPojo.java    From typesafeconfig-guice with Apache License 2.0 4 votes vote down vote up
public ConfigMemorySize getTestSize() {
	return testSize;
}
 
Example #17
Source File: MethodInjectedPojo.java    From typesafeconfig-guice with Apache License 2.0 4 votes vote down vote up
public List<ConfigMemorySize> getTestListOfSize() {
	return testListOfSize;
}
 
Example #18
Source File: MethodInjectedPojo.java    From typesafeconfig-guice with Apache License 2.0 4 votes vote down vote up
@Inject
public void setTestSize(@TypesafeConfig("method.size") ConfigMemorySize testSize) {
	this.testSize = testSize;
}
 
Example #19
Source File: MethodInjectedPojo.java    From typesafeconfig-guice with Apache License 2.0 4 votes vote down vote up
@Inject
public void setTestListOfSize(@TypesafeConfig("method.list.size") List<ConfigMemorySize> testListOfSize) {
	this.testListOfSize = testListOfSize;
}
 
Example #20
Source File: TypesafeConfigModuleTest.java    From typesafeconfig-guice with Apache License 2.0 4 votes vote down vote up
private Module createTestModule() {

		Module testModule = new AbstractModule() {
			@Override
			protected void configure() {
				bind(ConstructorInjectedPojo.class).asEagerSingleton();
				bind(FieldInjectedPojo.class).asEagerSingleton();
				bind(MethodInjectedPojo.class).asEagerSingleton();
			}

			@Provides
			@Singleton
			ProvidedPojo providePojo(
					@TypesafeConfig("provided.boolean") 	  boolean testBoolean,
					@TypesafeConfig("provided.yesBoolean") 	  boolean testYesBoolean,
					@TypesafeConfig("provided.long") 		  long testLong,
					@TypesafeConfig("provided.byte") 		  byte testByte,
					@TypesafeConfig("provided.int") 		  int testInt,
					@TypesafeConfig("provided.double") 		  double testDouble,
					@TypesafeConfig("provided.float") 		  float testFloat,
					@TypesafeConfig("provided.string") 		  String testString,
					@TypesafeConfig("provided.list.boolean")  List<Boolean> testListOfBoolean,
					@TypesafeConfig("provided.list.integer")  List<Integer> testListOfInteger,
					@TypesafeConfig("provided.list.double")   List<Double> testListOfDouble,
					@TypesafeConfig("provided.list.long") 	  List<Long> testListOfLong,
					@TypesafeConfig("provided.list.string")   List<String> testListOfString,
					@TypesafeConfig("provided.list.duration") List<Duration> testListOfDuration,
					@TypesafeConfig("provided.list.size") 	  List<ConfigMemorySize> testListOfSize,
					@TypesafeConfig("provided.list.nested")   List<NestedPojo> testListOfNested,
					@TypesafeConfig("provided.duration") 	  Duration testDuration,
					@TypesafeConfig("provided.size") 		  ConfigMemorySize testSize,
					@TypesafeConfig("provided.map") 		  Map<String, Integer> testMap,
					@TypesafeConfig("provided.map.intkey") 	  Map<Integer, String> testMapIntkey,
					@TypesafeConfig("provided.nested") 		  NestedPojo testNestedPojo
			) {
				return new ProvidedPojo(testBoolean, testYesBoolean, testLong, testByte, testInt, testDouble, testFloat, testString, testListOfBoolean, testListOfInteger, testListOfDouble, testListOfLong, testListOfString, testListOfDuration, testListOfSize, testListOfNested, testDuration, testSize, testMap, testMapIntkey, testNestedPojo);
			}

		};
		return testModule;
	}
 
Example #21
Source File: ConfigBeanImpl.java    From mpush with Apache License 2.0 4 votes vote down vote up
private static Object getValue(Class<?> beanClass, Type parameterType, Class<?> parameterClass, Config config,
                               String configPropName) {
    if (parameterClass == Boolean.class || parameterClass == boolean.class) {
        return config.getBoolean(configPropName);
    } else if (parameterClass == Integer.class || parameterClass == int.class) {
        return config.getInt(configPropName);
    } else if (parameterClass == Double.class || parameterClass == double.class) {
        return config.getDouble(configPropName);
    } else if (parameterClass == Long.class || parameterClass == long.class) {
        return config.getLong(configPropName);
    } else if (parameterClass == String.class) {
        return config.getString(configPropName);
    } else if (parameterClass == Duration.class) {
        return config.getDuration(configPropName);
    } else if (parameterClass == ConfigMemorySize.class) {
        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);
    } else if (parameterClass == Map.class) {
        // we could do better here, but right now we don't.
        Type[] typeArgs = ((ParameterizedType) parameterType).getActualTypeArguments();
        if (typeArgs[0] != String.class || typeArgs[1] != Object.class) {
            throw new ConfigException.BadBean("Bean property '" + configPropName + "' of class " + beanClass.getName() + " has unsupported Map<" + typeArgs[0] + "," + typeArgs[1] + ">, only Map<String,Object> is supported right now");
        }
        return config.getObject(configPropName).unwrapped();
    } else if (parameterClass == Config.class) {
        return config.getConfig(configPropName);
    } else if (parameterClass == ConfigObject.class) {
        return config.getObject(configPropName);
    } else if (parameterClass == ConfigValue.class) {
        return config.getValue(configPropName);
    } else if (parameterClass == ConfigList.class) {
        return config.getList(configPropName);
    } else if (hasAtLeastOneBeanProperty(parameterClass)) {
        return createInternal(config.getConfig(configPropName), parameterClass);
    } else {
        throw new ConfigException.BadBean("Bean property " + configPropName + " of class " + beanClass.getName() + " has unsupported type " + parameterType);
    }
}
 
Example #22
Source File: ConfigWithFallback.java    From ditto with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public List<ConfigMemorySize> getMemorySizeList(final String path) {
    return baseConfig.getMemorySizeList(path);
}
 
Example #23
Source File: ConfigWithFallback.java    From ditto with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public ConfigMemorySize getMemorySize(final String path) {
    return baseConfig.getMemorySize(path);
}
 
Example #24
Source File: DittoServiceConfig.java    From ditto with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public ConfigMemorySize getMemorySize(final String path) {
    return serviceScopedConfig.getMemorySize(path);
}
 
Example #25
Source File: TestPojo.java    From typesafeconfig-guice with Apache License 2.0 votes vote down vote up
public ConfigMemorySize getTestSize(); 
Example #26
Source File: TestPojo.java    From typesafeconfig-guice with Apache License 2.0 votes vote down vote up
public List<ConfigMemorySize> getTestListOfSize();