List of usage examples for org.apache.commons.math3.distribution IntegerDistribution sample
int[] sample(int sampleSize);
From source file:org.apache.solr.client.solrj.io.eval.SampleEvaluator.java
@Override public Object doWork(Object... objects) throws IOException { if (objects.length < 1) { throw new IOException(String.format(Locale.ROOT, "Invalid expression %s - null found for the first value", toExpression(constructingFactory))); }//from www .ja v a 2 s. c om Object first = objects[0]; if (!(first instanceof RealDistribution) && !(first instanceof IntegerDistribution) && !(first instanceof MarkovChainEvaluator.MarkovChain)) { throw new IOException(String.format(Locale.ROOT, "Invalid expression %s - found type %s for the first value, expecting a Markov Chain, Real or Integer Distribution", toExpression(constructingFactory), first.getClass().getSimpleName())); } Object second = null; if (objects.length > 1) { second = objects[1]; } if (first instanceof MarkovChainEvaluator.MarkovChain) { MarkovChainEvaluator.MarkovChain markovChain = (MarkovChainEvaluator.MarkovChain) first; if (second != null) { return Arrays.stream(markovChain.sample(((Number) second).intValue())).mapToObj(item -> item) .collect(Collectors.toList()); } else { return markovChain.sample(); } } else if (first instanceof RealDistribution) { RealDistribution realDistribution = (RealDistribution) first; if (second != null) { return Arrays.stream(realDistribution.sample(((Number) second).intValue())).mapToObj(item -> item) .collect(Collectors.toList()); } else { return realDistribution.sample(); } } else { IntegerDistribution integerDistribution = (IntegerDistribution) first; if (second != null) { return Arrays.stream(integerDistribution.sample(((Number) second).intValue())) .mapToObj(item -> item).collect(Collectors.toList()); } else { return integerDistribution.sample(); } } }