List of usage examples for java.util.function Function Function
Function
From source file:com.thoughtworks.go.domain.AllConfigErrors.java
public String asString() { return StringUtils.join(this.stream().map(new Function<ConfigErrors, String>() { @Override//from w ww . j a va 2 s . com public String apply(ConfigErrors errors) { return errors.asString(); } }).collect(Collectors.toList()), ", "); }
From source file:io.yields.math.framework.kpi.Accuracy.java
@Override protected double quality(PropertyVerifications<Double> propertyVerifications) { if (propertyVerifications.allValid()) { return 1d; } else {/*from ww w .java 2 s . com*/ return propertyVerifications.getFunctionOutcome().map(new Function<Double, Double>() { @Override public Double apply(Double value) { double negativeFunctionOutcome = value * -1; return NORMAL_DISTRIBUTION.cumulativeProbability(negativeFunctionOutcome / accuracy) / .5; } }).orElse(0d); } }
From source file:com.opengamma.strata.math.impl.statistics.leastsquare.NonLinearLeastSquareWithPenaltyTest.java
public void linearTest() { boolean print = false; if (print) {//from w w w . j a v a2 s .co m System.out.println("NonLinearLeastSquareWithPenaltyTest.linearTest"); } int nWeights = 20; int diffOrder = 2; double lambda = 100.0; DoubleMatrix penalty = (DoubleMatrix) MA.scale(getPenaltyMatrix(nWeights, diffOrder), lambda); int[] onIndex = new int[] { 1, 4, 11, 12, 15, 17 }; double[] obs = new double[] { 0, 1.0, 1.0, 1.0, 0.0, 0.0 }; int n = onIndex.length; Function<DoubleArray, DoubleArray> func = new Function<DoubleArray, DoubleArray>() { @Override public DoubleArray apply(DoubleArray x) { return DoubleArray.of(n, i -> x.get(onIndex[i])); } }; Function<DoubleArray, DoubleMatrix> jac = new Function<DoubleArray, DoubleMatrix>() { @Override public DoubleMatrix apply(DoubleArray x) { return DoubleMatrix.of(n, nWeights, (i, j) -> j == onIndex[i] ? 1d : 0d); } }; Well44497b random = new Well44497b(0L); DoubleArray start = DoubleArray.of(nWeights, i -> random.nextDouble()); LeastSquareWithPenaltyResults lsRes = NLLSWP.solve(DoubleArray.copyOf(obs), DoubleArray.filled(n, 0.01), func, jac, start, penalty); if (print) { System.out.println("chi2: " + lsRes.getChiSq()); System.out.println(lsRes.getFitParameters()); } for (int i = 0; i < n; i++) { assertEquals(obs[i], lsRes.getFitParameters().get(onIndex[i]), 0.01); } double expPen = 20.87912357454752; assertEquals(expPen, lsRes.getPenalty(), 1e-9); }
From source file:objenome.NumericAnalysisTest.java
@Test public void testFindZeros() throws IncompleteSolutionException { Objenome o = Objenome.solve(new FindZeros(ExampleScalarFunction.class, new Function<ExampleScalarFunction, Double>() { @Override/*from w w w. j av a 2s .c om*/ public Double apply(ExampleScalarFunction s) { return s.output(0.0) + s.output(0.5) + s.output(1.0); } }), ExampleScalarFunction.class); double bestParam = ((Number) o.getSolutions().get(0)).doubleValue(); assertEquals(-3.97454, bestParam, 0.001); }
From source file:com.tobedevoured.json.SimpleStreamTest.java
@Test public void testStreamFromUrl() throws StreamException { stubFor(get(urlEqualTo("/test")).willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "text/json").withBody("{ \"test\": \n true }"))); final Map results = new HashMap(); simpleStream.setCallback(new Function<Object, Object>() { @Override/* w w w.ja v a 2s .c o m*/ public Object apply(Object entity) { assertNotNull(entity); results.putAll((Map) entity); return null; } }); simpleStream.streamFromUrl("http://localhost:8089/test", 30); simpleStream.flush(); Map<String, Boolean> test = ImmutableMap.of("test", true); assertEquals(results, test); }
From source file:com.heliosapm.streams.collector.ds.pool.PooledObjectFactoryBuilder.java
/** * Provides the validating function that will validate pooled objects * @return the validating function//from w ww . j a va 2 s. c o m */ default public Function<PooledObject<T>, Boolean> validator() { return new Function<PooledObject<T>, Boolean>() { @Override public Boolean apply(final PooledObject<T> t) { return validateObject(t); } }; }
From source file:org.zalando.riptide.OAuth2CompatibilityResponseErrorHandlerTest.java
private Matcher<ClientHttpResponse> statusCode(final HttpStatus status) { return hasFeature("statusCode", new Function<ClientHttpResponse, HttpStatus>() { @Override/*w ww . ja v a 2 s.com*/ public HttpStatus apply(final ClientHttpResponse response) { try { return response.getStatusCode(); } catch (final Exception e) { throw new RuntimeException(e); } } }, is(status)); }
From source file:com.heliosapm.streams.collector.ds.pool.PooledObjectFactoryBuilder.java
/** * Provides the validating function that will validate pooled objects * @return the validating function// w w w. j av a 2 s.co m */ default public Function<PooledObject<T>, Void> closer() { return new Function<PooledObject<T>, Void>() { @Override public Void apply(final PooledObject<T> p) { try { destroyObject(p); } catch (Exception x) { /* No Op */} return null; } }; }
From source file:com.opengamma.strata.math.impl.minimization.SumToOneTest.java
@Test public void solverTest() { double[] w = new double[] { 0.01, 0.5, 0.3, 0.19 }; final int n = w.length; final SumToOne trans = new SumToOne(n); Function<DoubleArray, DoubleArray> func = new Function<DoubleArray, DoubleArray>() { @Override/*from w ww . j a va 2 s . co m*/ public DoubleArray apply(DoubleArray theta) { return trans.transform(theta); } }; DoubleArray sigma = DoubleArray.filled(n, 1e-4); DoubleArray start = DoubleArray.filled(n - 1, 0.8); LeastSquareResults res = SOLVER.solve(DoubleArray.copyOf(w), sigma, func, start/*, maxJump*/); assertEquals("chi sqr", 0.0, res.getChiSq(), 1e-9); double[] fit = res.getFitParameters().toArray(); double[] expected = trans.inverseTransform(w); for (int i = 0; i < n - 1; i++) { //put the fit result back in the range 0 - pi/2 double x = fit[i]; if (x < 0) { x = -x; } if (x > Math.PI / 2) { int p = (int) (x / Math.PI); x -= p * Math.PI; if (x > Math.PI / 2) { x = -x + Math.PI; } } assertEquals(expected[i], x, 1e-9); } }
From source file:io.github.jianzhichun.springboot.starters.swagger2.config.AutoSwagger2Configuration.java
@Bean @ConditionalOnMissingBean(Docket.class) public Docket docket() { ApiInfo apiInfo = new ApiInfoBuilder().title(autoSwagger2Properties.getApiInfo().getTitle()) .description(autoSwagger2Properties.getApiInfo().getDescription()) .termsOfServiceUrl(autoSwagger2Properties.getApiInfo().getTermsOfServiceUrl()) .contact(new Contact(autoSwagger2Properties.getApiInfo().getContact().getName(), autoSwagger2Properties.getApiInfo().getContact().getUrl(), autoSwagger2Properties.getApiInfo().getContact().getEmail())) .version(autoSwagger2Properties.getApiInfo().getVersion()) .license(autoSwagger2Properties.getApiInfo().getLicense()) .licenseUrl(autoSwagger2Properties.getApiInfo().getLicenseUrl()).build(); return new Docket(DocumentationType.SWAGGER_2).host(autoSwagger2Properties.getHost()) .protocols(newHashSet(autoSwagger2Properties.getProtocols())) .enable(autoSwagger2Properties.isEnable()).apiInfo(apiInfo).select() .apis(not(withMethodAnnotation(IgnoreMethod.class))) .apis(RequestHandlerSelectors.basePackage(autoSwagger2Properties.getBasePackage())) .paths(CollectionUtils.isEmpty(autoSwagger2Properties.getPaths().getOr()) ? PathSelectors.any() : or(map2list(autoSwagger2Properties.getPaths().getOr(), new Function<String, Predicate<String>>() { @Override public Predicate<String> apply(String path) { return regex(path); }/*from w w w. j a va 2s. co m*/ }))) .paths(CollectionUtils.isEmpty(autoSwagger2Properties.getPaths().getNot()) ? PathSelectors.any() : and(map2list(autoSwagger2Properties.getPaths().getNot(), new Function<String, Predicate<String>>() { @Override public Predicate<String> apply(String path) { return not(regex(path)); } }))) .build(); }