mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
:trollface: unshift 灵感来源:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift
This commit is contained in:
parent
e6c7dfa047
commit
236ebba3a8
@ -1114,7 +1114,7 @@ public class FastStream<T> implements Stream<T>, Iterable<T> {
|
|||||||
* @param obj 元素
|
* @param obj 元素
|
||||||
* @return 流
|
* @return 流
|
||||||
*/
|
*/
|
||||||
public FastStream<T> addFirst(T obj) {
|
public FastStream<T> unshift(T obj) {
|
||||||
return FastStream.concat(Stream.of(obj), this.stream);
|
return FastStream.concat(Stream.of(obj), this.stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1125,7 +1125,7 @@ public class FastStream<T> implements Stream<T>, Iterable<T> {
|
|||||||
* @return 流
|
* @return 流
|
||||||
*/
|
*/
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public final FastStream<T> addFirst(T... obj) {
|
public final FastStream<T> unshift(T... obj) {
|
||||||
return FastStream.concat(ofStream(obj), this.stream);
|
return FastStream.concat(ofStream(obj), this.stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +100,8 @@ public class FastStreamTest {
|
|||||||
put("1", 1);
|
put("1", 1);
|
||||||
put("2", 2);
|
put("2", 2);
|
||||||
put("3", 3);
|
put("3", 3);
|
||||||
}}, identityMap);
|
}
|
||||||
|
}, identityMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -115,7 +116,8 @@ public class FastStreamTest {
|
|||||||
put("1", singletonList(1));
|
put("1", singletonList(1));
|
||||||
put("2", singletonList(2));
|
put("2", singletonList(2));
|
||||||
put("3", singletonList(3));
|
put("3", singletonList(3));
|
||||||
}}, group);
|
}
|
||||||
|
}, group);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -230,9 +232,9 @@ public class FastStreamTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddFirst() {
|
public void testUnshift() {
|
||||||
List<Integer> list = Arrays.asList(2, 3);
|
List<Integer> list = Arrays.asList(2, 3);
|
||||||
List<Integer> unshift = FastStream.of(list).addFirst(1).toList();
|
List<Integer> unshift = FastStream.of(list).unshift(1).toList();
|
||||||
Assert.assertEquals(Arrays.asList(1, 2, 3), unshift);
|
Assert.assertEquals(Arrays.asList(1, 2, 3), unshift);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user