From 0956393cf366f493a629eebf28c3f9c7f8520077 Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Wed, 10 Dec 2008 16:32:26 +0000 Subject: [PATCH] add int getProperty(String prop, int default) --- core/java/src/net/i2p/I2PAppContext.java | 19 +++++++++++++++++++ .../src/net/i2p/router/RouterContext.java | 17 +++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/core/java/src/net/i2p/I2PAppContext.java b/core/java/src/net/i2p/I2PAppContext.java index cac8cdb29e..3e514ea18b 100644 --- a/core/java/src/net/i2p/I2PAppContext.java +++ b/core/java/src/net/i2p/I2PAppContext.java @@ -179,6 +179,25 @@ public class I2PAppContext { return System.getProperty(propName, defaultValue); } + /** + * Return an int with an int default + */ + public int getProperty(String propName, int defaultVal) { + String val = null; + if (_overrideProps != null) { + val = _overrideProps.getProperty(propName); + if (val == null) + val = System.getProperty(propName); + } + int ival = defaultVal; + if (val != null) { + try { + ival = Integer.parseInt(val); + } catch (NumberFormatException nfe) {} + } + return ival; + } + /** * Access the configuration attributes of this context, listing the properties * provided during the context construction, as well as the ones included in diff --git a/router/java/src/net/i2p/router/RouterContext.java b/router/java/src/net/i2p/router/RouterContext.java index 8b34f63641..087cde9184 100644 --- a/router/java/src/net/i2p/router/RouterContext.java +++ b/router/java/src/net/i2p/router/RouterContext.java @@ -329,6 +329,23 @@ public class RouterContext extends I2PAppContext { return super.getProperty(propName, defaultVal); } + /** + * Return an int with an int default + */ + public int getProperty(String propName, int defaultVal) { + if (_router != null) { + String val = _router.getConfigSetting(propName); + if (val != null) { + int ival = defaultVal; + try { + ival = Integer.parseInt(val); + } catch (NumberFormatException nfe) {} + return ival; + } + } + return super.getProperty(propName, defaultVal); + } + /** * The context's synchronized clock, which is kept context specific only to * enable simulators to play with clock skew among different instances. -- GitLab