usernames = null; else usernames = Collections.unmodifiableList(StreamSupport.stream(usernameArray.spliterator(), false).map(String::valueOf).collect(Collectors.toList())); guildFeatures = Collections.emptySet(); else guildFeatures = Collections.unmodifiableSet(StreamSupport.stream(guildObject.getJSONArray("features").spliterator(), false).map(String::valueOf).collect(Collectors.toSet()));
StreamSupport.stream(featuresArray.spliterator(), false) .map(String::valueOf) .collect(Collectors.toSet()));
features = StreamSupport.stream(featureArr.spliterator(), false).map(String::valueOf).collect(Collectors.toSet());
/** * Extracts the error messages from JSON response. */ private static String getErrorString(JSONObject data) { return StreamSupport .stream(data.getJSONArray("errors").spliterator(), false) .map(error -> (JSONObject) error) .map(error -> String.format( "[%d] %s", error.getInt("code"), error.getString("message")) ) .collect(Collectors.joining("\n")); }
public static <T> List<T> fromJSONArray(final JSONArray jsonArray, Function<JSONObject, T> mapper) { List<JSONObject> onlyObjects = new ArrayList<>(); List<T> results = new ArrayList<>(); Optional.ofNullable(jsonArray).map(array -> StreamSupport.stream(array.spliterator(), true) .filter(json -> json instanceof JSONObject) .map(JSONObject.class::cast).collect(Collectors.toList())) .ifPresent(onlyObjects::addAll); for (JSONObject json : onlyObjects) { results.add(mapper.apply(json)); } return results; } }
/** * Updates the data stored in {@code pedigreeNodes pedigree nodes} of a family. * * @param pedigreeNodes a {@link JSONArray} containing pedigree node data * @return true iff pedigree nodes were updated, false otherwise */ private boolean updatePedigreeNodes(@Nullable final JSONArray pedigreeNodes) { return (pedigreeNodes != null && pedigreeNodes.length() != 0) ? StreamSupport.stream(pedigreeNodes.spliterator(), false) .map(this::updateCancers) .reduce((x, y) -> x || y) .orElse(false) : false; }
public static List<CheckReport> readReportsFromReader(Reader reader) throws IOException, JSONException { JSONTokener tokener = new JSONTokener(reader); JSONObject json = new JSONObject(tokener); List<CheckReport> reports = new ArrayList<>(); JSONArray jsonReports = json.optJSONArray(KEY_REPORTS); if (jsonReports != null) { reports = StreamSupport.stream(jsonReports.spliterator(), false) .filter(v -> v instanceof JSONObject) .map(v -> reportFromJSON((JSONObject) v)) .collect(Collectors.toList()); } return Collections.unmodifiableList(reports); }
private static CheckReport reportFromJSON(JSONObject jsonReport) { String vCheckName = jsonReport.optString(KEY_CHECK_NAME); List<Violation> violations = new ArrayList<>(); JSONArray vViolations = jsonReport.optJSONArray(KEY_VIOLATIONS); if (vViolations != null) { violations = StreamSupport.stream(vViolations.spliterator(), false) .filter(v -> v instanceof JSONObject) .map(v -> violationFromJSON((JSONObject) v)) .collect(Collectors.toList()); } return new SimpleReport(vCheckName, violations); }
@Override public ProgressCheck newInstance(final JSONObject config) throws Exception { List<Rule> pathScope = Rule.fromJSON(config.optJSONArray(CONFIG_SCOPE_PATHS)); List<String> denyNodeTypes = ofNullable(config.optJSONArray(CONFIG_DENY_NODE_TYPES)) .map(array -> StreamSupport.stream(array.spliterator(), false) .map(String::valueOf).collect(Collectors.toList())) .orElse(Collections.emptyList()); List<String> nodeTypeScope = ofNullable(config.optJSONArray(CONFIG_SCOPE_NODE_TYPES)) .map(array -> StreamSupport.stream(array.spliterator(), false) .map(String::valueOf).collect(Collectors.toList())) .orElse(Collections.emptyList()); List<JcrPropertyConstraints> propertyChecks = JcrPropertyConstraints .fromJSON(config.optJSONArray(CONFIG_PROPERTIES)); return new Check(pathScope, denyNodeTypes, nodeTypeScope, propertyChecks); }
@Override public ProgressCheck newInstance(final JSONObject jsonObject) { final String libsPathPrefix = jsonObject.optString(CONFIG_LIBS_PATH_PREFIX, LIBS_PATH_PREFIX); final Violation.Severity severity = Violation.Severity.valueOf(jsonObject.optString(CONFIG_SEVERITY, Violation.Severity.MAJOR.name()).toUpperCase()); final List<Rule> scopePaths = Rule.fromJSON(jsonObject.optJSONArray(CONFIG_SCOPE_PATHS)); final List<String> searchPaths = ofNullable(jsonObject.optJSONArray(CONFIG_SEARCH_PATHS)) .map(array -> StreamSupport.stream(array.spliterator(), false) .map(String::valueOf).collect(Collectors.toList())) .orElse(Arrays.asList("/apps", "/libs")); return new Check(libsPathPrefix, severity, scopePaths, searchPaths); }
private static Violation violationFromJSON(JSONObject jsonViolation) { String vSeverity = jsonViolation.optString(KEY_SEVERITY, Violation.Severity.MINOR.name()); Violation.Severity severity = Violation.Severity.valueOf(vSeverity); String description = jsonViolation.optString(KEY_DESCRIPTION, ""); List<PackageId> packages = new ArrayList<>(); JSONArray vPackages = jsonViolation.optJSONArray(KEY_PACKAGES); if (vPackages != null) { packages = StreamSupport.stream(vPackages.spliterator(), false) .map(v -> Optional.ofNullable(PackageId.fromString(String.valueOf(v)))) .filter(Optional::isPresent).map(Optional::get) .collect(Collectors.toList()); } return new SimpleViolation(severity, description, packages); }
@Override public ProgressCheck newInstance(final JSONObject config) throws Exception { if (config.has(CONFIG_ALLOWED_MODES)) { List<String> jsonAllowedModes = StreamSupport .stream(config.getJSONArray(CONFIG_ALLOWED_MODES).spliterator(), false) .map(String::valueOf).collect(Collectors.toList()); List<AccessControlHandling> allowedModes = new ArrayList<>(); for (String mode : jsonAllowedModes) { allowedModes.add(AccessControlHandling.valueOf(mode.toUpperCase())); } return new Check(ACHandlingLevelSet.EXPLICIT, allowedModes); } else if (config.has(CONFIG_LEVEL_SET)) { ACHandlingLevelSet levelSet = ACHandlingLevelSet.valueOf(config.getString(CONFIG_LEVEL_SET).toUpperCase()); return new Check(levelSet, Collections.emptyList()); } else { return new Check(ACHandlingLevelSet.NO_UNSAFE, Collections.emptyList()); } }
builder.withCndUrls(cndUrls); ofNullable(json.optJSONArray(KEY_JCR_NAMESPACES)) .map(jcrNamespaces -> StreamSupport.stream(jcrNamespaces.spliterator(), false) .filter(elem -> elem instanceof JSONObject) .map(JSONObject.class::cast) .ifPresent(builder::withJcrNamespaces); ofNullable(json.optJSONArray(KEY_JCR_PRIVILEGES)) .map(privs -> StreamSupport.stream(privs.spliterator(), false) .map(String::valueOf).collect(Collectors.toList())) .ifPresent(builder::withJcrPrivileges); ofNullable(json.optJSONArray(KEY_FORCED_ROOTS)) .map(forcedRoots -> StreamSupport.stream(forcedRoots.spliterator(), false) .filter(elem -> elem instanceof JSONObject) .map(JSONObject.class::cast) .ifPresent(builder::withForcedRoots); ofNullable(json.optJSONArray(KEY_CHECKS)) .map(checks -> StreamSupport.stream(checks.spliterator(), false) .filter(elem -> elem instanceof JSONObject) .map(JSONObject.class::cast)
double correctnessProb = spec.getDouble("p"); List<String> operatorProperties = spec.has("import") ? StreamSupport.stream(spec.optJSONArray("import").spliterator(), false).map(Objects::toString).collect(Collectors.toList()) : Collections.emptyList();
double correctnessProb = spec.getDouble("p"); List<String> operatorProperties = spec.has("import") ? StreamSupport.stream(spec.optJSONArray("import").spliterator(), false).map(Objects::toString).collect(Collectors.toList()) : Collections.emptyList();