Class Section
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescription<T> Optional<T>Shortcut for callingasBean(sectionName, c,.false )<T> Optional<T>Converts this config file section to the specified bean instance.<T> Optional<T>asInterface(Class<T> c) Wraps this section inside a Java interface so that values in the section can be read and write using getters and setters.asMap()Returns this section as a map.booleanReturnstrue if this section exists.writeToBean(Object bean, boolean ignoreUnknownProperties) Copies the entries in this section to the specified bean by calling the public setters on that bean.
- 
Constructor Details- 
SectionConstructor.- Parameters:
- config- The config that this entry belongs to.
- configMap- The map that this belongs to.
- name- The section name of this entry.
 
 
- 
- 
Method Details- 
isPresentReturnstrue if this section exists.- Returns:
- true if this section exists.
 
- 
asBeanShortcut for callingasBean(sectionName, c,.false )- Type Parameters:
- T- The bean class to create.
- Parameters:
- c- The bean class to create.
- Returns:
- A new bean instance, or Optional.empty()if this section does not exist.
- Throws:
- ParseException- Malformed input encountered.
 
- 
asBeanConverts this config file section to the specified bean instance.Key/value pairs in the config file section get copied as bean property values to the specified bean class. Example config file[MyAddress] name =John Smith street =123 Main Street city =Anywhere state =NY zip =12345 Example beanpublic class Address {public Stringname ,street ,city ;public StateEnumstate ;public int zip ; }Example usageConfig config = Config.create ().name("MyConfig.cfg" ).build(); Addressaddress =config .getSection("MySection" ).asBean(Address.class ).orElse(null );- Type Parameters:
- T- The bean class to create.
- Parameters:
- c- The bean class to create.
- ignoreUnknownProperties- If- false , throws a- ParseExceptionif the section contains an entry that isn't a bean property name.
- Returns:
- A new bean instance, or null if this section doesn't exist.
- Throws:
- ParseException- Unknown property was encountered in section.
 
- 
asMapReturns this section as a map.- Returns:
- A new JsonMap, orOptional.empty()if this section doesn't exist.
 
- 
asInterfaceWraps this section inside a Java interface so that values in the section can be read and write using getters and setters.Example config file[MySection] string =foo int =123 enum =ONE bean ={foo:'bar',baz:123} int3dArray =[[[123,null],null],null] bean1d3dListMap ={key:[[[[{foo:'bar',baz:123}]]]]} Example interfacepublic interface MyConfigInterface { String getString();void setString(Stringvalue );int getInt();void setInt(int value ); MyEnum getEnum();void setEnum(MyEnumvalue ); MyBean getBean();void setBean(MyBeanvalue );int [][][] getInt3dArray();void setInt3dArray(int [][][]value ); Map<String,List<MyBean[][][]>> getBean1d3dListMap();void setBean1d3dListMap(Map<String,List<MyBean[][][]>>value ); }Example usageConfig config = Config.create ().name("MyConfig.cfg" ).build(); MyConfigInterfaceci =config .get("MySection" ).asInterface(MyConfigInterface.class ).orElse(null );int myInt =ci .getInt();ci .setBean(new MyBean());ci .save();Notes:- Calls to setters when the configuration is read-only will cause UnsupportedOperationExceptionto be thrown.
 - Type Parameters:
- T- The proxy interface class.
- Parameters:
- c- The proxy interface class.
- Returns:
- The proxy interface.
 
- Calls to setters when the configuration is read-only will cause 
- 
writeToBeanCopies the entries in this section to the specified bean by calling the public setters on that bean.- Parameters:
- bean- The bean to set the properties on.
- ignoreUnknownProperties- If- true , don't throw an- IllegalArgumentExceptionif this section contains a key that doesn't correspond to a setter method.
- Returns:
- An object map of the changes made to the bean.
- Throws:
- ParseException- If parser was not set on this config file or invalid properties were found in the section.
- UnsupportedOperationException- If configuration is read only.
 
 
-