/**
  * Returns a composed {@link ToFloatBiFunction} that first applies the {@code before} functions to
  * its input, and then applies this function to the result. If evaluation of either operation
  * throws an exception, it is relayed to the caller of the composed operation.
  *
  * @param <A> The type of the argument to the first given function, and of composed function
  * @param <B> The type of the argument to the second given function, and of composed function
  * @param before1 The first function to apply before this function is applied
  * @param before2 The second function to apply before this function is applied
  * @return A composed {@code ToFloatBiFunction} that first applies the {@code before} functions to
  *     its input, and then applies this function to the result.
  * @throws NullPointerException If given argument is {@code null}
  * @implSpec The input argument of this method is able to handle every type.
  */
 @Nonnull
 default <A, B> ToFloatBiFunction<A, B> compose(
     @Nonnull final Function<? super A, ? extends T> before1,
     @Nonnull final ToDoubleFunction<? super B> before2) {
   Objects.requireNonNull(before1);
   Objects.requireNonNull(before2);
   return (a, b) -> applyAsFloat(before1.apply(a), before2.applyAsDouble(b));
 }
  private <E extends RuntimeException> void assertToDoubleFunction(
      ToDoubleFunction<Object> test, Class<E> type) {
    assertNotNull(test);
    try {
      test.applyAsDouble(null);
      fail();
    } catch (RuntimeException e) {
      assertException(type, e, "null");
    }

    try {
      Stream.of("1", "2", "3").mapToDouble(test);
    } catch (RuntimeException e) {
      assertException(type, e, "a");
    }
  }
示例#3
0
  @Override
  public PolygonIntegrateUnit apply(MFEdge edge) {
    MFCell cell = edge.getCell();
    if (cell.vertesSize() != 3) {
      throw new IllegalArgumentException();
    }
    double[] vertesLevels = new double[3];

    int negativeVertesNum = 0;
    for (int i = 0; i < vertesLevels.length; i++) {
      double lv = levelFunction.applyAsDouble(cell.getVertexCoord(i));
      if (lv < 0) {
        negativeVertesNum++;
      }
      vertesLevels[i] = lv;
    }
    if (negativeVertesNum == 0) {
      return null;
    }

    int firstInsideIndex = -1;
    for (int i = 0; i < vertesLevels.length; i++) {
      if (vertesLevels[i] < 0 && vertesLevels[(i + 2) % 3] >= 0) {
        firstInsideIndex = i;
        break;
      }
    }

    double[][] polygonVertesCoords = new double[2 + negativeVertesNum][];
    polygonVertesCoords[0] = edge.getStartCoord();
    polygonVertesCoords[1] = edge.getEndCoord();
    for (int i = 0; i < negativeVertesNum; i++) {
      polygonVertesCoords[2 + i] = cell.getVertexCoord((firstInsideIndex + i) % 3);
    }
    PolygonIntegrateUnit result = new PolygonIntegrateUnit();
    result.setVertesCoords(polygonVertesCoords);
    return result;
  }
示例#4
0
 /**
  * Returns a composed {@link Predicate2} that first applies the {@code before} function to its
  * input, and then applies this predicate to the result. If evaluation of either operation throws
  * an exception, it is relayed to the caller of the composed operation.
  *
  * @param <A> The type of the argument to the given function, and of composed predicate
  * @param before The function to apply before this predicate is applied
  * @return A composed {@code Predicate2} that first applies the {@code before} function to its
  *     input, and then applies this predicate to the result.
  * @throws NullPointerException If given argument is {@code null}
  * @implSpec The input argument of this method is able to handle every type.
  */
 @Nonnull
 default <A> Predicate2<A> compose(@Nonnull final ToDoubleFunction<? super A> before) {
   Objects.requireNonNull(before);
   return (a) -> test(before.applyAsDouble(a));
 }