Options (org.ini4j.Options) is a java.util.Properties replacement with several useful features, like:
player.name = Joe player.greetings = Hi ${player.name}! player.domain = foo.bar player.email = ${player.name}@${player.domain}
player.fortuneNumber = 33 player.fortuneNumber = 44 player.fortuneNumber = 55 player.fortuneNumber = 66 magicNumber = ${player.foruneNumber[1]}
The magicNumber property will have value: 44
With standard Properties class there is several small problem. Most of them came from backward compatibility.
As side effect of [ini4j] development, there is a solution for aboves. This is the org.ini4j.Options class, which is basicly a feature rich replacement for java.util.Properties.
Code sniplets in this tutorial tested with the following .opt file: dwarfs.opt
There is nothing special with instantiating Options object, but there is a few constructor, to simplify loading data. These constructors simply call the load() method on newly created instance. Ofcource these constructors are throws IOException.
void sample01(File file) throws IOException { Options opt = new Options(); // // or instantiate and load data: // opt = new Options(new FileReader(file));
void sample02(Options opt) { Set<String> optionNames = opt.keySet(); // String age = opt.get("age"); String weight = opt.fetch("weight"); String height = opt.fetch("height");
The Options is a MultiMap<String,String>, that is, a map that assigns String values to String keys. So the get method is used to get values inside the options. To get a value, besides get() you can also use fetch() which resolves any occurrent ${option} format variable references in the needed value.