io.sphere.sdk.models.Reference.getId()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(132)

本文整理了Java中io.sphere.sdk.models.Reference.getId方法的一些代码示例,展示了Reference.getId的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Reference.getId方法的具体详情如下:
包路径:io.sphere.sdk.models.Reference
类名称:Reference
方法名:getId

Reference.getId介绍

[英]Id of the object this reference represents.
[中]此引用表示的对象的Id。

代码示例

代码示例来源:origin: com.commercetools.sdk.jvm.core/commercetools-models

@Nullable
protected <X> String convertReference(final Reference<X> reference, final ProductType productType) {
  return reference.getId();
}

代码示例来源: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/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: commercetools/commercetools-jvm-sdk

@Override
public QueryPredicate<T> isIn(final List<? extends Referenceable<R>> elements) {
  final List<String> ids = elements.stream().map(elem -> elem.toReference().getId()).collect(toList());
  return isInIds(ids);
}

代码示例来源:origin: com.commercetools.sdk.jvm.core/commercetools-models

@Override
public Category getRootAncestor(final Identifiable<Category> category) {
  requireNonNull(category);
  final Category theCategory = CategoryTreeUtils.getCategoryOrThrow(category, this);
  return theCategory
      .getAncestors().stream().findFirst()
      .flatMap(root -> findById(root.getId()))
      .orElse(theCategory);
}

代码示例来源:origin: io.sphere.sdk.jvm/sphere-models

@Nullable
@Override
public T convert(final Attribute attribute, final Referenceable<ProductType> productType) {
  final String productTypeId = productType.toReference().getId();
  final Optional<ProductType> productTypeOptional = productTypes.findById(productTypeId);
  return productTypeOptional.map(pt -> convertWithProductType(attribute, pt)).orElse(null);
}

代码示例来源:origin: commercetools/commercetools-jvm-sdk

@Override
public final QueryPredicate<T> isIn(final Iterable<? extends Referenceable<R>> references) {
  final List<String> ids = toStream(references).map(r -> r.toReference().getId()).collect(toList());
  return id().isIn(ids);
}

代码示例来源:origin: io.sphere.sdk.jvm/models

private static Multimap<String, Category> buildParentMultiMap(List<Category> categoriesWithParents) {
  final Multimap<String, Category> categoriesByParentId = new Multimap<>();
  for (final Category categoryWithParent : categoriesWithParents) {
    final String parentId = categoryWithParent.getParent().get().getId();
    categoriesByParentId.put(parentId, categoryWithParent);
  }
  return categoriesByParentId;
}

代码示例来源:origin: io.sphere.sdk.jvm/categories

private static Multimap<String, Category> buildParentMultiMap(List<Category> categoriesWithParents) {
  final Multimap<String, Category> categoriesByParentId = new Multimap<>();
  for (final Category categoryWithParent : categoriesWithParents) {
    final String parentId = categoryWithParent.getParent().get().getId();
    categoriesByParentId.put(parentId, categoryWithParent);
  }
  return categoriesByParentId;
}

代码示例来源:origin: io.sphere.sdk.jvm/products

private static Multimap<String, Category> buildParentMultiMap(List<Category> categoriesWithParents) {
  final Multimap<String, Category> categoriesByParentId = new Multimap<>();
  for (final Category categoryWithParent : categoriesWithParents) {
    final String parentId = categoryWithParent.getParent().get().getId();
    categoriesByParentId.put(parentId, categoryWithParent);
  }
  return categoriesByParentId;
}

代码示例来源:origin: io.sphere.sdk.jvm/common

/**
 * Serializer to convert the given reference into the identifier value.
 * @param <R> type of the reference.
 * @return the serializer for references of the given type.
 */
public static <R> TypeSerializer<Referenceable<R>> ofReference() {
  return new TypeSerializer<>(v -> withQuotes(v.toReference().getId()));
}

代码示例来源:origin: commercetools/commercetools-jvm-sdk

@Override
  public QueryPredicate<ProductProjection> is(final Referenceable<Product> product) {
    return id().is(product.toReference().getId());
  }
}

代码示例来源:origin: com.commercetools.sdk.jvm.core/commercetools-models

@Override
  public QueryPredicate<ProductProjection> is(final Referenceable<Product> product) {
    return id().is(product.toReference().getId());
  }
}

代码示例来源:origin: commercetools/commercetools-jvm-sdk

@Test
public void cartWithRefusedGifts() {
  final Cart cart = SphereJsonUtils.readObjectFromResource("carts/cart-with-refused-gifts.json", Cart.class);
  final List<Reference<CartDiscount>> refusedGifts = cart.getRefusedGifts();
  assertThat(refusedGifts).hasSize(1);
  final Reference<CartDiscount> refusedGift = refusedGifts.get(0);
  assertThat(refusedGift.getId()).isEqualTo("<my-cart-discount-id>");
}

代码示例来源:origin: commercetools/commercetools-jvm-sdk

@Test
public void deserializeRefusedGifts(){
  final Order order = SphereJsonUtils.readObjectFromResource("order/order-with-refused-gift.json", Order.class);
  assertThat(order.getRefusedGifts()).hasSize(1);
  assertThat(order.getRefusedGifts().get(0).getId()).isEqualTo("<my-order-discount-id>");
}

代码示例来源: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: commercetools/commercetools-jvm-sdk

@Test
public void createEmptyReference() throws Exception {
  final Reference<TestEntity> reference = newEmptyReference();
  assertThat(reference.getId()).isEqualTo(id);
  assertThat(reference.getTypeId()).isEqualTo(typeId);
  assertThat(reference.getObj()).isNull();
}

代码示例来源:origin: commercetools/commercetools-jvm-sdk

@Test
public void toReference() {
  final Category category = getCategory1();
  final Reference<Category> categoryReference = category.toReference();
  assertThat(category.getId()).isEqualTo(categoryReference.getId());
}

代码示例来源:origin: commercetools/commercetools-jvm-sdk

@Test
public void cartState() {
  OrderFixtures.withOrder(client(), order -> {
    final CartQuery query = CartQuery.of()
        .plusPredicates(m -> m.cartState().is(CartState.ORDERED))
        .plusPredicates(m -> m.is(order.getCart()));
    final List<Cart> results = client().executeBlocking(query).getResults();
    assertThat(results).hasSize(1);
    assertThat(results.get(0).getId()).isEqualTo(order.getCart().getId());
    return order;
  });
}

相关文章