List of usage examples for java.util.function Supplier get
T get();
From source file:nl.rivm.cib.episim.model.disease.infection.MSEIRSTest.java
public static Observable<Map.Entry<Double, double[]>> deterministic(final SIRConfig config, final Supplier<FirstOrderIntegrator> integrators) { return Observable.create(sub -> { final double gamma = 1. / config.recovery(); final double beta = gamma * config.reproduction(); final double[] y0 = Arrays.stream(config.population()).mapToDouble(n -> n).toArray(); final double[] t = config.t(); try {/* w w w . j av a 2 s . c o m*/ final FirstOrderIntegrator integrator = integrators.get(); integrator.addStepHandler(new StepHandler() { @Override public void init(final double t0, final double[] y0, final double t) { publishCopy(sub, t0, y0); } @Override public void handleStep(final StepInterpolator interpolator, final boolean isLast) throws MaxCountExceededException { publishCopy(sub, interpolator.getInterpolatedTime(), interpolator.getInterpolatedState()); if (isLast) sub.onComplete(); } }); integrator.integrate(new FirstOrderDifferentialEquations() { @Override public int getDimension() { return y0.length; } @Override public void computeDerivatives(final double t, final double[] y, final double[] yp) { // SIR terms (flow rates) final double n = y[0] + y[1] + y[2], flow_si = beta * y[0] * y[1] / n, flow_ir = gamma * y[1]; yp[0] = -flow_si; yp[1] = flow_si - flow_ir; yp[2] = flow_ir; } }, t[0], y0, t[1], y0); } catch (final Exception e) { sub.onError(e); } }); }
From source file:nl.salp.warcraft4j.casc.cdn.CdnCascContext.java
/** * Parse the encoding file.// w w w . jav a 2 s. co m * * @return The parsed encoding file. * * @throws CascParsingException When parsing of the encoding file failed. */ protected EncodingFile parseEncoding() throws CascParsingException { Supplier<DataReader> readerSupplier = getEncodingReader(); LOGGER.debug("Initialising encoding file (fileKey: {}, fileSize: {}).", getCdnCascConfig().getStorageEncodingFileChecksum(), getCdnCascConfig().getStorageEncodingFileSize()); try (DataReader reader = readerSupplier.get()) { EncodingFile encodingFile = new EncodingFileParser().parse(reader, getCdnCascConfig().getExtractedEncodingFileSize()); return encodingFile; } catch (IOException e) { throw new CascParsingException(format("Error parsing encoding file %s", getCdnCascConfig().getExtractedEncodingFileChecksum().toHexString()), e); } }
From source file:onl.area51.filesystem.ftp.client.DefaultFTPClient.java
@Override public void log(Supplier<String> msg) { if (writer != null) { writer.println(msg.get()); } }
From source file:org.apache.cassandra.Util.java
public static void spinAssertEquals(Object expected, Supplier<Object> s, int timeoutInSeconds) { long now = System.currentTimeMillis(); while (System.currentTimeMillis() - now < now + (1000 * timeoutInSeconds)) { if (s.get().equals(expected)) break; Thread.yield();/*from w w w . j ava 2s .c o m*/ } assertEquals(expected, s.get()); }
From source file:org.apache.commons.weaver.privilizer.example.MethodReferencesUsingBlueprints.java
public String utilsReadPublicConstant() { final Supplier<String> s = Utils::readPublicConstant; return s.get(); }
From source file:org.apache.commons.weaver.privilizer.example.MethodReferencesUsingBlueprints.java
public String utilsGetProperty() { final Supplier<String> s = Utils::getProperty; return s.get(); }
From source file:org.apache.commons.weaver.privilizer.example.MethodReferencesUsingBlueprints.java
public String moreGetProperty() { final Supplier<String> s = Utils.More::getProperty; return s.get(); }
From source file:org.apache.commons.weaver.privilizer.example.MethodReferencesUsingBlueprints.java
public String moreGetTopStackElementClassName() { final Supplier<String> s = Utils.More::getTopStackElementClassName; return s.get(); }
From source file:org.apache.flink.table.client.gateway.local.ExecutionContext.java
/** * Executes the given supplier using the execution context's classloader as thread classloader. *//*www . j a va 2s . c o m*/ public <R> R wrapClassLoader(Supplier<R> supplier) { final ClassLoader previousClassloader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(classLoader); try { return supplier.get(); } finally { Thread.currentThread().setContextClassLoader(previousClassloader); } }
From source file:org.apache.hadoop.hbase.client.AsyncBatchRpcRetryingCaller.java
private void logException(int tries, Supplier<Stream<RegionRequest>> regionsSupplier, Throwable error, ServerName serverName) {/*w w w.j a va2 s . c o m*/ if (tries > startLogErrorsCnt) { String regions = regionsSupplier.get() .map(r -> "'" + r.loc.getRegionInfo().getRegionNameAsString() + "'") .collect(Collectors.joining(",", "[", "]")); LOG.warn("Process batch for " + regions + " in " + tableName + " from " + serverName + " failed, tries=" + tries, error); } }