1. What is "Java INI Package"?
  2. What is an INI file?
  3. Why can't you set a value straight from an IniFile object?

What is Java INI Package?

Java INI Package is a small java jar package that provides developers support for reading, writing and manipulating INI files from within Java.

What is an INI file?

see INI Specifications

Why can't you set a value straight from an IniFile object?

To set a value for an item, I must first get a reference to the IniFile object, then the IniSection which contains the item, and then the actual IniItem where I want to set the value. As In:

// assume that "ini" is a reference to an IniFile object
IniSection section = ini.getSection( "setttings" );
IniItem item = section.getItem( "resolution" );
item.setValue( "720 x 400" );

Why can't I just set the value from the IniFile object? Such as:

// assume that "ini" is a reference to an IniFile object
ini.setValue("setttings", "resolution", "720 x 400" );

When I designed the Java INI Package, I made use of a design principle called responsibility, which simply states that one should organise methods based on who is responsible for it. In the case of setting\getting a value to\from an item, it is the responsibility of the IniItem class. The IniSection class is responsible for managing all the items within that section, whilst the IniFile class is responsible for all sections within an INI file.

The advantage of this design principle is that the design is more intuitive. For example, when one passes a name of an item to the method getItem(String) they would intuitivly know that the item with that name would be returned, whereas if one were to do the same with the a method in the IniFile called getItem(String,String), one would not intuitivly know which string referes to the section name and which string refers to the item name.

Furthermore, and by far a bigger advantage, is that the design is more modular. By keeping the responsibility of setting\getting values to\from an IniItem class, the IniFile class does not need to know how a value is stored. And if the IniItem class were to (bizarly) change how it stored a value from a String object to an Object reference, then the IniFile class would not need to be modified as it is not the responsibility of IniFile to deal with the item's value.

If you really need to set a value only using one line of code, you can write:

// assume that "ini" is a reference to an IniFile object
ini.getSection( "setttings" ).getItem( "resolution" ).setValue( "720 x 400" );