Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
5b2f4c91
提交
5b2f4c91
authored
8月 16, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add some comments to Interval
上级
766d64b7
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
54 行增加
和
1 行删除
+54
-1
Interval.java
h2/src/main/org/h2/api/Interval.java
+54
-1
没有找到文件。
h2/src/main/org/h2/api/Interval.java
浏览文件 @
5b2f4c91
...
@@ -18,10 +18,23 @@ public final class Interval {
...
@@ -18,10 +18,23 @@ public final class Interval {
private
final
IntervalQualifier
qualifier
;
private
final
IntervalQualifier
qualifier
;
/**
* {@code false} for zero or positive intervals, {@code true} for negative
* intervals.
*/
private
final
boolean
negative
;
private
final
boolean
negative
;
/**
* Non-negative long with value of leading field. For INTERVAL SECOND
* contains only integer part of seconds.
*/
private
final
long
leading
;
private
final
long
leading
;
/**
* Non-negative long with combined value of all remaining field, or 0 for
* single-field intervals, with exception for INTERVAL SECOND that uses this
* field to store fractional part of seconds measured in nanoseconds.
*/
private
final
long
remaining
;
private
final
long
remaining
;
/**
/**
...
@@ -104,13 +117,18 @@ public final class Interval {
...
@@ -104,13 +117,18 @@ public final class Interval {
* @return INTERVAL SECOND
* @return INTERVAL SECOND
*/
*/
public
static
Interval
ofSeconds
(
long
seconds
,
int
nanos
)
{
public
static
Interval
ofSeconds
(
long
seconds
,
int
nanos
)
{
// Interval is negative if any field is negative
boolean
negative
=
(
seconds
|
nanos
)
<
0
;
boolean
negative
=
(
seconds
|
nanos
)
<
0
;
if
(
negative
)
{
if
(
negative
)
{
// Ensure that all fields are negative or zero
if
(
seconds
>
0
||
nanos
>
0
)
{
if
(
seconds
>
0
||
nanos
>
0
)
{
throw
new
IllegalArgumentException
();
throw
new
IllegalArgumentException
();
}
}
// Make them positive
seconds
=
-
seconds
;
seconds
=
-
seconds
;
nanos
=
-
nanos
;
nanos
=
-
nanos
;
// Long.MIN_VALUE and Integer.MIN_VALUE will be rejected by
// constructor
}
}
return
new
Interval
(
IntervalQualifier
.
SECOND
,
negative
,
seconds
,
nanos
);
return
new
Interval
(
IntervalQualifier
.
SECOND
,
negative
,
seconds
,
nanos
);
}
}
...
@@ -148,13 +166,18 @@ public final class Interval {
...
@@ -148,13 +166,18 @@ public final class Interval {
* @return INTERVAL YEAR TO MONTH
* @return INTERVAL YEAR TO MONTH
*/
*/
public
static
Interval
ofYearsMonths
(
long
years
,
int
months
)
{
public
static
Interval
ofYearsMonths
(
long
years
,
int
months
)
{
// Interval is negative if any field is negative
boolean
negative
=
(
years
|
months
)
<
0
;
boolean
negative
=
(
years
|
months
)
<
0
;
if
(
negative
)
{
if
(
negative
)
{
// Ensure that all fields are negative or zero
if
(
years
>
0
||
months
>
0
)
{
if
(
years
>
0
||
months
>
0
)
{
throw
new
IllegalArgumentException
();
throw
new
IllegalArgumentException
();
}
}
// Make them positive
years
=
-
years
;
years
=
-
years
;
months
=
-
months
;
months
=
-
months
;
// Long.MIN_VALUE and Integer.MIN_VALUE will be rejected by
// constructor
}
}
return
new
Interval
(
IntervalQualifier
.
YEAR_TO_MONTH
,
negative
,
years
,
months
);
return
new
Interval
(
IntervalQualifier
.
YEAR_TO_MONTH
,
negative
,
years
,
months
);
}
}
...
@@ -173,13 +196,18 @@ public final class Interval {
...
@@ -173,13 +196,18 @@ public final class Interval {
* @return INTERVAL DAY TO HOUR
* @return INTERVAL DAY TO HOUR
*/
*/
public
static
Interval
ofDaysHours
(
long
days
,
int
hours
)
{
public
static
Interval
ofDaysHours
(
long
days
,
int
hours
)
{
// Interval is negative if any field is negative
boolean
negative
=
(
days
|
hours
)
<
0
;
boolean
negative
=
(
days
|
hours
)
<
0
;
if
(
negative
)
{
if
(
negative
)
{
// Ensure that all fields are negative or zero
if
(
days
>
0
||
hours
>
0
)
{
if
(
days
>
0
||
hours
>
0
)
{
throw
new
IllegalArgumentException
();
throw
new
IllegalArgumentException
();
}
}
// Make them positive
days
=
-
days
;
days
=
-
days
;
hours
=
-
hours
;
hours
=
-
hours
;
// Long.MIN_VALUE and Integer.MIN_VALUE will be rejected by
// constructor
}
}
return
new
Interval
(
IntervalQualifier
.
DAY_TO_HOUR
,
negative
,
days
,
hours
);
return
new
Interval
(
IntervalQualifier
.
DAY_TO_HOUR
,
negative
,
days
,
hours
);
}
}
...
@@ -200,11 +228,14 @@ public final class Interval {
...
@@ -200,11 +228,14 @@ public final class Interval {
* @return INTERVAL DAY TO MINUTE
* @return INTERVAL DAY TO MINUTE
*/
*/
public
static
Interval
ofDaysHoursMinutes
(
long
days
,
int
hours
,
int
minutes
)
{
public
static
Interval
ofDaysHoursMinutes
(
long
days
,
int
hours
,
int
minutes
)
{
// Interval is negative if any field is negative
boolean
negative
=
(
days
|
hours
|
minutes
)
<
0
;
boolean
negative
=
(
days
|
hours
|
minutes
)
<
0
;
if
(
negative
)
{
if
(
negative
)
{
// Ensure that all fields are negative or zero
if
(
days
>
0
||
hours
>
0
||
minutes
>
0
)
{
if
(
days
>
0
||
hours
>
0
||
minutes
>
0
)
{
throw
new
IllegalArgumentException
();
throw
new
IllegalArgumentException
();
}
}
// Make them positive
days
=
-
days
;
days
=
-
days
;
hours
=
-
hours
;
hours
=
-
hours
;
minutes
=
-
minutes
;
minutes
=
-
minutes
;
...
@@ -212,7 +243,9 @@ public final class Interval {
...
@@ -212,7 +243,9 @@ public final class Interval {
// Integer.MIN_VALUE
// Integer.MIN_VALUE
throw
new
IllegalArgumentException
();
throw
new
IllegalArgumentException
();
}
}
// days = Long.MIN_VALUE will be rejected by constructor
}
}
// Check only minutes.
// Overflow in days or hours will be detected by constructor
// Overflow in days or hours will be detected by constructor
if
(
minutes
>=
60
)
{
if
(
minutes
>=
60
)
{
throw
new
IllegalArgumentException
();
throw
new
IllegalArgumentException
();
...
@@ -259,11 +292,14 @@ public final class Interval {
...
@@ -259,11 +292,14 @@ public final class Interval {
* @return INTERVAL DAY TO SECOND
* @return INTERVAL DAY TO SECOND
*/
*/
public
static
Interval
ofDaysHoursMinutesNanos
(
long
days
,
int
hours
,
int
minutes
,
long
nanos
)
{
public
static
Interval
ofDaysHoursMinutesNanos
(
long
days
,
int
hours
,
int
minutes
,
long
nanos
)
{
// Interval is negative if any field is negative
boolean
negative
=
(
days
|
hours
|
minutes
|
nanos
)
<
0
;
boolean
negative
=
(
days
|
hours
|
minutes
|
nanos
)
<
0
;
if
(
negative
)
{
if
(
negative
)
{
// Ensure that all fields are negative or zero
if
(
days
>
0
||
hours
>
0
||
minutes
>
0
||
nanos
>
0
)
{
if
(
days
>
0
||
hours
>
0
||
minutes
>
0
||
nanos
>
0
)
{
throw
new
IllegalArgumentException
();
throw
new
IllegalArgumentException
();
}
}
// Make them positive
days
=
-
days
;
days
=
-
days
;
hours
=
-
hours
;
hours
=
-
hours
;
minutes
=
-
minutes
;
minutes
=
-
minutes
;
...
@@ -272,8 +308,11 @@ public final class Interval {
...
@@ -272,8 +308,11 @@ public final class Interval {
// Integer.MIN_VALUE, Long.MIN_VALUE
// Integer.MIN_VALUE, Long.MIN_VALUE
throw
new
IllegalArgumentException
();
throw
new
IllegalArgumentException
();
}
}
// days = Long.MIN_VALUE will be rejected by constructor
}
}
if
(
hours
>=
24
||
minutes
>=
60
||
nanos
>=
NANOS_PER_MINUTE
)
{
// Check only minutes and nanoseconds.
// Overflow in days or hours will be detected by constructor
if
(
minutes
>=
60
||
nanos
>=
NANOS_PER_MINUTE
)
{
throw
new
IllegalArgumentException
();
throw
new
IllegalArgumentException
();
}
}
return
new
Interval
(
IntervalQualifier
.
DAY_TO_SECOND
,
negative
,
days
,
return
new
Interval
(
IntervalQualifier
.
DAY_TO_SECOND
,
negative
,
days
,
...
@@ -294,13 +333,18 @@ public final class Interval {
...
@@ -294,13 +333,18 @@ public final class Interval {
* @return INTERVAL HOUR TO MINUTE
* @return INTERVAL HOUR TO MINUTE
*/
*/
public
static
Interval
ofHoursMinutes
(
long
hours
,
int
minutes
)
{
public
static
Interval
ofHoursMinutes
(
long
hours
,
int
minutes
)
{
// Interval is negative if any field is negative
boolean
negative
=
(
hours
|
minutes
)
<
0
;
boolean
negative
=
(
hours
|
minutes
)
<
0
;
if
(
negative
)
{
if
(
negative
)
{
// Ensure that all fields are negative or zero
if
(
hours
>
0
||
minutes
>
0
)
{
if
(
hours
>
0
||
minutes
>
0
)
{
throw
new
IllegalArgumentException
();
throw
new
IllegalArgumentException
();
}
}
// Make them positive
hours
=
-
hours
;
hours
=
-
hours
;
minutes
=
-
minutes
;
minutes
=
-
minutes
;
// Long.MIN_VALUE and Integer.MIN_VALUE will be rejected by
// constructor
}
}
return
new
Interval
(
IntervalQualifier
.
HOUR_TO_MINUTE
,
negative
,
hours
,
minutes
);
return
new
Interval
(
IntervalQualifier
.
HOUR_TO_MINUTE
,
negative
,
hours
,
minutes
);
}
}
...
@@ -340,11 +384,14 @@ public final class Interval {
...
@@ -340,11 +384,14 @@ public final class Interval {
* @return INTERVAL HOUR TO SECOND
* @return INTERVAL HOUR TO SECOND
*/
*/
public
static
Interval
ofHoursMinutesNanos
(
long
hours
,
int
minutes
,
long
nanos
)
{
public
static
Interval
ofHoursMinutesNanos
(
long
hours
,
int
minutes
,
long
nanos
)
{
// Interval is negative if any field is negative
boolean
negative
=
(
hours
|
minutes
|
nanos
)
<
0
;
boolean
negative
=
(
hours
|
minutes
|
nanos
)
<
0
;
if
(
negative
)
{
if
(
negative
)
{
// Ensure that all fields are negative or zero
if
(
hours
>
0
||
minutes
>
0
||
nanos
>
0
)
{
if
(
hours
>
0
||
minutes
>
0
||
nanos
>
0
)
{
throw
new
IllegalArgumentException
();
throw
new
IllegalArgumentException
();
}
}
// Make them positive
hours
=
-
hours
;
hours
=
-
hours
;
minutes
=
-
minutes
;
minutes
=
-
minutes
;
nanos
=
-
nanos
;
nanos
=
-
nanos
;
...
@@ -352,7 +399,9 @@ public final class Interval {
...
@@ -352,7 +399,9 @@ public final class Interval {
// Integer.MIN_VALUE, Long.MIN_VALUE
// Integer.MIN_VALUE, Long.MIN_VALUE
throw
new
IllegalArgumentException
();
throw
new
IllegalArgumentException
();
}
}
// hours = Long.MIN_VALUE will be rejected by constructor
}
}
// Check only nanoseconds.
// Overflow in hours or minutes will be detected by constructor
// Overflow in hours or minutes will be detected by constructor
if
(
nanos
>=
NANOS_PER_MINUTE
)
{
if
(
nanos
>=
NANOS_PER_MINUTE
)
{
throw
new
IllegalArgumentException
();
throw
new
IllegalArgumentException
();
...
@@ -391,13 +440,17 @@ public final class Interval {
...
@@ -391,13 +440,17 @@ public final class Interval {
* @return INTERVAL MINUTE TO SECOND
* @return INTERVAL MINUTE TO SECOND
*/
*/
public
static
Interval
ofMinutesNanos
(
long
minutes
,
long
nanos
)
{
public
static
Interval
ofMinutesNanos
(
long
minutes
,
long
nanos
)
{
// Interval is negative if any field is negative
boolean
negative
=
(
minutes
|
nanos
)
<
0
;
boolean
negative
=
(
minutes
|
nanos
)
<
0
;
if
(
negative
)
{
if
(
negative
)
{
// Ensure that all fields are negative or zero
if
(
minutes
>
0
||
nanos
>
0
)
{
if
(
minutes
>
0
||
nanos
>
0
)
{
throw
new
IllegalArgumentException
();
throw
new
IllegalArgumentException
();
}
}
// Make them positive
minutes
=
-
minutes
;
minutes
=
-
minutes
;
nanos
=
-
nanos
;
nanos
=
-
nanos
;
// Long.MIN_VALUE will be rejected by constructor
}
}
return
new
Interval
(
IntervalQualifier
.
MINUTE_TO_SECOND
,
negative
,
minutes
,
nanos
);
return
new
Interval
(
IntervalQualifier
.
MINUTE_TO_SECOND
,
negative
,
minutes
,
nanos
);
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论