Skip to content

Commit

Permalink
Configuration.toString() is now sorted.
Browse files Browse the repository at this point in the history
  • Loading branch information
albertus82 committed May 27, 2015
1 parent c028646 commit a353e0b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
43 changes: 27 additions & 16 deletions src/it/albertus/util/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;

/**
* Classe astratta da estendere con una classe <b>Singleton</b> che richiami il
* costruttore {@link #Configuration(String)} passando come parametro il nome
* del file di configurazione da caricare.
*/
public abstract class Configuration {

private final Properties properties = new Properties();
Expand Down Expand Up @@ -52,127 +59,127 @@ public String getString(String key, String defaultValue) {
}

public Boolean getBoolean(String key) {
String value = getString(key);
final String value = getString(key);
if (value != null) {
return Boolean.valueOf(value.trim());
}
return null;
}

public boolean getBoolean(String key, boolean defaultValue) {
String value = getString(key);
final String value = getString(key);
if (value != null) {
return Boolean.parseBoolean(value.trim());
}
return defaultValue;
}

public Long getLong(String key) {
String value = getString(key);
final String value = getString(key);
if (value != null) {
return Long.valueOf(value);
}
return null;
}

public long getLong(String key, long defaultValue) {
String value = getString(key);
final String value = getString(key);
if (value != null) {
return Long.parseLong(value);
}
return defaultValue;
}

public Integer getInt(String key) {
String value = getString(key);
final String value = getString(key);
if (value != null) {
return Integer.valueOf(value);
}
return null;
}

public int getInt(String key, int defaultValue) {
String value = getString(key);
final String value = getString(key);
if (value != null) {
return Integer.parseInt(value);
}
return defaultValue;
}

public Short getShort(String key) {
String value = getString(key);
final String value = getString(key);
if (value != null) {
return Short.valueOf(value);
}
return null;
}

public short getShort(String key, short defaultValue) {
String value = getString(key);
final String value = getString(key);
if (value != null) {
return Short.parseShort(value);
}
return defaultValue;
}

public Byte getByte(String key) {
String value = getString(key);
final String value = getString(key);
if (value != null) {
return Byte.valueOf(value);
}
return null;
}

public byte getByte(String key, byte defaultValue) {
String value = getString(key);
final String value = getString(key);
if (value != null) {
return Byte.parseByte(value);
}
return defaultValue;
}

public Float getFloat(String key) {
String value = getString(key);
final String value = getString(key);
if (value != null) {
return Float.valueOf(value);
}
return null;
}

public float getFloat(String key, float defaultValue) {
String value = getString(key);
final String value = getString(key);
if (value != null) {
return Float.parseFloat(value);
}
return defaultValue;
}

public Double getDouble(String key) {
String value = getString(key);
final String value = getString(key);
if (value != null) {
return Double.valueOf(value);
}
return null;
}

public double getDouble(String key, double defaultValue) {
String value = getString(key);
final String value = getString(key);
if (value != null) {
return Double.parseDouble(value);
}
return defaultValue;
}

public Character getChar(String key) {
String value = getString(key);
final String value = getString(key);
if (value != null) {
return parseChar(value);
}
return null;
}

public char getChar(String key, char defaultValue) {
String value = getString(key);
final String value = getString(key);
if (value != null) {
return parseChar(value);
}
Expand All @@ -194,6 +201,10 @@ public boolean contains(String key) {

@Override
public String toString() {
final Map<String, String> properties = new TreeMap<String, String>();
for (final Object key : this.properties.keySet()) {
properties.put((String) key, this.properties.getProperty((String) key));
}
return properties.toString();
}

Expand Down
4 changes: 2 additions & 2 deletions src/version.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version.number=1.0.2
version.date=2015-05-26
version.number=1.0.3
version.date=2015-05-27

0 comments on commit a353e0b

Please sign in to comment.