Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
07df0b0a
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
3
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
07df0b0a
编写于
8月 21, 2013
作者:
H
henryjen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8023528: Rename Comparator combinators to disambiguate overloading methods
Reviewed-by: mduigou, smarks
上级
ed3b16b9
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
46 addition
and
46 deletion
+46
-46
src/share/classes/java/util/Comparator.java
src/share/classes/java/util/Comparator.java
+16
-16
test/java/util/Comparator/BasicTest.java
test/java/util/Comparator/BasicTest.java
+21
-21
test/java/util/Map/EntryComparators.java
test/java/util/Map/EntryComparators.java
+2
-2
test/java/util/function/BinaryOperator/BasicTest.java
test/java/util/function/BinaryOperator/BasicTest.java
+7
-7
未找到文件。
src/share/classes/java/util/Comparator.java
浏览文件 @
07df0b0a
...
...
@@ -199,7 +199,7 @@ public interface Comparator<T> {
* composed using following code,
*
* <pre>{@code
* Comparator<String> cmp = Comparator.comparing(String::length)
* Comparator<String> cmp = Comparator.comparing
Int
(String::length)
* .thenComparing(String.CASE_INSENSITIVE_ORDER);
* }</pre>
*
...
...
@@ -270,18 +270,18 @@ public interface Comparator<T> {
* extracts a {@code int} sort key.
*
* @implSpec This default implementation behaves as if {@code
* thenComparing(comparing(keyExtractor))}.
* thenComparing(comparing
Int
(keyExtractor))}.
*
* @param keyExtractor the function used to extract the integer sort key
* @return a lexicographic-order comparator composed of this and then the
* {@code int} sort key
* @throws NullPointerException if the argument is null.
* @see #comparing(ToIntFunction)
* @see #comparing
Int
(ToIntFunction)
* @see #thenComparing(Comparator)
* @since 1.8
*/
default
Comparator
<
T
>
thenComparing
(
ToIntFunction
<?
super
T
>
keyExtractor
)
{
return
thenComparing
(
comparing
(
keyExtractor
));
default
Comparator
<
T
>
thenComparing
Int
(
ToIntFunction
<?
super
T
>
keyExtractor
)
{
return
thenComparing
(
comparing
Int
(
keyExtractor
));
}
/**
...
...
@@ -289,18 +289,18 @@ public interface Comparator<T> {
* extracts a {@code long} sort key.
*
* @implSpec This default implementation behaves as if {@code
* thenComparing(comparing(keyExtractor))}.
* thenComparing(comparing
Long
(keyExtractor))}.
*
* @param keyExtractor the function used to extract the long sort key
* @return a lexicographic-order comparator composed of this and then the
* {@code long} sort key
* @throws NullPointerException if the argument is null.
* @see #comparing(ToLongFunction)
* @see #comparing
Long
(ToLongFunction)
* @see #thenComparing(Comparator)
* @since 1.8
*/
default
Comparator
<
T
>
thenComparing
(
ToLongFunction
<?
super
T
>
keyExtractor
)
{
return
thenComparing
(
comparing
(
keyExtractor
));
default
Comparator
<
T
>
thenComparing
Long
(
ToLongFunction
<?
super
T
>
keyExtractor
)
{
return
thenComparing
(
comparing
Long
(
keyExtractor
));
}
/**
...
...
@@ -308,18 +308,18 @@ public interface Comparator<T> {
* extracts a {@code double} sort key.
*
* @implSpec This default implementation behaves as if {@code
* thenComparing(comparing(keyExtractor))}.
* thenComparing(comparing
Double
(keyExtractor))}.
*
* @param keyExtractor the function used to extract the double sort key
* @return a lexicographic-order comparator composed of this and then the
* {@code double} sort key
* @throws NullPointerException if the argument is null.
* @see #comparing(ToDoubleFunction)
* @see #comparing
Double
(ToDoubleFunction)
* @see #thenComparing(Comparator)
* @since 1.8
*/
default
Comparator
<
T
>
thenComparing
(
ToDoubleFunction
<?
super
T
>
keyExtractor
)
{
return
thenComparing
(
comparing
(
keyExtractor
));
default
Comparator
<
T
>
thenComparing
Double
(
ToDoubleFunction
<?
super
T
>
keyExtractor
)
{
return
thenComparing
(
comparing
Double
(
keyExtractor
));
}
/**
...
...
@@ -484,7 +484,7 @@ public interface Comparator<T> {
* @throws NullPointerException if the argument is null
* @since 1.8
*/
public
static
<
T
>
Comparator
<
T
>
comparing
(
ToIntFunction
<?
super
T
>
keyExtractor
)
{
public
static
<
T
>
Comparator
<
T
>
comparing
Int
(
ToIntFunction
<?
super
T
>
keyExtractor
)
{
Objects
.
requireNonNull
(
keyExtractor
);
return
(
Comparator
<
T
>
&
Serializable
)
(
c1
,
c2
)
->
Integer
.
compare
(
keyExtractor
.
applyAsInt
(
c1
),
keyExtractor
.
applyAsInt
(
c2
));
...
...
@@ -505,7 +505,7 @@ public interface Comparator<T> {
* @throws NullPointerException if the argument is null
* @since 1.8
*/
public
static
<
T
>
Comparator
<
T
>
comparing
(
ToLongFunction
<?
super
T
>
keyExtractor
)
{
public
static
<
T
>
Comparator
<
T
>
comparing
Long
(
ToLongFunction
<?
super
T
>
keyExtractor
)
{
Objects
.
requireNonNull
(
keyExtractor
);
return
(
Comparator
<
T
>
&
Serializable
)
(
c1
,
c2
)
->
Long
.
compare
(
keyExtractor
.
applyAsLong
(
c1
),
keyExtractor
.
applyAsLong
(
c2
));
...
...
@@ -526,7 +526,7 @@ public interface Comparator<T> {
* @throws NullPointerException if the argument is null
* @since 1.8
*/
public
static
<
T
>
Comparator
<
T
>
comparing
(
ToDoubleFunction
<?
super
T
>
keyExtractor
)
{
public
static
<
T
>
Comparator
<
T
>
comparing
Double
(
ToDoubleFunction
<?
super
T
>
keyExtractor
)
{
Objects
.
requireNonNull
(
keyExtractor
);
return
(
Comparator
<
T
>
&
Serializable
)
(
c1
,
c2
)
->
Double
.
compare
(
keyExtractor
.
applyAsDouble
(
c1
),
keyExtractor
.
applyAsDouble
(
c2
));
...
...
test/java/util/Comparator/BasicTest.java
浏览文件 @
07df0b0a
...
...
@@ -90,7 +90,7 @@ public class BasicTest {
Thing
[]
things
=
new
Thing
[
intValues
.
length
];
for
(
int
i
=
0
;
i
<
intValues
.
length
;
i
++)
things
[
i
]
=
new
Thing
(
intValues
[
i
],
0L
,
0.0
,
null
);
Comparator
<
Thing
>
comp
=
Comparator
.
comparing
(
new
ToIntFunction
<
Thing
>()
{
Comparator
<
Thing
>
comp
=
Comparator
.
comparing
Int
(
new
ToIntFunction
<
Thing
>()
{
@Override
public
int
applyAsInt
(
Thing
thing
)
{
return
thing
.
getIntField
();
...
...
@@ -104,7 +104,7 @@ public class BasicTest {
Thing
[]
things
=
new
Thing
[
longValues
.
length
];
for
(
int
i
=
0
;
i
<
longValues
.
length
;
i
++)
things
[
i
]
=
new
Thing
(
0
,
longValues
[
i
],
0.0
,
null
);
Comparator
<
Thing
>
comp
=
Comparator
.
comparing
(
new
ToLongFunction
<
Thing
>()
{
Comparator
<
Thing
>
comp
=
Comparator
.
comparing
Long
(
new
ToLongFunction
<
Thing
>()
{
@Override
public
long
applyAsLong
(
Thing
thing
)
{
return
thing
.
getLongField
();
...
...
@@ -118,7 +118,7 @@ public class BasicTest {
Thing
[]
things
=
new
Thing
[
doubleValues
.
length
];
for
(
int
i
=
0
;
i
<
doubleValues
.
length
;
i
++)
things
[
i
]
=
new
Thing
(
0
,
0L
,
doubleValues
[
i
],
null
);
Comparator
<
Thing
>
comp
=
Comparator
.
comparing
(
new
ToDoubleFunction
<
Thing
>()
{
Comparator
<
Thing
>
comp
=
Comparator
.
comparing
Double
(
new
ToDoubleFunction
<
Thing
>()
{
@Override
public
double
applyAsDouble
(
Thing
thing
)
{
return
thing
.
getDoubleField
();
...
...
@@ -211,8 +211,8 @@ public class BasicTest {
};
public
void
testComparatorDefaultMethods
()
{
Comparator
<
People
>
cmp
=
Comparator
.
comparing
(
(
Function
<
People
,
String
>)
People:
:
getFirstName
);
Comparator
<
People
>
cmp2
=
Comparator
.
comparing
(
(
Function
<
People
,
String
>)
People:
:
getLastName
);
Comparator
<
People
>
cmp
=
Comparator
.
comparing
(
People:
:
getFirstName
);
Comparator
<
People
>
cmp2
=
Comparator
.
comparing
(
People:
:
getLastName
);
// reverseOrder
assertComparison
(
cmp
.
reversed
(),
people
[
1
],
people
[
0
]);
// thenComparing(Comparator)
...
...
@@ -222,20 +222,20 @@ public class BasicTest {
assertComparison
(
cmp
.
thenComparing
(
People:
:
getLastName
),
people
[
0
],
people
[
1
]);
assertComparison
(
cmp
.
thenComparing
(
People:
:
getLastName
),
people
[
4
],
people
[
0
]);
// thenComparing(ToIntFunction)
assertComparison
(
cmp
.
thenComparing
(
People:
:
getAge
),
people
[
0
],
people
[
1
]);
assertComparison
(
cmp
.
thenComparing
(
People:
:
getAge
),
people
[
1
],
people
[
5
]);
assertComparison
(
cmp
.
thenComparing
Int
(
People:
:
getAge
),
people
[
0
],
people
[
1
]);
assertComparison
(
cmp
.
thenComparing
Int
(
People:
:
getAge
),
people
[
1
],
people
[
5
]);
// thenComparing(ToLongFunction)
assertComparison
(
cmp
.
thenComparing
(
People:
:
getAgeAsLong
),
people
[
0
],
people
[
1
]);
assertComparison
(
cmp
.
thenComparing
(
People:
:
getAgeAsLong
),
people
[
1
],
people
[
5
]);
assertComparison
(
cmp
.
thenComparing
Long
(
People:
:
getAgeAsLong
),
people
[
0
],
people
[
1
]);
assertComparison
(
cmp
.
thenComparing
Long
(
People:
:
getAgeAsLong
),
people
[
1
],
people
[
5
]);
// thenComparing(ToDoubleFunction)
assertComparison
(
cmp
.
thenComparing
(
People:
:
getAgeAsDouble
),
people
[
0
],
people
[
1
]);
assertComparison
(
cmp
.
thenComparing
(
People:
:
getAgeAsDouble
),
people
[
1
],
people
[
5
]);
assertComparison
(
cmp
.
thenComparing
Double
(
People:
:
getAgeAsDouble
),
people
[
0
],
people
[
1
]);
assertComparison
(
cmp
.
thenComparing
Double
(
People:
:
getAgeAsDouble
),
people
[
1
],
people
[
5
]);
}
public
void
testNullsFirst
()
{
Comparator
<
String
>
strcmp
=
Comparator
.
nullsFirst
(
Comparator
.
naturalOrder
());
Comparator
<
People
>
cmp
=
Comparator
.
<
People
,
String
>
comparing
(
People:
:
getLastName
,
strcmp
)
Comparator
<
People
>
cmp
=
Comparator
.
comparing
(
People:
:
getLastName
,
strcmp
)
.
thenComparing
(
People:
:
getFirstName
,
strcmp
);
// Mary.null vs Mary.Cook - solve by last name
assertComparison
(
cmp
,
people
[
6
],
people
[
5
]);
...
...
@@ -243,7 +243,7 @@ public class BasicTest {
assertComparison
(
cmp
,
people
[
7
],
people
[
6
]);
// More than one thenComparing
strcmp
=
Comparator
.
nullsFirst
(
Comparator
.
comparing
((
ToIntFunction
<
String
>)
String:
:
length
)
strcmp
=
Comparator
.
nullsFirst
(
Comparator
.
comparing
Int
(
String:
:
length
)
.
thenComparing
(
String
.
CASE_INSENSITIVE_ORDER
));
assertComparison
(
strcmp
,
null
,
"abc"
);
assertComparison
(
strcmp
,
"ab"
,
"abc"
);
...
...
@@ -273,7 +273,7 @@ public class BasicTest {
public
void
testNullsLast
()
{
Comparator
<
String
>
strcmp
=
Comparator
.
nullsLast
(
Comparator
.
naturalOrder
());
Comparator
<
People
>
cmp
=
Comparator
.
<
People
,
String
>
comparing
(
People:
:
getLastName
,
strcmp
)
Comparator
<
People
>
cmp
=
Comparator
.
comparing
(
People:
:
getLastName
,
strcmp
)
.
thenComparing
(
People:
:
getFirstName
,
strcmp
);
// Mary.null vs Mary.Cook - solve by last name
assertComparison
(
cmp
,
people
[
5
],
people
[
6
]);
...
...
@@ -281,7 +281,7 @@ public class BasicTest {
assertComparison
(
cmp
,
people
[
7
],
people
[
6
]);
// More than one thenComparing
strcmp
=
Comparator
.
nullsLast
(
Comparator
.
comparing
((
ToIntFunction
<
String
>)
String:
:
length
)
strcmp
=
Comparator
.
nullsLast
(
Comparator
.
comparing
Int
(
String:
:
length
)
.
thenComparing
(
String
.
CASE_INSENSITIVE_ORDER
));
assertComparison
(
strcmp
,
"abc"
,
null
);
assertComparison
(
strcmp
,
"ab"
,
"abc"
);
...
...
@@ -341,28 +341,28 @@ public class BasicTest {
}
catch
(
NullPointerException
npe
)
{}
try
{
Comparator
<
People
>
cmp
=
Comparator
.
comparing
(
(
Function
<
People
,
String
>)
null
,
Comparator
.<
String
>
naturalOrder
());
Comparator
<
People
>
cmp
=
Comparator
.
comparing
(
null
,
Comparator
.<
String
>
naturalOrder
());
fail
(
"comparing(null, cmp) should throw NPE"
);
}
catch
(
NullPointerException
npe
)
{}
try
{
Comparator
<
People
>
cmp
=
Comparator
.
comparing
(
(
Function
<
People
,
String
>)
People:
:
getFirstName
,
null
);
Comparator
<
People
>
cmp
=
Comparator
.
comparing
(
People:
:
getFirstName
,
null
);
fail
(
"comparing(f, null) should throw NPE"
);
}
catch
(
NullPointerException
npe
)
{}
try
{
Comparator
<
People
>
cmp
=
Comparator
.
comparing
(
(
Function
<
People
,
String
>)
null
);
Comparator
<
People
>
cmp
=
Comparator
.
comparing
(
null
);
fail
(
"comparing(null) should throw NPE"
);
}
catch
(
NullPointerException
npe
)
{}
try
{
Comparator
<
People
>
cmp
=
Comparator
.
comparing
((
ToIntFunction
<
People
>)
null
);
Comparator
<
People
>
cmp
=
Comparator
.
comparing
Int
(
null
);
fail
(
"comparing(null) should throw NPE"
);
}
catch
(
NullPointerException
npe
)
{}
try
{
Comparator
<
People
>
cmp
=
Comparator
.
comparing
((
ToLongFunction
<
People
>)
null
);
Comparator
<
People
>
cmp
=
Comparator
.
comparing
Long
(
null
);
fail
(
"comparing(null) should throw NPE"
);
}
catch
(
NullPointerException
npe
)
{}
try
{
Comparator
<
People
>
cmp
=
Comparator
.
comparing
((
ToDoubleFunction
<
People
>)
null
);
Comparator
<
People
>
cmp
=
Comparator
.
comparing
Double
(
null
);
fail
(
"comparing(null) should throw NPE"
);
}
catch
(
NullPointerException
npe
)
{}
}
...
...
test/java/util/Map/EntryComparators.java
浏览文件 @
07df0b0a
...
...
@@ -115,8 +115,8 @@ public class EntryComparators {
// Comparator<People> cmp = Comparator.naturalOrder(); // Should fail to compiler as People is not comparable
// We can use simple comparator, but those have been tested above.
// Thus choose to do compose for some level of interation.
Comparator
<
People
>
cmp1
=
Comparator
.
comparing
(
(
Function
<
People
,
String
>)
People:
:
getFirstName
);
Comparator
<
People
>
cmp2
=
Comparator
.
comparing
(
(
Function
<
People
,
String
>)
People:
:
getLastName
);
Comparator
<
People
>
cmp1
=
Comparator
.
comparing
(
People:
:
getFirstName
);
Comparator
<
People
>
cmp2
=
Comparator
.
comparing
(
People:
:
getLastName
);
Comparator
<
People
>
cmp
=
cmp1
.
thenComparing
(
cmp2
);
assertPairComparison
(
people
[
0
],
people
[
0
],
people
[
1
],
people
[
1
],
...
...
test/java/util/function/BinaryOperator/BasicTest.java
浏览文件 @
07df0b0a
...
...
@@ -67,26 +67,26 @@ public class BasicTest {
};
public
void
testMaxBy
()
{
Comparator
<
People
>
cmp
=
Comparator
.
comparing
(
(
Function
<
People
,
String
>)
People:
:
getFirstName
);
Comparator
<
People
>
cmp
=
Comparator
.
comparing
(
People:
:
getFirstName
);
// lesser
assertSame
(
maxBy
(
cmp
).
apply
(
people
[
0
],
people
[
1
]),
people
[
1
]);
// euqal
cmp
=
Comparator
.
comparing
(
(
Function
<
People
,
String
>)
People:
:
getLastName
);
cmp
=
Comparator
.
comparing
(
People:
:
getLastName
);
assertSame
(
maxBy
(
cmp
).
apply
(
people
[
0
],
people
[
1
]),
people
[
0
]);
// greater
cmp
=
Comparator
.
comparing
((
ToIntFunction
<
People
>)
People:
:
getAge
);
cmp
=
Comparator
.
comparing
Int
(
People:
:
getAge
);
assertSame
(
maxBy
(
cmp
).
apply
(
people
[
0
],
people
[
1
]),
people
[
0
]);
}
public
void
test
LesserOf
()
{
Comparator
<
People
>
cmp
=
Comparator
.
comparing
(
(
Function
<
People
,
String
>)
People:
:
getFirstName
);
public
void
test
MinBy
()
{
Comparator
<
People
>
cmp
=
Comparator
.
comparing
(
People:
:
getFirstName
);
// lesser
assertSame
(
minBy
(
cmp
).
apply
(
people
[
0
],
people
[
1
]),
people
[
0
]);
// euqal
cmp
=
Comparator
.
comparing
(
(
Function
<
People
,
String
>)
People:
:
getLastName
);
cmp
=
Comparator
.
comparing
(
People:
:
getLastName
);
assertSame
(
minBy
(
cmp
).
apply
(
people
[
0
],
people
[
1
]),
people
[
0
]);
// greater
cmp
=
Comparator
.
comparing
((
ToIntFunction
<
People
>)
People:
:
getAge
);
cmp
=
Comparator
.
comparing
Int
(
People:
:
getAge
);
assertSame
(
minBy
(
cmp
).
apply
(
people
[
0
],
people
[
1
]),
people
[
1
]);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录