本文整理了Java中io.sphere.sdk.models.Reference
类的一些代码示例,展示了Reference
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Reference
类的具体详情如下:
包路径:io.sphere.sdk.models.Reference
类名称:Reference
[英]A io.sphere.sdk.models.Reference is a loose reference to another resource on the platform.
The reference may have a copy of the referenced object available via the method io.sphere.sdk.models.Reference#getObj() on io.sphere.sdk.models.Reference#getObj().
For equals, only the Reference#getTypeId() and io.sphere.sdk.models.Reference#getId() are compared used and Reference#getObj() will be ignored.
[中]木卫一。球sdk。模型。引用是对平台上其他资源的松散引用。
引用可以通过方法io获得引用对象的副本。球sdk。模型。io上的参考#getObj()。球sdk。模型。参考#getObj()。
对于equals,只有引用#getTypeId()和io。球sdk。模型。将使用引用#getId()进行比较,并忽略引用#getObj()。
代码示例来源:origin: com.commercetools.sdk.jvm.core/commercetools-models
private Map<String, List<Category>> getChildrenByParentIdMap(final List<Category> allCategoriesAsFlatList) {
final Map<String, List<Category>> childrenByParentId = new HashMap<>();
allCategoriesAsFlatList.forEach(category ->
Optional.ofNullable(category.getParent()).ifPresent(parentReference -> {
final String parentId = parentReference.getId();
final List<Category> entries = childrenByParentId.getOrDefault(parentId, new LinkedList<>());
entries.add(category);
childrenByParentId.put(parentId, entries);
})
);
return childrenByParentId;
}
代码示例来源:origin: io.sphere.sdk.jvm/sphere-models
@Override
public Reference<ProductDiscount> toReference() {
return Reference.of(ProductDiscount.referenceTypeId(), this);
}
}
代码示例来源:origin: io.sphere.jvmsdk/common
public static <T> Reference<T> of(final String typeId, final String id, T obj) {
return Reference.<T>of(typeId, id).filled(obj);
}
代码示例来源:origin: io.sphere.sdk.jvm/common
public Reference<T> filled(final Optional<T> obj) {
return new Reference<>(getTypeId(), getId(), obj);
}
代码示例来源:origin: io.sphere.sdk.jvm/common
@SuppressWarnings("rawtypes")//at runtime generic type is not determinable
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Reference reference = (Reference) o;
if (!getId().equals(reference.getId())) return false;
if (!getTypeId().equals(reference.getTypeId())) return false;
return true;
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
@Override
public void serialize(final Reference reference, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider) throws IOException {
jsonGenerator.writeStartObject();
jsonGenerator.writeStringField("id", reference.getId());
jsonGenerator.writeStringField("typeId", reference.getTypeId());
jsonGenerator.writeObjectField("obj", reference.getObj());
jsonGenerator.writeEndObject();
}
}
代码示例来源:origin: io.sphere.sdk.jvm/sphere-test-lib
@Override
public boolean matches(final T value) {
return value.getObj() != null;
}
};
代码示例来源:origin: io.sphere.sdk.jvm/sphere-models
@Override
public JsonNode serialize(final T t) {
return mapper().valueToTree(t.toReference().filled(null));
}
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
@Test
public void referencesAreNotByDefaultExpanded() {
withCustomerInGroup(client(), (customer, customerGroup) -> {
final CustomerByIdGet customerByIdGet = CustomerByIdGet.of(customer);
final Customer loadedCustomer = client().executeBlocking(customerByIdGet);
final Reference<CustomerGroup> customerGroupReference = loadedCustomer.getCustomerGroup();
assertThat(customerGroupReference.getId()).isEqualTo(customerGroup.getId());
assertThat(customerGroupReference.getObj())
.as("reference is not expanded")
.isNull();
});
}
代码示例来源:origin: io.sphere.jvmsdk/common
public Reference<T> filled(final T obj) {
return filled(Optional.ofNullable(obj));
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
@Test
public void implementEquals() throws Exception {
assertThat(newFilledReference()).isEqualTo(newFilledReference());
assertThat(newEmptyReference()).isEqualTo(newEmptyReference());
assertThat(newFilledReference()).isEqualTo(newEmptyReference());
assertThat(newFilledReference()).isEqualTo(newEmptyReference().filled(new TestEntity("other value")));
assertThat(Reference.<String>of(typeId, "Foo", "x")).isNotEqualTo(newEmptyReference());
assertThat(Reference.<String>ofResourceTypeIdAndIdAndObj(typeId, "Foo", "x")).isNotEqualTo(newEmptyReference());
}
代码示例来源:origin: com.commercetools.sdk.jvm.core/commercetools-models
public static CustomFieldsDraftBuilder of(final CustomFields customFields) {
final Reference<Type> type = customFields.getType();
return new CustomFieldsDraftBuilder(type.getId(), type.getKey()).fields(customFields.getFieldsJsonMap());
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
@Test
public void attributeShouldKeepExpansions() throws Exception {
final AttributeAccess<Reference<Product>> access = AttributeAccess.ofProductReference();
final NamedAttributeAccess<Reference<Product>> namedAccess = access.ofName("foo");
assertThat(EXPANDED_PRODUCT_REFERENCE.getObj()).overridingErrorMessage("product reference is expanded").isNotNull();
final Attribute attribute = Attribute.of(namedAccess, EXPANDED_PRODUCT_REFERENCE);
assertThat(attribute.getValue(access).getObj()).isNotNull();
final String jsonFilledRef = SphereJsonUtils.toJsonString(EXPANDED_PRODUCT_REFERENCE);
final String jsonEmptyRef = SphereJsonUtils.toJsonString(EXPANDED_PRODUCT_REFERENCE.filled(null));
assertThat(jsonFilledRef)
.overridingErrorMessage("references are not expanded if serialized")
.doesNotContain(EXPANDED_PRODUCT_REFERENCE.getObj().getMasterData().getStaged().getName().get(Locale.ENGLISH))
.isEqualTo(jsonEmptyRef);
}
代码示例来源:origin: io.sphere.sdk.jvm/common
public static <T> Reference<T> of(final String typeId, final String id) {
return new Reference<>(typeId, id, Optional.empty());
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
@Test
public void createAttributeFromReferenceSet(){
final Product product = SphereJsonUtils.readObjectFromResource("product1.json", Product.class);
final Reference<Product> expandedReference =
Reference.ofResourceTypeIdAndIdAndObj(Product.referenceTypeId(), UUID.randomUUID().toString(), product);
final HashSet<Reference<Product>> references = new HashSet<>();
references.add(expandedReference);
final Attribute attribute = Attribute.of("attrName", AttributeAccess.ofProductReferenceSet(), references);
assertThat(attribute.getValue(AttributeAccess.ofProductReferenceSet()).stream().allMatch(productReference -> productReference.getObj() != null)).isTrue();
}
代码示例来源:origin: io.sphere.sdk.jvm/sphere-models
public static CustomFieldsDraft ofCustomFields(final CustomFields custom) {
return CustomFieldsDraft.ofTypeIdAndJson(custom.getType().getTypeId(), custom.getFieldsJsonMap());
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
@Test
public void setCustomerGroup() throws Exception {
withB2cCustomerGroup(client(), customerGroup -> {
final Cart cart = createCartWithCountry(client());
assertThat(cart.getCustomerGroup()).isNull();
Cart updatedCart = client().executeBlocking(CartUpdateCommand.of(cart, SetCustomerGroup.of(customerGroup)));
assertThat(updatedCart.getCustomerGroup().toReference()).isEqualTo(customerGroup.toReference());
client().executeBlocking(CartDeleteCommand.of(updatedCart));
});
}
代码示例来源:origin: io.sphere.sdk.jvm/common
public boolean referencesSameResource(final Referenceable<T> counterpart) {
final Reference<T> reference = counterpart.toReference();
return reference.getId().equals(getId()) && reference.getTypeId().equals(getTypeId());
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
@Test
public void createFilledReference() throws Exception {
final Reference<TestEntity> reference = newFilledReference();
assertThat(reference.getId()).isEqualTo(id);
assertThat(reference.getTypeId()).isEqualTo(typeId);
assertThat(reference.getObj()).isEqualTo(new TestEntity("value"));
}
代码示例来源:origin: io.sphere.jvmsdk/common
public Reference<T> filled(final Optional<T> obj) {
return new Reference<>(getTypeId(), getId(), obj);
}
内容来源于网络,如有侵权,请联系作者删除!