List of usage examples for java.util Arrays stream
public static DoubleStream stream(double[] array)
From source file:examples.utils.CifarReader.java
public static List<double[]> rawDouble(InputStream is) { List<double[]> result = new ArrayList<>(); int row = 1 + (IMAGE_WIDTH * IMAGE_HIGHT * IMAGE_DEPTH); try {//from w w w . j ava 2s. c o m while (is.available() > 0) { byte[] arr = new byte[row]; is.read(arr); result.add( Arrays.stream(ArrayUtils.toObject(arr)).mapToDouble(b -> Byte.toUnsignedInt(b)).toArray()); } } catch (IOException e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(is); } return result; }
From source file:Imputers.KnniLDProb.java
public double[][][] impute(double[][][] callprobs, int[][][] readCounts) { ProbToCallMinDepth p2c = new ProbToCallMinDepth(knownDepth); byte[][] original = p2c.call(callprobs, readCounts); Correlation corr = new Pearson(); byte[][] transposed = Matrix.transpose(original); //Map<Integer,List<Integer>> ld = corr.topn(transposed, 100); Map<Integer, int[]> ld = corr.topn(transposed, 100); //Integer[][] sim = new Integer[original[0].length][]; int[][] sim = new int[original[0].length][]; //for (Entry<Integer,List<Integer>> e: ld.entrySet()) for (Entry<Integer, int[]> e : ld.entrySet()) { //Integer[] a = new Integer[e.getValue().size()]; //sim[e.getKey()] = e.getValue().toArray(a); sim[e.getKey()] = e.getValue();/*from ww w .j av a 2s.co m*/ } double[][][] probs = new double[original.length][][]; Progress progress = ProgressFactory.get(original.length); IntStream.range(0, original.length).parallel().forEach(i -> { double[][] p = new double[original[i].length][]; probs[i] = p; IntStream.range(0, original[i].length).forEach(j -> { if (Arrays.stream(readCounts[i][j]).sum() < knownDepth) { p[j] = imputeSingle(original, i, j, false, sim); } else { p[j] = callprobs[i][j]; } }); progress.done(); }); return probs; }
From source file:com.ejisto.util.collector.FieldNode.java
public FieldNode fillGap(MockedField mockedField) { String[] missingPath = difference(path, mockedField.getComparisonKey()).split(MockedField.PATH_SEPARATOR); List<String> difference = asList(missingPath); final List<FieldNode> gap = Arrays.stream(missingPath).limit(Math.max(0, missingPath.length - 1)) .filter(StringUtils::isNotBlank).map(p -> { int index = difference.indexOf(p); return difference.stream().limit(index + 1).collect(joining(MockedField.PATH_SEPARATOR)); }).map(p -> new FieldNode(mockedField, p)).collect(Collectors.toList()); gap.add(0, this); return gap.stream().reduce((f1, f2) -> { f1.addChild(f2);/*from w w w . java 2 s . c om*/ return f2; }).orElseThrow(IllegalStateException::new); }
From source file:uk.urchinly.wabi.expose.DownloadController.java
@RequestMapping(method = RequestMethod.GET, value = "/browse") public List<String> browseFiles(Model model) { File rootFolder = new File(appSharePath); return Arrays.stream(rootFolder.listFiles()).map(f -> f.getName()).collect(Collectors.toList()); }
From source file:com.ejisto.modules.vertx.handler.Boilerplate.java
static void addResourcesMatcher(RouteMatcher m) { Arrays.stream(ResourceType.values()).forEach(t -> m.getWithRegEx(t.regex, req -> serveResource(req.response(), extractResourceFileName(req, t), t.contentType))); }
From source file:com.thinkbiganalytics.metadata.sla.EmailServiceLevelAgreementAction.java
@Override public boolean respond(EmailServiceLevelAgreementActionConfiguration actionConfiguration, ServiceLevelAssessment assessment, Alert a) { log.info("Responding to SLA violation {}. for alert {} received from: {} ", assessment.getServiceLevelAgreementDescription().getName(), a.getId(), a.getSource()); String desc = ServiceLevelAssessmentAlertUtil.getDescription(assessment); String slaName = assessment.getAgreement().getName(); String emails = actionConfiguration.getEmailAddresses(); String[] addresses = emails.split(","); String subject = "SLA Violated: " + slaName; String body = desc;/*from w w w . java 2 s . co m*/ VelocityEmailTemplate emailTemplate = parseVelocityTemplate(actionConfiguration, assessment, a); if (emailTemplate == null) { body = desc; } else { subject = emailTemplate.getSubject(); body = emailTemplate.getBody(); } final String finalSubject = subject; final String finalBody = body; log.info("sending {} email to: {}", assessment.getServiceLevelAgreementDescription().getName(), addresses); Arrays.stream(addresses).forEach(address -> { emailService.sendMail(address.trim(), finalSubject, finalBody); }); return true; }
From source file:eu.crydee.alignment.aligner.ae.MetricsOneVsOneC.java
@Override public void initialize(UimaContext context) throws ResourceInitializationException { super.initialize(context); results = HashBasedTable.create();/*from ww w.j a v a 2 s . co m*/ keys = Lists.newArrayList(keysArray); methodsMetadata = Arrays.stream(Complete.class.getMethods()) .map(m -> Pair.of(m, m.getAnnotation(Metric.class))) .filter(p -> p.getRight() != null && keys.contains(p.getRight().key())) .collect(Collectors.toMap(p -> p.getRight().key(), p -> Pair.of(p.getLeft(), p.getRight().name()))); }
From source file:com.github.mavogel.ilias.utils.IOUtils.java
/** * Splits with ',' and trims each token. * * @param line the line to split// w w w . j a v a 2s . co m * @return the tokens */ private static List<String> splitAndTrim(final String line) { return Arrays.stream(line.split(",")).map(StringUtils::deleteWhitespace).collect(Collectors.toList()); }
From source file:io.spring.initializr.metadata.InitializrConfiguration.java
private static String unsplitWords(String text) { return String.join("", Arrays.stream(text.split("(_|-| |:)+")).map(StringUtils::capitalize).toArray(String[]::new)); }
From source file:com.vsthost.rnd.jdeoptim.utils.Utils.java
/** * Returns random elements from the set. * * @param set The set to be chosen from. * @param n The number of elements to be returned. * @param exclude Elements to be excluded. * @param randomGenerator The random number generator. * @return Random elements./*from w w w. j a v a 2 s . co m*/ */ public static int[] pickRandom(int[] set, int n, int[] exclude, RandomGenerator randomGenerator) { // Create a set from excluded: final Set<Integer> toExclude = new HashSet<>(); Arrays.stream(exclude).forEach(toExclude::add); // Create set out of elements: int[] newSet = Arrays.stream(set).filter(e -> !toExclude.contains(e)).toArray(); // Shuffle the set: MathArrays.shuffle(newSet, randomGenerator); // Get n elements and return: return Arrays.copyOf(newSet, n); }