bacoAlunos
ENGSOFT2019
BlueGrey
calm
Elegant
Català-Valencià - Catalan
中文 - Chinese (Simplified)
中文 - Chinese (Traditional)
Česky - Czech
Dansk - Danish
Nederlands - Dutch
English - English
Suomi - Finnish
Français - French
Deutsch - German
עברית - Hebrew
हिंदी - Hindi
Magyar - Hungarian
Bahasa Indonesia - Indonesian
Italiano - Italian
日本語 - Japanese
한국어 - Korean
मराठी - Marathi
Norsk - Norwegian
Polski - Polish
Português - Portuguese
Português - Portuguese (Brazil)
Русский - Russian
Slovenčina - Slovak
Slovenščina - Slovenian
Español - Spanish
Svenska - Swedish
Türkçe - Turkish
Oëzbekcha - Uzbek
Subversion Repositories
bacoAlunos
(root)
/
impl
/
src
/
java
/
jomm
/
utils
/
PropertiesUtils.java
@ 1
- Rev
Rev
Blame
|
Compare with Previous
|
Last modification
|
View Log
|
RSS feed
package
jomm.utils
;
import
org.apache.log4j.Logger
;
import
java.util.*
;
/**
* Class Description
*
* @author Jorge Machado <machadofisher@gmail.com>
*
*/
public
class
PropertiesUtils
{
private
static
final
1.
5
.0/docs/api/java/util/logging/Logger.html">
Logger
logger =
1.
5
.0/docs/api/java/util/logging/Logger.html">
Logger
.
getLogger
(
PropertiesUtils.
class
)
;
/**
*
* @param p properties in use
* @param propertyPrefix to find
* @return a list of all property names hat starts with the given prefix
*
*/
public
static
List
<
String
>
getListProperties
(
1.
5
.0/docs/api/java/util/Properties.html">
Properties
p,
1.
5
.0/docs/api/java/lang/String.html">
String
propertyPrefix
)
{
List
<
String
>
props =
new
ArrayList
<
String
>
(
)
;
Enumeration
<?>
enumE
;
try
{
enumE = p.
propertyNames
(
)
;
}
catch
(
1.
5
.0/docs/api/java/lang/Exception.html">
Exception
e
)
{
PropertiesUtils.
logger
.
fatal
(
"cant load properties"
)
;
return
null
;
}
while
(
enumE.
hasMoreElements
(
)
)
{
1.
5
.0/docs/api/java/lang/String.html">
String
propertyName =
(
1.
5
.0/docs/api/java/lang/String.html">
String
)
enumE.
nextElement
(
)
;
if
(
propertyName.
startsWith
(
propertyPrefix
)
)
{
props.
add
(
propertyName
)
;
}
}
1.
5
.0/docs/api/java/util/Collections.html">
Collections
.
sort
(
props, StringComparator.
getInstance
(
)
)
;
return
props
;
}
/**
* @param p to use
* @param propertyPrefix to find
* @return a list of values
*/
public
static
List
<
String
>
getListValuesOrderedByPropertyName
(
1.
5
.0/docs/api/java/util/Properties.html">
Properties
p,
1.
5
.0/docs/api/java/lang/String.html">
String
propertyPrefix
)
{
List
<
String
>
props =
new
ArrayList
<
String
>
(
)
;
List
<
String
>
properties = PropertiesUtils.
getListProperties
(
p,propertyPrefix
)
;
for
(
5+
0
%
2Fdocs
%
2Fapi+Object">
Object
property1 : properties
)
{
1.
5
.0/docs/api/java/lang/String.html">
String
property =
(
1.
5
.0/docs/api/java/lang/String.html">
String
)
property1
;
props.
add
(
p.
getProperty
(
property
)
)
;
}
return
props
;
}
/**
* Get property and convert it to float
*
* @param property to get and convert
* @return float value
* @param props to use
*/
public
static
float
getFloatProperty
(
1.
5
.0/docs/api/java/lang/String.html">
String
property,
1.
5
.0/docs/api/java/util/Properties.html">
Properties
props
)
{
1.
5
.0/docs/api/java/lang/String.html">
String
stringValue = props.
getProperty
(
property
)
;
float
floatValue =
0
;
if
(
stringValue
!
=
null
)
{
try
{
floatValue =
new
1.
5
.0/docs/api/java/lang/Float.html">
Float
(
stringValue
)
;
}
catch
(
1.
5
.0/docs/api/java/lang/NumberFormatException.html">
NumberFormatException
e
)
{
e.
printStackTrace
(
)
;
}
}
return
floatValue
;
}
/**
* Get property and convert it to boolean
*
* @param property to get and convert
* @return float value
* @param props to use
*/
public
static
boolean
getBooleanProperty
(
1.
5
.0/docs/api/java/lang/String.html">
String
property,
1.
5
.0/docs/api/java/util/Properties.html">
Properties
props
)
{
1.
5
.0/docs/api/java/lang/String.html">
String
stringValue = props.
getProperty
(
property
)
;
boolean
booleanValue =
false
;
if
(
stringValue
!
=
null
)
{
try
{
booleanValue =
1.
5
.0/docs/api/java/lang/Boolean.html">
Boolean
.
parseBoolean
(
stringValue
)
;
}
catch
(
1.
5
.0/docs/api/java/lang/Exception.html">
Exception
e
)
{
e.
printStackTrace
(
)
;
}
}
return
booleanValue
;
}
/**
* Get property and convert it to float
*
* @param property to get and convert
* @return float value
* @param props to use
*/
public
static
short
getShortProperty
(
1.
5
.0/docs/api/java/lang/String.html">
String
property,
1.
5
.0/docs/api/java/util/Properties.html">
Properties
props
)
{
1.
5
.0/docs/api/java/lang/String.html">
String
stringValue = props.
getProperty
(
property
)
;
short
shortValue =
0
;
if
(
stringValue
!
=
null
)
{
try
{
shortValue =
new
1.
5
.0/docs/api/java/lang/Short.html">
Short
(
stringValue
)
;
}
catch
(
1.
5
.0/docs/api/java/lang/NumberFormatException.html">
NumberFormatException
e
)
{
e.
printStackTrace
(
)
;
}
}
return
shortValue
;
}
/**
* Get property and convert it to float
*
* @param property to get and convert
* @return float value
* @param props to use
*/
public
static
int
getIntProperty
(
1.
5
.0/docs/api/java/lang/String.html">
String
property,
1.
5
.0/docs/api/java/util/Properties.html">
Properties
props
)
{
1.
5
.0/docs/api/java/lang/String.html">
String
stringValue = props.
getProperty
(
property
)
;
int
intValue =
0
;
if
(
stringValue
!
=
null
)
{
try
{
intValue =
new
1.
5
.0/docs/api/java/lang/Integer.html">
Integer
(
stringValue
)
;
}
catch
(
1.
5
.0/docs/api/java/lang/NumberFormatException.html">
NumberFormatException
e
)
{
e.
printStackTrace
(
)
;
}
}
return
intValue
;
}
}