io.sphere.sdk.models.Versioned Maven / Gradle / Ivy
package io.sphere.sdk.models;
/**
* Something that has an ID and a version.
*
* Typically this is a parameter of the an update or delete command.
* So for example you have
{@code ProductUpdateCommand of(final Versioned versioned, final UpdateAction updateAction)}
then you should NOT do:
*
* {@code final Product product = getProduct();
* //NOT GOOD
* final ProductUpdateCommand cmd = ProductUpdateCommand.of(Versioned.of(product.getId(), product.getVersion()), Publish.of()); }
*
* The resources already implement {@link Versioned} so you can use them directly:
* {@code final Product product = getProduct();
* //Product implements Versioned
* final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, Publish.of());}
*
*
* But there occasions where you submit ID and version in a form and want to update a resource without fetching it before:
* {@code final String id = "c7b25e66-465f-4b77-8c8b-10f0958a1436";
* final long version = 5;
* final ProductUpdateCommand cmd = ProductUpdateCommand.of(Versioned.of(id, version), Publish.of());}
*
* @param The type which has an ID and version.
*/
public interface Versioned extends Identifiable {
@Override
String getId();
Long getVersion();
/**
* Creates a versioned that only contains the id and the version.
* @param versioned the template object to use its ID and version
* @param The type which has an ID and version.
* @return versioned
*/
static Versioned of(final Versioned versioned) {
return of(versioned.getId(), versioned.getVersion());
}
static Versioned of(final String id, final long version) {
return new SimpleVersioned<>(id, version);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy