/** * Returns a newly-created {@link Change} whose type is {@link ChangeType#REMOVE}. * * @param path the path of the file to remove */ static Change<Void> ofRemoval(String path) { return new DefaultChange<>(path, ChangeType.REMOVE, null); }
/** * Returns a newly-created {@link Change} whose type is {@link ChangeType#REMOVE}. * * @param path the path of the file to remove */ static Change<Void> ofRemoval(String path) { return new DefaultChange<>(path, ChangeType.REMOVE, null); }
/** * Returns a newly-created {@link Change} whose type is {@link ChangeType#REMOVE}. * * @param path the path of the file to remove */ static Change<Void> ofRemoval(String path) { return new DefaultChange<>(path, ChangeType.REMOVE, null); }
/** * Returns a newly-created {@link Change} whose type is {@link ChangeType#APPLY_JSON_PATCH}. * * @param path the path of the file * @param jsonPatchNode the patch in <a href="https://tools.ietf.org/html/rfc6902">JSON patch format</a> */ static Change<JsonNode> ofJsonPatch(String path, JsonNode jsonPatchNode) { requireNonNull(jsonPatchNode, "jsonPatchNode"); return new DefaultChange<>(path, ChangeType.APPLY_JSON_PATCH, jsonPatchNode); }
/** * Returns a newly-created {@link Change} whose type is {@link ChangeType#APPLY_JSON_PATCH}. * * @param path the path of the file * @param jsonPatchNode the patch in <a href="https://tools.ietf.org/html/rfc6902">JSON patch format</a> */ static Change<JsonNode> ofJsonPatch(String path, JsonNode jsonPatchNode) { requireNonNull(jsonPatchNode, "jsonPatchNode"); return new DefaultChange<>(path, ChangeType.APPLY_JSON_PATCH, jsonPatchNode); }
/** * Returns a newly-created {@link Change} whose type is {@link ChangeType#APPLY_TEXT_PATCH}. * * @param path the path of the file * @param textPatch the patch in * <a href="https://en.wikipedia.org/wiki/Diff_utility#Unified_format">unified format</a> */ static Change<String> ofTextPatch(String path, String textPatch) { requireNonNull(textPatch, "textPatch"); return new DefaultChange<>(path, ChangeType.APPLY_TEXT_PATCH, textPatch); }
/** * Returns a newly-created {@link Change} whose type is {@link ChangeType#UPSERT_TEXT}. * * @param path the path of the file * @param text the content of the file */ static Change<String> ofTextUpsert(String path, String text) { requireNonNull(text, "text"); return new DefaultChange<>(path, ChangeType.UPSERT_TEXT, text); }
/** * Returns a newly-created {@link Change} whose type is {@link ChangeType#UPSERT_JSON}. * * @param path the path of the file * @param jsonNode the content of the file */ static Change<JsonNode> ofJsonUpsert(String path, JsonNode jsonNode) { requireNonNull(jsonNode, "jsonNode"); return new DefaultChange<>(path, ChangeType.UPSERT_JSON, jsonNode); }
/** * Returns a newly-created {@link Change} whose type is {@link ChangeType#UPSERT_TEXT}. * * @param path the path of the file * @param text the content of the file */ static Change<String> ofTextUpsert(String path, String text) { requireNonNull(text, "text"); return new DefaultChange<>(path, ChangeType.UPSERT_TEXT, text); }
/** * Returns a newly-created {@link Change} whose type is {@link ChangeType#APPLY_TEXT_PATCH}. * * @param path the path of the file * @param textPatch the patch in * <a href="https://en.wikipedia.org/wiki/Diff_utility#Unified_format">unified format</a> */ static Change<String> ofTextPatch(String path, String textPatch) { requireNonNull(textPatch, "textPatch"); return new DefaultChange<>(path, ChangeType.APPLY_TEXT_PATCH, textPatch); }
/** * Returns a newly-created {@link Change} whose type is {@link ChangeType#UPSERT_JSON}. * * @param path the path of the file * @param jsonNode the content of the file */ static Change<JsonNode> ofJsonUpsert(String path, JsonNode jsonNode) { requireNonNull(jsonNode, "jsonNode"); return new DefaultChange<>(path, ChangeType.UPSERT_JSON, jsonNode); }
/** * Returns a newly-created {@link Change} whose type is {@link ChangeType#UPSERT_JSON}. * * @param path the path of the file * @param jsonNode the content of the file */ static Change<JsonNode> ofJsonUpsert(String path, JsonNode jsonNode) { requireNonNull(jsonNode, "jsonNode"); return new DefaultChange<>(path, ChangeType.UPSERT_JSON, jsonNode); }
/** * Returns a newly-created {@link Change} whose type is {@link ChangeType#APPLY_JSON_PATCH}. * * @param path the path of the file * @param jsonPatchNode the patch in <a href="https://tools.ietf.org/html/rfc6902">JSON patch format</a> */ static Change<JsonNode> ofJsonPatch(String path, JsonNode jsonPatchNode) { requireNonNull(jsonPatchNode, "jsonPatchNode"); return new DefaultChange<>(path, ChangeType.APPLY_JSON_PATCH, jsonPatchNode); }
/** * Returns a newly-created {@link Change} whose type is {@link ChangeType#APPLY_TEXT_PATCH}. * * @param path the path of the file * @param textPatch the patch in * <a href="https://en.wikipedia.org/wiki/Diff_utility#Unified_format">unified format</a> */ static Change<String> ofTextPatch(String path, String textPatch) { requireNonNull(textPatch, "textPatch"); return new DefaultChange<>(path, ChangeType.APPLY_TEXT_PATCH, textPatch); }
/** * Returns a newly-created {@link Change} whose type is {@link ChangeType#UPSERT_TEXT}. * * @param path the path of the file * @param text the content of the file */ static Change<String> ofTextUpsert(String path, String text) { requireNonNull(text, "text"); return new DefaultChange<>(path, ChangeType.UPSERT_TEXT, text); }
/** * Returns a newly-created {@link Change} whose type is {@link ChangeType#APPLY_JSON_PATCH}. * * @param path the path of the file * @param oldJsonNode the old content of the file * @param newJsonNode the new content of the file */ static Change<JsonNode> ofJsonPatch(String path, @Nullable JsonNode oldJsonNode, JsonNode newJsonNode) { requireNonNull(newJsonNode, "newJsonNode"); if (oldJsonNode == null) { oldJsonNode = Jackson.nullNode; } return new DefaultChange<>(path, ChangeType.APPLY_JSON_PATCH, JsonPatch.generate(oldJsonNode, newJsonNode, ReplaceMode.SAFE).toJson()); }
/** * Returns a newly-created {@link Change} whose type is {@link ChangeType#RENAME}. * * @param oldPath the old path of the file * @param newPath the new path of the file */ static Change<String> ofRename(String oldPath, String newPath) { validateFilePath(oldPath, "oldPath"); validateFilePath(newPath, "newPath"); return new DefaultChange<>(oldPath, ChangeType.RENAME, newPath); }
/** * Returns a newly-created {@link Change} whose type is {@link ChangeType#RENAME}. * * @param oldPath the old path of the file * @param newPath the new path of the file */ static Change<String> ofRename(String oldPath, String newPath) { validateFilePath(oldPath, "oldPath"); validateFilePath(newPath, "newPath"); return new DefaultChange<>(oldPath, ChangeType.RENAME, newPath); }
/** * Returns a newly-created {@link Change} whose type is {@link ChangeType#RENAME}. * * @param oldPath the old path of the file * @param newPath the new path of the file */ static Change<String> ofRename(String oldPath, String newPath) { validateFilePath(oldPath, "oldPath"); validateFilePath(newPath, "newPath"); return new DefaultChange<>(oldPath, ChangeType.RENAME, newPath); }
/** * Returns a newly-created {@link Change} whose type is {@link ChangeType#APPLY_TEXT_PATCH}. * * @param path the path of the file * @param oldText the old content of the file * @param newText the new content of the file */ static Change<String> ofTextPatch(String path, @Nullable String oldText, String newText) { validateFilePath(path, "path"); requireNonNull(newText, "newText"); final List<String> oldLineList = oldText == null ? Collections.emptyList() : Util.stringToLines(oldText); final List<String> newLineList = Util.stringToLines(newText); final Patch<String> patch = DiffUtils.diff(oldLineList, newLineList); final List<String> unifiedDiff = DiffUtils.generateUnifiedDiff(path, path, oldLineList, patch, 3); return new DefaultChange<>(path, ChangeType.APPLY_TEXT_PATCH, String.join("\n", unifiedDiff)); }