Compare

View as Markdown

Compare

A branch comparison lists the differences in content types and global fields between a base branch and a compare branch. Use this class to hold the two branches and the headers and query parameters for that comparison.

stack.branch("<BRANCH>").compare("docs-test-branch") returns a Compare with <BRANCH> as the base branch. The public constructor takes the internal Retrofit instance of the SDK, so use the compare method of Branch instead.

NameTypeDescription
branchUidStringUID of the base branch. Pass it to stack.branch().
compareBranchIdStringUID of the branch to compare. Pass it to compare().
  • Known issue: In 1.16.0, Compare has no public method that sends a request, so the SDK cannot run a branch comparison. Send the Compare branches request with another HTTP client.

addHeader

addHeader adds one request header to this comparison.

NameTypeDescription
key (required)String

Name of the header.

Default: Not applicable
value (required)String

Value of the header.

Default: Not applicable

Returns: Compare. The same comparison, for chaining.

Validation

  • There is no client-side validation. A null key or value does not throw here.
  • Nothing reports a bad value, because no public method of Compare sends a request in 1.16.0.

Behavior

  • addHeader stores the header in the header map of this object and sends nothing.
  • A later call with the same name replaces the value.
  • The header goes on the headers of the comparison. In 1.16.0, no public method of Compare sends them, and stays there for every later request.
  • A new Compare object holds only a Content-Type header. It does not carry the api_key and authorization headers of the stack.

Example

Basic usage: add the API key header to a comparison

import com.contentstack.cms.Contentstack;
import com.contentstack.cms.stack.Compare;

public class CompareHeader {
    public static void main(String[] args) {
        Contentstack client = new Contentstack.Builder().build();

        Compare compare = client.stack("<API_KEY>", "<MANAGEMENT_TOKEN>")
                .branch("main")
                .compare("docs-test-branch")
                .addHeader("api_key", "<API_KEY>");

        // Compare has no public request method in 1.16.0, so the header stays on the object
        System.out.println("Stored the api_key header on the comparison.");
    }
}

addHeaders

addHeaders adds every entry of a map to the request headers of this comparison.

NameTypeDescription
headers (required)HashMap

Header names mapped to their values.

Default: Not applicable

Returns: Compare. The same comparison, for chaining.

Validation

  • Throws NullPointerException if headers is null, because addHeaders copies every entry of the map.
  • Nothing reports a bad value, because no public method of Compare sends a request in 1.16.0.

Behavior

  • addHeaders copies the entries into the header map of this object and sends nothing.
  • An entry replaces a header with the same name.
  • The headers go on the headers of the comparison. In 1.16.0, no public method of Compare sends them, and stay there for every later request.
  • A new Compare object holds only a Content-Type header. It does not carry the api_key and authorization headers of the stack.

Example

Basic usage: add the stack credentials to a comparison

import com.contentstack.cms.Contentstack;
import com.contentstack.cms.stack.Compare;

import java.util.HashMap;

public class CompareHeaders {
    public static void main(String[] args) {
        Contentstack client = new Contentstack.Builder().build();

        HashMap<String, String> headers = new HashMap<>();
        headers.put("api_key", "<API_KEY>");
        headers.put("authorization", "<MANAGEMENT_TOKEN>");

        Compare compare = client.stack("<API_KEY>", "<MANAGEMENT_TOKEN>")
                .branch("main")
                .compare("docs-test-branch")
                .addHeaders(headers);

        // Compare has no public request method in 1.16.0, so the headers stay on the object
        System.out.println("Stored " + headers.size() + " headers on the comparison.");
    }
}

addParam

addParam adds one query parameter to this comparison.

NameTypeDescription
key (required)String

Name of the query parameter.

Default: Not applicable
value (required)Object

Value of the query parameter, sent as its string form.

Default: Not applicable

Returns: Compare. The same comparison, for chaining.

Validation

  • There is no client-side validation. A null key or value does not throw here.
  • Nothing reports a bad value, because no public method of Compare sends a request in 1.16.0.

Behavior

  • addParam stores the pair in the query parameter map of this object and sends nothing.
  • A later call with the same key replaces the value.
  • The parameter goes on the query parameters of the comparison. In 1.16.0, no public method of Compare sends them.
  • The parameter stays on the object for every later request.
  • The Compare branches reference lists skip and limit for this request, and include_schemas for the requests on one content type or global field.

Example

Basic usage: set the page size of a comparison

import com.contentstack.cms.Contentstack;
import com.contentstack.cms.stack.Compare;

public class LimitComparison {
    public static void main(String[] args) {
        Contentstack client = new Contentstack.Builder().build();

        Compare compare = client.stack("<API_KEY>", "<MANAGEMENT_TOKEN>")
                .branch("main")
                .compare("docs-test-branch")
                .addParam("limit", 50);

        // Compare has no public request method in 1.16.0, so the parameter stays on the object
        System.out.println("Stored the limit parameter on the comparison.");
    }
}

addParams

addParams adds every entry of a map to the query parameters of this comparison.

NameTypeDescription
params (required)HashMap

Query parameter names mapped to their values.

Default: Not applicable

Returns: Compare. The same comparison, for chaining.

Validation

  • Throws NullPointerException if params is null, because addParams copies every entry of the map.
  • Nothing reports a bad value, because no public method of Compare sends a request in 1.16.0.

Behavior

  • addParams copies the entries into the query parameter map of this object and sends nothing.
  • An entry replaces a parameter with the same name.
  • The parameters go on the query parameters of the comparison. In 1.16.0, no public method of Compare sends them.
  • The parameters stay on the object for every later request.
  • The Compare branches reference lists skip and limit for this request, and include_schemas for the requests on one content type or global field.

Example

Basic usage: set several comparison parameters

import com.contentstack.cms.Contentstack;
import com.contentstack.cms.stack.Compare;

import java.util.HashMap;

public class ConfigureComparison {
    public static void main(String[] args) {
        Contentstack client = new Contentstack.Builder().build();

        HashMap<String, Object> params = new HashMap<>();
        params.put("skip", 0);
        params.put("limit", 50);
        params.put("include_schemas", true);

        Compare compare = client.stack("<API_KEY>", "<MANAGEMENT_TOKEN>")
                .branch("main")
                .compare("docs-test-branch")
                .addParams(params);

        // Compare has no public request method in 1.16.0, so the parameters stay on the object
        System.out.println("Stored " + params.size() + " parameters on the comparison.");
    }
}