java.util.stream.DoubleStream.mapToObj()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(6.6k)|赞(0)|评价(0)|浏览(208)

本文整理了Java中java.util.stream.DoubleStream.mapToObj()方法的一些代码示例,展示了DoubleStream.mapToObj()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DoubleStream.mapToObj()方法的具体详情如下:
包路径:java.util.stream.DoubleStream
类名称:DoubleStream
方法名:mapToObj

DoubleStream.mapToObj介绍

[英]Returns an object-valued Stream consisting of the results of applying the given function to the elements of this stream.

This is an intermediate operation.
[中]返回一个对象值流,该流包含将给定函数应用于该流元素的结果。
这是一个intermediate operation

代码示例

代码示例来源:origin: speedment/speedment

public DoubleMapToObjAction(DoubleFunction<? extends U> mapper) {
  super(s -> s.mapToObj(requireNonNull(mapper)), Stream.class, MAP_TO);
}

代码示例来源:origin: speedment/speedment

@Override
  public Stream<R> build(boolean parallel) {
    return previous().build(parallel).mapToObj(mapper);
  }
}

代码示例来源:origin: speedment/speedment

@Override
public <U> Stream<U> mapToObj(DoubleFunction<? extends U> mapper) {
  return wrap(stream().mapToObj(mapper));
}

代码示例来源:origin: apache/nifi

return IntStream.range(0, floatArray.length)
    .mapToDouble(i -> floatArray[i])
    .mapToObj((element) -> convertToORCObject(TypeInfoFactory.getPrimitiveTypeInfo("float"), (float) element))
    .collect(Collectors.toList());
double[] doubleArray = (double[]) o;
return Arrays.stream(doubleArray)
    .mapToObj((element) -> convertToORCObject(TypeInfoFactory.getPrimitiveTypeInfo("double"), element))
    .collect(Collectors.toList());

代码示例来源:origin: apache/nifi

return IntStream.range(0, floatArray.length)
    .mapToDouble(i -> floatArray[i])
    .mapToObj((element) -> convertToORCObject(TypeInfoFactory.getPrimitiveTypeInfo("float"), (float) element, hiveFieldNames))
    .collect(Collectors.toList());
double[] doubleArray = (double[]) o;
return Arrays.stream(doubleArray)
    .mapToObj((element) -> convertToORCObject(TypeInfoFactory.getPrimitiveTypeInfo("double"), element, hiveFieldNames))
    .collect(Collectors.toList());

代码示例来源:origin: org.elasticsearch/elasticsearch

/**
 * A filter for a field based on several terms matching on any of them.
 *
 * @param fieldName The field name
 * @param values The terms
 */
public TermsQueryBuilder(String fieldName, double... values) {
  this(fieldName, values != null ? Arrays.stream(values).mapToObj(s -> s).collect(Collectors.toList()) : (Iterable<?>) null);
}

代码示例来源:origin: org.codelibs/elasticsearch-querybuilders

/**
 * A filter for a field based on several terms matching on any of them.
 *
 * @param fieldName The field name
 * @param values The terms
 */
public TermsQueryBuilder(String fieldName, double... values) {
  this(fieldName, values != null ? Arrays.stream(values).mapToObj(s -> s).collect(Collectors.toList()) : (Iterable<?>) null);
}

代码示例来源:origin: eu.stamp-project/assert-fixer

static String createSnippetFromObservations(Object o) {
  String snippet = "new " + o.getClass().getSimpleName() + "{ ";
  if (o instanceof int[]) {
    snippet += Arrays.stream((int[]) o).mapToObj(v -> v).map(Object::toString).collect(Collectors.joining(","));
  } else if (o instanceof double[]) {
    snippet += Arrays.stream((double[]) o).mapToObj(v -> v).map(Object::toString).collect(Collectors.joining(","));
  } else if (o instanceof long[]) {
    snippet += Arrays.stream((long[]) o).mapToObj(v -> v).map(Object::toString).collect(Collectors.joining(","));
  }
  return snippet + "}";
}

代码示例来源:origin: jenetics/jenetics

public static SubsetSum of(final int n, final int k, final Random random) {
  return new SubsetSum(
    random.doubles()
      .limit(n)
      .mapToObj(d -> (int)((d - 0.5)*n))
      .collect(ISeq.toISeq()),
    k
  );
}

代码示例来源:origin: jenetics/jenetics

