private void writeEnvVariables(BufferedWriter fileWriter) throws IOException { fileWriter.append("Environment variables:\n"); Map<String, String> envVariables = system.envVariables(); new TreeSet<>(envVariables.keySet()) .forEach(envKey -> { try { String envValue = isSensitiveEnvVariable(envKey) ? "******" : envVariables.get(envKey); fileWriter.append(String.format(KEY_VALUE_FORMAT, envKey, envValue)).append('\n'); } catch (IOException e) { throw new IllegalStateException(e); } }); }
handlerNamesSorted.forEach(key -> { StringBuilder sb = new StringBuilder(); sb.append("{\"name\":\"");
@Override public List<okhttp3.Cookie> loadForRequest(HttpUrl url) { List<okhttp3.Cookie> cookies = new ArrayList<>(); store.forEach(c -> cookies.add(((CookieImpl)c).cookie)); return cookies; } }
@Override public LargestUnique mergeAccumulators(Iterable<LargestUnique> heaps) { Iterator<LargestUnique> iterator = heaps.iterator(); LargestUnique accumulator = iterator.next(); while (iterator.hasNext()) { iterator.next().heap.forEach(h -> accumulator.add(h)); } return accumulator; }
@Override public synchronized void reset() { history.forEach(x -> x.freeRef()); history.clear(); }
private void writeEnvVariables(BufferedWriter fileWriter) throws IOException { fileWriter.append("Environment variables:\n"); Map<String, String> envVariables = system.envVariables(); new TreeSet<>(envVariables.keySet()) .forEach(envKey -> { try { String envValue = isSensitiveEnvVariable(envKey) ? "******" : envVariables.get(envKey); fileWriter.append(String.format(KEY_VALUE_FORMAT, envKey, envValue)).append('\n'); } catch (IOException e) { throw new IllegalStateException(e); } }); }
private LBFGS setHistory(@Nonnull final TrainingMonitor monitor, @Nonnull final List<PointSample> history) { if (history.size() == this.history.size() && history.stream().filter(x -> !this.history.contains(x)).count() == 0) return this; if (verbose) { monitor.log(String.format("Overwriting history with %s points", history.size())); } synchronized (this.history) { history.forEach(x -> x.addRef()); this.history.forEach(x -> x.freeRef()); this.history.clear(); this.history.addAll(history); } return this; }
@Override public GolangDependencySet clone() { try { GolangDependencySet ret = (GolangDependencySet) super.clone(); ret.container = new TreeSet<>( comparing((Serializable & Function<GolangDependency, String>) GolangDependency::getName)); this.container.forEach(item -> ret.add((GolangDependency) item.clone())); return ret; } catch (CloneNotSupportedException e) { return null; } } }
@Override protected int finish(final CommandMap command) { @SuppressWarnings("unchecked") final Optional<File> possibleFile = (Optional<File>) command.getOption(OUTPUT_PARAMETER); if (possibleFile.isPresent()) { try (PrintStream out = new PrintStream( new FileOutputStream(possibleFile.get().getFile(), true))) { this.restrictedPaths.forEach(value -> out.println(value)); } catch (final IOException oops) { throw new CoreException("Error writing restrictedPaths to file", oops); } } else { try (PrintStream out = new PrintStream(System.out)) { this.restrictedPaths.forEach(value -> out.println(value)); } } return 0; }
@Override protected int finish(final CommandMap command) { final File file = (File) command.get(OUTPUT_PARAMETER); try (PrintStream out = new PrintStream(new FileOutputStream(file.getFile(), true))) { this.turnRestrictions.forEach(value -> out.println(value)); } catch (final IOException oops) { throw new CoreException("Error writing turnRestriction ids to file", oops); } return 0; }
@OnOpen public void show() { clear(); ExperimentalFeaturesRegistry registry = registryService.getFeaturesRegistry(); if (registry != null) { Map<String, Set<ExperimentalFeature>> groupedFeatures = registry.getAllFeatures().stream() .collect(Collectors.groupingBy(this::getFeatureGroupName, Collectors.toSet())); TreeSet<ExperimentalFeaturesGroup> groups = groupedFeatures.entrySet() .stream() .map(this::getFeaturesGroup) .filter(Objects::nonNull) .collect(Collectors.toCollection(TreeSet::new)); if (!groups.isEmpty()) { groups.first().expand(); groups.forEach(view::add); } } }
@OnOpen public void show() { clear(); ExperimentalFeaturesRegistry registry = registryService.getFeaturesRegistry(); if (registry != null) { Map<String, Set<ExperimentalFeature>> groupedFeatures = registry.getAllFeatures().stream() .collect(Collectors.groupingBy(this::getFeatureGroupName, Collectors.toSet())); TreeSet<ExperimentalFeaturesGroup> groups = groupedFeatures.entrySet() .stream() .map(this::getFeaturesGroup) .filter(Objects::nonNull) .collect(Collectors.toCollection(TreeSet::new)); if (!groups.isEmpty()) { groups.first().expand(); groups.forEach(view::add); } } }
@Command(name = "help") public static void printHelp(List<String> options) { JTerm.out.println(TextColor.INFO, "JTerm v" + JTerm.VERSION + "\n" + "Available Commands\n" + "(type [command] -h to view specific help information)"); new TreeSet<>(JTerm.getCommands()).forEach(command -> JTerm.out.printf(TextColor.INFO, "\t%s%n", command)); } }
@Override public boolean verifyEchoString(EchoRequest request) { Assert.hasText(request.getEchostr(), "The echo string must be not empty"); Assert.hasText(request.getSignature(), "The signature string must be not empty"); Assert.hasText(request.getNonce(), "The nonce string must be not empty"); Assert.notNull(request.getTimestamp(), "The timestamp must be not null"); Assert.isTrue(request.getTimestamp() > 0, "The timestamp string must be greater than 0"); TreeSet<String> set = new TreeSet<>(Arrays.asList(request.getNonce(), request.getTimestamp().toString(), wechatToken)); StringBuilder sign = new StringBuilder(); set.forEach(sign::append); try { String originSign = sign.toString(); String hexSign = HexUtils.bytesToHex(MessageDigest.getInstance("SHA-1").digest(originSign.getBytes(StandardCharsets.US_ASCII))); log.info("verify echo string. {} | {} | {}", originSign, hexSign, request.getSignature()); return request.getSignature().equals(hexSign); } catch (Exception e) { log.error("verify echo string exception", e); return false; } }
public void init(final String labelKey, final Collection<ExperimentalFeature> features, final ParameterizedCommand<EditableExperimentalFeature> callback) { PortablePreconditions.checkNotNull("labelKey", labelKey); PortablePreconditions.checkNotNull("features", features); PortablePreconditions.checkNotNull("callback", callback); clear(); this.labelKey = labelKey; this.callback = feature -> { callback.execute(feature); setEnableAllLabel(); }; view.setLabel(getLabel()); features.stream() .map(this::getEditor) .collect(Collectors.toCollection(TreeSet::new)) .forEach(view::render); setEnableAllLabel(); }
public void init(final String labelKey, final Collection<ExperimentalFeature> features, final ParameterizedCommand<EditableExperimentalFeature> callback) { PortablePreconditions.checkNotNull("labelKey", labelKey); PortablePreconditions.checkNotNull("features", features); PortablePreconditions.checkNotNull("callback", callback); clear(); this.labelKey = labelKey; this.callback = feature -> { callback.execute(feature); setEnableAllLabel(); }; view.setLabel(getLabel()); features.stream() .map(this::getEditor) .collect(Collectors.toCollection(TreeSet::new)) .forEach(view::render); setEnableAllLabel(); }
@SuppressWarnings("unused") void onNestedElementAdded(final @Observes ExpressionEditorChanged event) { final Node node = presenter.getGraph().getNode(getActiveParent().getUUID()); presenter.updateElement(node); getActiveParent().getChildren().forEach(e -> getTreePresenter().selectItem(e.getUUID())); }
private void writeAllViolations(final MendelianViolationDetector.Result result) { if (VCF_DIR != null) { LOG.info(String.format("Writing family violation VCFs to %s/", VCF_DIR.getAbsolutePath())); final VariantContextComparator vcComparator = new VariantContextComparator(inputHeader.get().getContigLines()); final Set<VCFHeaderLine> headerLines = new LinkedHashSet<>(inputHeader.get().getMetaDataInInputOrder()); headerLines.add(new VCFInfoHeaderLine(MendelianViolationDetector.MENDELIAN_VIOLATION_KEY, 1, VCFHeaderLineType.String, "Type of mendelian violation.")); headerLines.add(new VCFInfoHeaderLine(MendelianViolationDetector.ORIGINAL_AC, VCFHeaderLineCount.A, VCFHeaderLineType.Integer, "Original AC")); headerLines.add(new VCFInfoHeaderLine(MendelianViolationDetector.ORIGINAL_AF, VCFHeaderLineCount.A, VCFHeaderLineType.Float, "Original AF")); headerLines.add(new VCFInfoHeaderLine(MendelianViolationDetector.ORIGINAL_AN, 1, VCFHeaderLineType.Integer, "Original AN")); for (final PedFile.PedTrio trio : pedFile.get().values()) { final File outputFile = new File(VCF_DIR, IOUtil.makeFileNameSafe(trio.getFamilyId() + IOUtil.VCF_FILE_EXTENSION)); LOG.info(String.format("Writing %s violation VCF to %s", trio.getFamilyId(), outputFile.getAbsolutePath())); final VariantContextWriter out = new VariantContextWriterBuilder() .setOutputFile(outputFile) .unsetOption(INDEX_ON_THE_FLY) .build(); final VCFHeader newHeader = new VCFHeader(headerLines, CollectionUtil.makeList(trio.getMaternalId(), trio.getPaternalId(), trio.getIndividualId())); final TreeSet<VariantContext> orderedViolations = new TreeSet<>(vcComparator); orderedViolations.addAll(result.violations().get(trio.getFamilyId())); out.writeHeader(newHeader); orderedViolations.forEach(out::add); out.close(); } } }
private void writeAllViolations(final MendelianViolationDetector.Result result) { if (VCF_DIR != null) { LOG.info(String.format("Writing family violation VCFs to %s/", VCF_DIR.getAbsolutePath())); final VariantContextComparator vcComparator = new VariantContextComparator(inputHeader.get().getContigLines()); final Set<VCFHeaderLine> headerLines = new LinkedHashSet<>(inputHeader.get().getMetaDataInInputOrder()); headerLines.add(new VCFInfoHeaderLine(MendelianViolationDetector.MENDELIAN_VIOLATION_KEY, 1, VCFHeaderLineType.String, "Type of mendelian violation.")); headerLines.add(new VCFInfoHeaderLine(MendelianViolationDetector.ORIGINAL_AC, VCFHeaderLineCount.A, VCFHeaderLineType.Integer, "Original AC")); headerLines.add(new VCFInfoHeaderLine(MendelianViolationDetector.ORIGINAL_AF, VCFHeaderLineCount.A, VCFHeaderLineType.Float, "Original AF")); headerLines.add(new VCFInfoHeaderLine(MendelianViolationDetector.ORIGINAL_AN, 1, VCFHeaderLineType.Integer, "Original AN")); for (final PedFile.PedTrio trio : pedFile.get().values()) { final File outputFile = new File(VCF_DIR, IOUtil.makeFileNameSafe(trio.getFamilyId() + IOUtil.VCF_FILE_EXTENSION)); LOG.info(String.format("Writing %s violation VCF to %s", trio.getFamilyId(), outputFile.getAbsolutePath())); final VariantContextWriter out = new VariantContextWriterBuilder() .setOutputFile(outputFile) .unsetOption(INDEX_ON_THE_FLY) .build(); final VCFHeader newHeader = new VCFHeader(headerLines, CollectionUtil.makeList(trio.getMaternalId(), trio.getPaternalId(), trio.getIndividualId())); final TreeSet<VariantContext> orderedViolations = new TreeSet<>(vcComparator); orderedViolations.addAll(result.violations().get(trio.getFamilyId())); out.writeHeader(newHeader); orderedViolations.forEach(out::add); out.close(); } } }