Interface Change<T>


public interface Change<T>
A modification of an individual Entry.
  • Method Details

    • ofTextUpsert

      static Change<String> ofTextUpsert(String path, String text)
      Returns a newly-created Change whose type is ChangeType.UPSERT_TEXT.

      Note that you should use ofJsonUpsert(String, String) if the specified path ends with ".json" or ".json5". The ofJsonUpsert(String, String) will check that the given text is a valid JSON.

      Parameters:
      path - the path of the file
      text - the content of the file
      Throws:
      ChangeFormatException - if the path ends with ".json" or ".json5"
    • ofJsonUpsert

      static Change<JsonNode> ofJsonUpsert(String path, String jsonText)
      Returns a newly-created Change whose type is ChangeType.UPSERT_JSON.
      Parameters:
      path - the path of the file
      jsonText - the content of the file
      Throws:
      ChangeFormatException - if the specified jsonText is not a valid JSON
    • ofJsonUpsert

      static Change<JsonNode> ofJsonUpsert(String path, JsonNode jsonNode)
      Returns a newly-created Change whose type is ChangeType.UPSERT_JSON.
      Parameters:
      path - the path of the file
      jsonNode - the content of the file
    • ofYamlUpsert

      static Change<JsonNode> ofYamlUpsert(String path, String yamlText)
      Returns a newly-created Change whose type is ChangeType.UPSERT_YAML.
      Parameters:
      path - the path of the file
      yamlText - the content of the file
    • ofRemoval

      static Change<Void> ofRemoval(String path)
      Returns a newly-created Change whose type is ChangeType.REMOVE.
      Parameters:
      path - the path of the file to remove
    • ofRename

      static Change<String> ofRename(String oldPath, String newPath)
      Returns a newly-created Change whose type is ChangeType.RENAME.
      Parameters:
      oldPath - the old path of the file
      newPath - the new path of the file
    • ofTextPatch

      static Change<String> ofTextPatch(String path, @Nullable String oldText, String newText)
      Returns a newly-created Change whose type is ChangeType.APPLY_TEXT_PATCH.

      Note that you should use ofJsonPatch(String, String, String) if the specified path ends with ".json". The ofJsonUpsert(String, String) will check that the given oldText and newText are valid JSONs.

      Parameters:
      path - the path of the file
      oldText - the old content of the file
      newText - the new content of the file
      Throws:
      ChangeFormatException - if the path ends with ".json"
    • ofTextPatch

      static Change<String> ofTextPatch(String path, String textPatch)
      Returns a newly-created Change whose type is ChangeType.APPLY_TEXT_PATCH.

      Note that you should use ofJsonPatch(String, String) if the specified path ends with ".json". The ofJsonUpsert(String, String) will check that the given textPatch is a valid JSON.

      Parameters:
      path - the path of the file
      textPatch - the patch in unified format
      Throws:
      ChangeFormatException - if the path ends with ".json"
    • ofJsonPatch

      static Change<JsonNode> ofJsonPatch(String path, @Nullable String oldJsonText, String newJsonText)
      Returns a newly-created Change whose type is ChangeType.APPLY_JSON_PATCH.

      Note that the JSON patch operation normalizes the original data before applying the patch, so contextual information such as comments cannot be retained when the patch is applied.

      Parameters:
      path - the path of the file
      oldJsonText - the old content of the file
      newJsonText - the new content of the file
      Throws:
      ChangeFormatException - if the specified oldJsonText or newJsonText is not a valid JSON
    • ofJsonPatch

      static Change<JsonNode> ofJsonPatch(String path, @Nullable JsonNode oldJsonNode, JsonNode newJsonNode)
      Returns a newly-created Change whose type is ChangeType.APPLY_JSON_PATCH.

      Note that the JSON patch operation normalizes the original data before applying the patch, so contextual information such as comments cannot be retained when the patch is applied.

      Parameters:
      path - the path of the file
      oldJsonNode - the old content of the file
      newJsonNode - the new content of the file
    • ofJsonPatch

      static Change<JsonNode> ofJsonPatch(String path, JsonPatchOperation jsonPatch)
      Returns a newly-created Change whose type is ChangeType.APPLY_JSON_PATCH. The JSON patch operation can be applied to JSON, JSON5, YAML files.

      Note that the JSON patch operation normalizes the original data before applying the patch, so contextual information such as comments cannot be retained when the patch is applied.

      Parameters:
      path - the path of the file
      jsonPatch - the patch in JSON patch format
    • ofJsonPatch

      static Change<JsonNode> ofJsonPatch(String path, JsonPatchOperation... jsonPatches)
      Returns a newly-created Change whose type is ChangeType.APPLY_JSON_PATCH. The JSON patch operation can be applied to JSON, JSON5, YAML files.

      Note that the JSON patch operation normalizes the original data before applying the patch, so contextual information such as comments cannot be retained when the patch is applied.

      Parameters:
      path - the path of the file
      jsonPatches - the list of patches in JSON patch format
    • ofJsonPatch

      static Change<JsonNode> ofJsonPatch(String path, Iterable<? extends JsonPatchOperation> jsonPatches)
      Returns a newly-created Change whose type is ChangeType.APPLY_JSON_PATCH. The JSON patch operation can be applied to JSON, JSON5, YAML files.

      Note that the JSON patch operation normalizes the original data before applying the patch, so contextual information such as comments cannot be retained when the patch is applied.

      Parameters:
      path - the path of the file
      jsonPatches - the list of patches in JSON patch format
    • ofJsonPatch

      static Change<JsonNode> ofJsonPatch(String path, String jsonPatchText)
      Returns a newly-created Change whose type is ChangeType.APPLY_JSON_PATCH. The JSON patch operation can be applied to JSON, JSON5, YAML files.

      Note that the JSON patch operation normalizes the original data before applying the patch, so contextual information such as comments cannot be retained when the patch is applied.

      Parameters:
      path - the path of the file
      jsonPatchText - the patch in JSON patch format
      Throws:
      ChangeFormatException - if the specified jsonPatchText is not a valid JSON
    • ofJsonPatch

      static Change<JsonNode> ofJsonPatch(String path, JsonNode jsonPatchNode)
      Returns a newly-created Change whose type is ChangeType.APPLY_JSON_PATCH. The JSON patch operation can be applied to JSON, JSON5, YAML files.

      Note that the JSON patch operation normalizes the original data before applying the patch, so contextual information such as comments cannot be retained when the patch is applied.

      Parameters:
      path - the path of the file
      jsonPatchNode - the patch in JSON patch format
    • fromDirectory

      static List<Change<?>> fromDirectory(Path sourcePath, String targetPath)
      Creates a List of upsert Changes from all files under the specified directory recursively.
      Parameters:
      sourcePath - the path to the import directory
      targetPath - the target directory path of the imported Changes
      Throws:
      IOError - if I/O error occurs
    • fromFile

      static Change<?> fromFile(Path sourcePath, String targetPath)
      Creates a new Change from the file at the specified location.
      Parameters:
      sourcePath - the path to the regular file to import
      targetPath - the target path of the imported Change
    • type

      ChangeType type()
      Returns the type of the Change.
    • path

      String path()
      Returns the path of the Change.
    • content

      @Nullable T content()
      Returns the content of the Change, which depends on the type().
    • rawContent

      @Nullable String rawContent()
      Returns the raw content of the Change as-is without any transformation. If a JsonNode was set as the content, raw content will be null.
    • contentAsText

      @Nullable String contentAsText()
      Returns the textual representation of content().