private static ISeq<Phenotype<DoubleGene, Double>> population(
  final int min,
  final int max
) {
  return IntStream.rangeClosed(min, max)
    .mapToDouble(i -> (double)i)
    .mapToObj(PopulationConvergenceLimitTest::phenotype)
    .collect(ISeq.toISeq());
}

代码示例来源:origin: jenetics/jenetics

private static ISeq<Phenotype<DoubleGene, Double>> population(
  final int min,
  final int max
) {
  return IntStream.rangeClosed(min, max)
    .mapToDouble(i -> (double)i)
    .mapToObj(FitnessThresholdLimitTest::phenotype)
    .collect(ISeq.toISeq());
}

代码示例来源:origin: jenetics/jenetics

private static ISeq<Phenotype<DoubleGene, Double>> population(
  final int min,
  final int max
) {
  return IntStream.rangeClosed(min, max)
    .mapToDouble(i -> (double)i)
    .mapToObj(GeneConvergenceLimitTest::phenotype)
    .collect(ISeq.toISeq());
}

代码示例来源:origin: jenetics/jenetics

static ISeq<Vec<double[]>> circle(final int count, final Random random) {
  return random.doubles(count)
    .mapToObj(r -> {
      final double a = random.nextDouble()*2*PI;
      return Vec.of(r*sin(a), r*cos(a));
    })
    .collect(ISeq.toISeq());
}

代码示例来源:origin: jenetics/jenetics

static ISeq<Point2> front(final int count, final Random random) {
  return random.doubles(count)
    .mapToObj(x -> Point2.of(x, sqrt(1 - x*x)))
    .collect(ISeq.toISeq());
}

代码示例来源:origin: jenetics/jenetics

static ISeq<Vec<double[]>> frontMax(
  final double r,
  final int count,
  final Random random
) {
  return random.doubles(count)
    .map(a -> a*PI*0.5)
    .mapToObj(a -> Vec.of(r*sin(a), r*cos(a)))
    .collect(ISeq.toISeq());
}

代码示例来源:origin: jenetics/jenetics

static ISeq<Vec<double[]>> frontMin(
  final double r,
  final int count,
  final Random random
) {
  return random.doubles(count)
    .map(a -> a*PI*0.5 + PI)
    .mapToObj(a -> Vec.of(r*sin(a), r*cos(a)))
    .collect(ISeq.toISeq());
}

代码示例来源:origin: jenetics/jenetics

@Test
public void acceptReverseMinMax() {
  final Random random = RandomRegistry.getRandom();
  final double[] numbers = random.doubles().limit(1000).toArray();
  final MinMax<Double> minMax = MinMax.of((a, b) -> b.compareTo(a));
  Arrays.stream(numbers)
    .mapToObj(Double::valueOf)
    .forEach(minMax);
  Assert.assertEquals(minMax.getMin(), StatUtils.max(numbers));
  Assert.assertEquals(minMax.getMax(), StatUtils.min(numbers));
}

代码示例来源:origin: jenetics/jenetics

static ISeq<Point2> circle(final int count, final Random random) {
    return random.doubles()
      .mapToObj(x -> Point2.of(x, random.nextDouble()))
      .filter(p -> p.x()*p.x() + p.y()*p.y() < 0.9)
      .limit(count)
      .collect(ISeq.toISeq());
  }
}

代码示例来源:origin: jenetics/jenetics

@Test
public void toMinMaxNormal() {
  final Random random = RandomRegistry.getRandom();
  final double[] numbers = random.doubles().limit(1000).toArray();
  final MinMax<Double> minMax = Arrays.stream(numbers)
    .mapToObj(Double::valueOf)
    .collect(MinMax.toMinMax());
  Assert.assertEquals(minMax.getMin(), StatUtils.min(numbers));
  Assert.assertEquals(minMax.getMax(), StatUtils.max(numbers));
}

代码示例来源:origin: jenetics/jenetics

@Test
public void acceptNormalMinMax() {
  final Random random = RandomRegistry.getRandom();
  final double[] numbers = random.doubles().limit(1000).toArray();
  final MinMax<Double> minMax = MinMax.of();
  Arrays.stream(numbers)
    .mapToObj(Double::valueOf)
    .forEach(minMax);
  Assert.assertEquals(minMax.getMin(), StatUtils.min(numbers));
  Assert.assertEquals(minMax.getMax(), StatUtils.max(numbers));
}

相关文章