Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
4de13b24
Unverified
提交
4de13b24
authored
7 年前
作者:
Noel Grandin
提交者:
GitHub
7 年前
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #811 from katzyn/misc
Issues with Boolean.parseBoolean()
上级
144aec21
c2bcac16
显示空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
77 行增加
和
19 行删除
+77
-19
SettingsBase.java
h2/src/main/org/h2/engine/SettingsBase.java
+3
-3
SimpleResultSet.java
h2/src/main/org/h2/tools/SimpleResultSet.java
+20
-3
SortedProperties.java
h2/src/main/org/h2/util/SortedProperties.java
+2
-3
Utils.java
h2/src/main/org/h2/util/Utils.java
+30
-9
ValueTimestamp.java
h2/src/main/org/h2/value/ValueTimestamp.java
+1
-1
TestTools.java
h2/src/test/org/h2/test/unit/TestTools.java
+21
-0
没有找到文件。
h2/src/main/org/h2/engine/SettingsBase.java
浏览文件 @
4de13b24
...
...
@@ -30,10 +30,10 @@ public class SettingsBase {
* @return the setting
*/
protected
boolean
get
(
String
key
,
boolean
defaultValue
)
{
String
s
=
get
(
key
,
""
+
defaultValue
);
String
s
=
get
(
key
,
Boolean
.
toString
(
defaultValue
)
);
try
{
return
Boolean
.
parseBoolean
(
s
);
}
catch
(
NumberForma
tException
e
)
{
return
Utils
.
parseBoolean
(
s
,
defaultValue
,
true
);
}
catch
(
IllegalArgumen
tException
e
)
{
throw
DbException
.
get
(
ErrorCode
.
DATA_CONVERSION_ERROR_1
,
e
,
"key:"
+
key
+
" value:"
+
s
);
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/tools/SimpleResultSet.java
浏览文件 @
4de13b24
...
...
@@ -8,6 +8,7 @@ package org.h2.tools;
import
java.io.InputStream
;
import
java.io.Reader
;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
import
java.net.URL
;
import
java.sql.Array
;
import
java.sql.Blob
;
...
...
@@ -478,10 +479,26 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData,
@Override
public
boolean
getBoolean
(
int
columnIndex
)
throws
SQLException
{
Object
o
=
get
(
columnIndex
);
if
(
o
!=
null
&&
!(
o
instanceof
Boolean
))
{
o
=
Boolean
.
valueOf
(
o
.
toString
());
if
(
o
==
null
)
{
return
false
;
}
if
(
o
instanceof
Boolean
)
{
return
(
Boolean
)
o
;
}
if
(
o
instanceof
Number
)
{
Number
n
=
(
Number
)
o
;
if
(
n
instanceof
Double
||
n
instanceof
Float
)
{
return
n
.
doubleValue
()
!=
0
;
}
if
(
n
instanceof
BigDecimal
)
{
return
((
BigDecimal
)
n
).
signum
()
!=
0
;
}
if
(
n
instanceof
BigInteger
)
{
return
((
BigInteger
)
n
).
signum
()
!=
0
;
}
return
n
.
longValue
()
!=
0
;
}
return
o
==
null
?
false
:
((
Boolean
)
o
).
booleanValue
(
);
return
Boolean
.
parseBoolean
(
o
.
toString
()
);
}
/**
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/util/SortedProperties.java
浏览文件 @
4de13b24
...
...
@@ -52,10 +52,9 @@ public class SortedProperties extends Properties {
*/
public
static
boolean
getBooleanProperty
(
Properties
prop
,
String
key
,
boolean
def
)
{
String
value
=
prop
.
getProperty
(
key
,
""
+
def
);
try
{
return
Boolean
.
parseBoolean
(
val
ue
);
}
catch
(
Exception
e
)
{
return
Utils
.
parseBoolean
(
prop
.
getProperty
(
key
,
null
),
def
,
tr
ue
);
}
catch
(
IllegalArgument
Exception
e
)
{
e
.
printStackTrace
();
return
def
;
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/util/Utils.java
浏览文件 @
4de13b24
...
...
@@ -642,6 +642,35 @@ public class Utils {
return
clazz
;
}
/**
* Parses the specified string to boolean value.
*
* @param value
* string to parse
* @param defaultValue
* value to return if value is null or on parsing error
* @param throwException
* throw exception on parsing error or return default value instead
* @return parsed or default value
* @throws IllegalArgumentException
* on parsing error if {@code throwException} is true
*/
public
static
boolean
parseBoolean
(
String
value
,
boolean
defaultValue
,
boolean
throwException
)
{
if
(
value
==
null
)
{
return
defaultValue
;
}
if
(
value
.
equalsIgnoreCase
(
"true"
))
{
return
true
;
}
if
(
value
.
equalsIgnoreCase
(
"false"
))
{
return
false
;
}
if
(
throwException
)
{
throw
new
IllegalArgumentException
(
value
);
}
return
defaultValue
;
}
/**
* Get the system property. If the system property is not set, or if a
* security exception occurs, the default value is returned.
...
...
@@ -687,15 +716,7 @@ public class Utils {
* @return the value
*/
public
static
boolean
getProperty
(
String
key
,
boolean
defaultValue
)
{
String
s
=
getProperty
(
key
,
null
);
if
(
s
!=
null
)
{
try
{
return
Boolean
.
parseBoolean
(
s
);
}
catch
(
NumberFormatException
e
)
{
// ignore
}
}
return
defaultValue
;
return
parseBoolean
(
getProperty
(
key
,
null
),
defaultValue
,
false
);
}
/**
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/value/ValueTimestamp.java
浏览文件 @
4de13b24
...
...
@@ -216,7 +216,7 @@ public class ValueTimestamp extends Value {
tz
,
year
,
month
,
day
,
hour
,
minute
,
(
int
)
second
,
(
int
)
ms
);
ms
=
DateTimeUtils
.
convertToLocal
(
new
Date
(
millis
),
DateTimeUtils
.
createGregorianCalendar
(
TimeZone
.
getTimeZone
(
"UTC"
)
));
DateTimeUtils
.
createGregorianCalendar
(
DateTimeUtils
.
UTC
));
long
md
=
DateTimeUtils
.
MILLIS_PER_DAY
;
long
absoluteDay
=
(
ms
>=
0
?
ms
:
ms
-
md
+
1
)
/
md
;
dateValue
=
DateTimeUtils
.
dateValueFromAbsoluteDay
(
absoluteDay
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestTools.java
浏览文件 @
4de13b24
...
...
@@ -18,6 +18,7 @@ import java.io.Writer;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
import
java.net.ServerSocket
;
import
java.net.Socket
;
import
java.nio.charset.StandardCharsets
;
...
...
@@ -257,6 +258,8 @@ public class TestTools extends TestBase {
Clob
clob
=
new
SimpleClob
(
"Hello World"
);
Blob
blob
=
new
SimpleBlob
(
new
byte
[]{(
byte
)
1
,
(
byte
)
2
});
rs
.
addRow
(
1
,
b
,
true
,
d
,
"10.3"
,
Math
.
PI
,
"-3"
,
a
,
t
,
ts
,
clob
,
blob
);
rs
.
addRow
(
BigInteger
.
ONE
,
null
,
true
,
null
,
BigDecimal
.
ONE
,
1
d
,
null
,
null
,
null
,
null
,
null
);
rs
.
addRow
(
BigInteger
.
ZERO
,
null
,
false
,
null
,
BigDecimal
.
ZERO
,
0
d
,
null
,
null
,
null
,
null
,
null
);
rs
.
addRow
(
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
);
rs
.
next
();
...
...
@@ -270,6 +273,7 @@ public class TestTools extends TestBase {
assertEquals
((
short
)
1
,
rs
.
getShort
(
"a"
));
assertTrue
(
rs
.
getObject
(
1
).
getClass
()
==
Integer
.
class
);
assertTrue
(
rs
.
getObject
(
"a"
).
getClass
()
==
Integer
.
class
);
assertTrue
(
rs
.
getBoolean
(
1
));
assertEquals
(
b
,
rs
.
getBytes
(
2
));
assertEquals
(
b
,
rs
.
getBytes
(
"b"
));
...
...
@@ -288,6 +292,7 @@ public class TestTools extends TestBase {
assertTrue
(
Math
.
PI
==
rs
.
getDouble
(
"f"
));
assertTrue
((
float
)
Math
.
PI
==
rs
.
getFloat
(
6
));
assertTrue
((
float
)
Math
.
PI
==
rs
.
getFloat
(
"f"
));
assertTrue
(
rs
.
getBoolean
(
6
));
assertEquals
(-
3
,
rs
.
getInt
(
7
));
assertEquals
(-
3
,
rs
.
getByte
(
7
));
...
...
@@ -326,6 +331,20 @@ public class TestTools extends TestBase {
rs
.
next
();
assertTrue
(
rs
.
getBoolean
(
1
));
assertTrue
(
rs
.
getBoolean
(
3
));
assertTrue
(
rs
.
getBoolean
(
5
));
assertTrue
(
rs
.
getBoolean
(
6
));
rs
.
next
();
assertFalse
(
rs
.
getBoolean
(
1
));
assertFalse
(
rs
.
getBoolean
(
3
));
assertFalse
(
rs
.
getBoolean
(
5
));
assertFalse
(
rs
.
getBoolean
(
6
));
rs
.
next
();
assertEquals
(
0
,
rs
.
getLong
(
1
));
assertTrue
(
rs
.
wasNull
());
assertEquals
(
null
,
rs
.
getBytes
(
2
));
...
...
@@ -454,6 +473,8 @@ public class TestTools extends TestBase {
assertFalse
(
rs
.
isClosed
());
assertEquals
(
1
,
rs
.
getRow
());
assertTrue
(
rs
.
next
());
assertTrue
(
rs
.
next
());
assertTrue
(
rs
.
next
());
assertFalse
(
rs
.
next
());
assertThrows
(
ErrorCode
.
NO_DATA_AVAILABLE
,
(
ResultSet
)
rs
).
getInt
(
1
);
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论