本文整理汇总了Java中java8.util.stream.StreamSupport.stream方法的典型用法代码示例。如果您正苦于以下问题:Java StreamSupport.stream方法的具体用法?Java StreamSupport.stream怎么用?Java StreamSupport.stream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java8.util.stream.StreamSupport
的用法示例。
在下文中一共展示了StreamSupport.stream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: launchCameraActivity
import java8.util.stream.StreamSupport; //导入方法依赖的package包/类
private void launchCameraActivity() {
Location myLocation = mapFragment.getCurrentLocation();
if (myLocation == null){
showError("Could not determine precise location. Improve GPS reception, then retry.");
return;
}
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
int n = Integer.parseInt(preferences.getString(getResources().getString(R.string.prefkey_ar_nodes), "5"));
List<Node> nodes = nodeRepository.getSpatialDataSource().findClosestItems(new LatLng(myLocation.getLatitude(), myLocation.getLongitude()), n, 200.0f);
SurroundingNodesSetup setup = new SurroundingNodesSetup(myLocation, StreamSupport.stream(nodes));
Log.d(TAG, String.format("starting AR view with %d nodes at location (%f,%f,%.1fm)", nodes.size(), myLocation.getLatitude(), myLocation.getLongitude(), myLocation.getAltitude()));
CameraFinderActivity.startWithSetup(this, setup);
}
示例2: testUnBox
import java8.util.stream.StreamSupport; //导入方法依赖的package包/类
public void testUnBox() {
List<Double> list = java.util.Arrays.asList(1.0, 2.0, 3.0, 4.0, 5.0);
Spliterator<Double> spliter = Spliterators.spliteratorUnknownSize(list.iterator(), 0);
Stream<Double> stream = StreamSupport.stream(spliter, false);
// double sum = Arrays.asList(1.0, 2.0, 3.0, 4.0, 5.0).stream().mapToDouble(i -> i).reduce(0.0, Double::sum);
double sum = stream.mapToDouble(new ToDoubleFunction<Double>() {
@Override
public double applyAsDouble(Double i) {
return i;
}
}).reduce(0.0, (DoubleBinaryOperator) new DoubleBinaryOperator() {
@Override
public double applyAsDouble(double v, double v2) {
return v + v2;
}
});
assertEquals(sum, 1.0 + 2.0 + 3.0 + 4.0 + 5.0);
}
示例3: testEntrySetSizeRemove
import java8.util.stream.StreamSupport; //导入方法依赖的package包/类
private void testEntrySetSizeRemove(String name, final Set<Map.Entry<Integer, Integer>> c) {
Iterator<Map.Entry<Integer, Integer>> testIter = c.iterator();
Map.Entry<Integer, Integer> first = testIter.next();
assertTrue(c.remove(first));
Supplier<Spliterator<Map.Entry<Integer, Integer>>> late = new Supplier<Spliterator<Map.Entry<Integer, Integer>>>() {
@Override
public Spliterator<Map.Entry<Integer, Integer>> get() {
return Spliterators.spliterator(c, 0);
}
};
Stream<Map.Entry<Integer, Integer>> stream = StreamSupport.stream(late, 0, false);
Map.Entry<Integer, Integer> second = c.iterator().next();
assertTrue(c.remove(second));
Object[] result = stream.toArray();
assertEquals(result.length, c.size());
}
示例4: testParSeq
import java8.util.stream.StreamSupport; //导入方法依赖的package包/类
public void testParSeq() {
List<Integer> list = Arrays.asList(1, 2, 3, 4);
Spliterator<Integer> spliter = Spliterators.spliteratorUnknownSize(list.iterator(), 0);
Stream<Integer> stream = StreamSupport.stream(spliter, false);
// Stream<Integer> s = Arrays.asList(1, 2, 3, 4).stream().parallel();
Stream<Integer> s = stream.parallel();
assertTrue(s.isParallel());
s = s.sequential();
assertFalse(s.isParallel());
s = s.sequential();
assertFalse(s.isParallel());
s = s.parallel();
assertTrue(s.isParallel());
s = s.parallel();
assertTrue(s.isParallel());
}
示例5: addAddAll
import java8.util.stream.StreamSupport; //导入方法依赖的package包/类
public void addAddAll() {
final StringJoiner sj = new StringJoiner(DASH, "{", "}");
sj.add(ONE);
ArrayList<String> nextOne = new ArrayList<String>();
nextOne.add(TWO);
nextOne.add(THREE);
Stream<String> stream = StreamSupport.stream(nextOne);
stream.forEachOrdered(new java8.util.function.Consumer<String>() {
@Override
public void accept(String t) {
sj.add(t);
}
});
String expected = "{"+ONE+DASH+TWO+DASH+THREE+"}";
assertEquals(sj.toString(), expected);
}
示例6: addAlladd
import java8.util.stream.StreamSupport; //导入方法依赖的package包/类
void addAlladd() {
final StringJoiner sj = new StringJoiner(DASH, "{", "}");
ArrayList<String> firstOne = new ArrayList<String>();
firstOne.add(ONE);
firstOne.add(TWO);
Stream<String> stream = StreamSupport.stream(firstOne);
stream.forEachOrdered(new java8.util.function.Consumer<String>() {
@Override
public void accept(String t) {
sj.add(t);
}
});
sj.add(THREE);
String expected = "{"+ONE+DASH+TWO+DASH+THREE+"}";
assertEquals(sj.toString(), expected);
}
示例7: ConcatTest
import java8.util.stream.StreamSupport; //导入方法依赖的package包/类
public ConcatTest(String scenario, Collection<Integer> c1, Collection<Integer> c2, Collection<Integer> expected) {
this.scenario = scenario;
this.c1 = c1;
this.c2 = c2;
this.expected = expected;
// verify prerequisite
Stream<Integer> s1s = StreamSupport.stream(c1, Characteristics.get(c1));
Stream<Integer> s2s = StreamSupport.stream(c2, Characteristics.get(c2));
Stream<Integer> s1p = StreamSupport.stream(c1, Characteristics.get(c1), true);
Stream<Integer> s2p = StreamSupport.stream(c2, Characteristics.get(c2), true);
assertTrue(s1p.isParallel());
assertTrue(s2p.isParallel());
assertFalse(s1s.isParallel());
assertFalse(s2s.isParallel());
assertTrue(s1s.spliterator().hasCharacteristics(Spliterator.ORDERED));
assertTrue(s1p.spliterator().hasCharacteristics(Spliterator.ORDERED));
assertTrue(s2s.spliterator().hasCharacteristics(Spliterator.ORDERED));
assertTrue(s2p.spliterator().hasCharacteristics(Spliterator.ORDERED));
}
示例8: testConsumed
import java8.util.stream.StreamSupport; //导入方法依赖的package包/类
public void testConsumed() {
Stream<Integer> s1 = StreamSupport.stream(countTo(100));
try {
s1.forEach(i -> {});
// Adding onClose handler when stream is consumed is illegal
// handler must not be registered
checkISE(() -> s1.onClose(() -> fail("s1")));
} finally {
if (s1 != null) {
s1.close();
}
}
// close() must be idempotent:
// second close() invoked at the end of try-with-resources must have no effect
Stream<Integer> s2 = StreamSupport.stream(countTo(100));
try {
s2.close();
// Adding onClose handler when stream is closed is also illegal
checkISE(() -> s2.onClose(() -> fail("s2")));
} finally {
if (s2 != null) {
s2.close();
}
}
}
示例9: findClosestItems
import java8.util.stream.StreamSupport; //导入方法依赖的package包/类
public List<T> findClosestItems(LatLng center, int n, float initialRadius) {
final int incFactor = 2;
int found = 0;
float currentDist = initialRadius;
Stream<T> nodes = null;
if (this.mItems.size() < n)
nodes = StreamSupport.stream(mItems).map(x -> x.getClusterItem()); // return all nodes
else {
while (found < n) {
LatLngBounds bounds = LocationUtilities.calculateBoundingBox(center, currentDist);
List<T> f = search(bounds);
currentDist *= incFactor;
found = f.size();
nodes = StreamSupport.stream(f);
}
}
double mlat = center.latitude;
double mlon = center.longitude;
List<T> result = new ArrayList<>();
nodes
.sorted((x, y) ->
Double.compare(
distFrom(mlat, mlon, x.getPosition().latitude, x.getPosition().longitude),
distFrom(mlat, mlon, y.getPosition().latitude, y.getPosition().longitude)))
.limit(n)
.forEach(x -> result.add(x));
return result;
}
示例10: testEntrySetSizeRemove2
import java8.util.stream.StreamSupport; //导入方法依赖的package包/类
private void testEntrySetSizeRemove2(String name, Set<Map.Entry<Integer, Integer>> c) {
Map.Entry<Integer, Integer> first = c.iterator().next();
assertTrue(c.remove(first));
Stream<Map.Entry<Integer, Integer>> stream = StreamSupport.stream(c, 0, false);
Map.Entry<Integer, Integer> second = c.iterator().next();
assertTrue(c.remove(second));
Object[] result = stream.toArray();
assertEquals(result.length, c.size());
}
示例11: testEmptyCloseHandler
import java8.util.stream.StreamSupport; //导入方法依赖的package包/类
public void testEmptyCloseHandler() {
Stream<Integer> ints = null;
try {
ints = StreamSupport.stream(countTo(100));
ints.forEach(i -> {});
} finally {
if (ints != null) {
ints.close();
}
}
}
示例12: testCollectionSizeRemove
import java8.util.stream.StreamSupport; //导入方法依赖的package包/类
@Test(dataProvider = "collections")
public void testCollectionSizeRemove(String name, Collection<Integer> c) {
assertTrue(c.remove(1));
Stream<Integer> s = StreamSupport.stream(c);
assertTrue(c.remove(2));
Object[] result = s.toArray();
assertEquals(result.length, c.size());
}
示例13: testEntrySetSizeRemove
import java8.util.stream.StreamSupport; //导入方法依赖的package包/类
private void testEntrySetSizeRemove(String name, Set<Map.Entry<Integer, Integer>> c) {
Map.Entry<Integer, Integer> first = c.iterator().next();
assertTrue(c.remove(first));
Stream<Map.Entry<Integer, Integer>> s = StreamSupport.stream(c);
Map.Entry<Integer, Integer> second = c.iterator().next();
assertTrue(c.remove(second));
Object[] result = s.toArray();
assertEquals(result.length, c.size());
}
示例14: testFlatMap
import java8.util.stream.StreamSupport; //导入方法依赖的package包/类
public void testFlatMap() {
String[] stringsArray = {"hello", "there", "", "yada"};
Stream<String> strings = StreamSupport.stream(Arrays.asList(stringsArray));
assertConcat(strings.flatMap(flattenChars).iterator(), "hellothereyada");
assertCountSum(StreamSupport.stream(countTo(10)).flatMap(mfId), 10, 55);
assertCountSum(StreamSupport.stream(countTo(10)).flatMap(mfNull), 0, 0);
assertCountSum(StreamSupport.stream(countTo(3)).flatMap(mfLt), 6, 4);
exerciseOps(TestData.Factory.ofArray("stringsArray", stringsArray), s -> s.flatMap(flattenChars));
exerciseOps(TestData.Factory.ofArray("LONG_STRING", new String[] {LONG_STRING}), s -> s.flatMap(flattenChars));
}
示例15: getNodes
import java8.util.stream.StreamSupport; //导入方法依赖的package包/类
public Stream<Node> getNodes() {
return StreamSupport.stream(nodes);
}