Tabnine Logo
EnumValue
Code IndexAdd Tabnine to your IDE (free)

How to use
EnumValue
in
io.sphere.sdk.models

Best Java code snippets using io.sphere.sdk.models.EnumValue (Showing top 20 results out of 315)

origin: com.commercetools.sdk.jvm.core/commercetools-models

@Override
protected String convertEnumValue(final EnumValue enumValue, final Attribute attribute, final ProductType productType) {
  return enumValue.getLabel();
}
origin: com.commercetools.sunrise.payment/payone-adapter

  public static List<EnumValue> getValuesAsListOfEnumValue() {
    return EnumSet.allOf(CreditCardNetwork.class)
            .stream()
            .map(p -> EnumValue.of(p.name(), p.getLabel()))
            .collect(Collectors.toList());
  }
}
origin: com.commercetools.sdk.jvm.core/commercetools-models

static AttributeAccess<EnumValue> ofEnumValue() {
  return AttributeAccessImpl.ofEnumLike(EnumValue.typeReference(), EnumAttributeType.class);
}
origin: com.commercetools.sdk.jvm.core/commercetools-models

static <T> AttributeDraft of(final String name, final T value) {
  final AttributeDraft result;
  if (value instanceof LocalizedEnumValue) {
    result = of(name, ((LocalizedEnumValue) value).getKey());
  } else if (value instanceof EnumValue) {
    result = of(name, ((EnumValue) value).getKey());
  } else if (value instanceof Set) {
    final Set<?> set = (Set<?>) value;
    if (!set.isEmpty()) {
      final Object setValue = set.stream().findAny().get();
      if (setValue instanceof LocalizedEnumValue || setValue instanceof EnumValue) {
        //WithKey is a interface the enum like implement
        final Set<String> newValues = set.stream().map(x -> ((WithKey) x).getKey()).collect(toSet());
        result = of(name, newValues);
      } else {
        result = of(name, SphereJsonUtils.toJsonNode(value));
      }
    } else {
      result = of(name, SphereJsonUtils.toJsonNode(value));
    }
  } else {
    result = of(name, SphereJsonUtils.toJsonNode(value));
  }
  return result;
}
origin: io.sphere.sdk.jvm/sphere-models

public static <T> AttributeDraft of(final String name, final T value) {
  final AttributeDraft result;
  if (value instanceof LocalizedEnumValue) {
    result = of(name, ((LocalizedEnumValue) value).getKey());
  } else if (value instanceof EnumValue) {
    result = of(name, ((EnumValue) value).getKey());
  } else if (value instanceof Set) {
    final Set<?> set = (Set<?>) value;
    if (!set.isEmpty()) {
      final Object setValue = set.stream().findAny().get();
      if (setValue instanceof LocalizedEnumValue || setValue instanceof EnumValue) {
        //WithKey is a interface the enum like implement
        final Set<String> newValues = set.stream().map(x -> ((WithKey) x).getKey()).collect(toSet());
        result = of(name, newValues);
      } else {
        result = of(name, SphereJsonUtils.toJsonNode(value));
      }
    } else {
      result = of(name, SphereJsonUtils.toJsonNode(value));
    }
  } else {
    result = of(name, SphereJsonUtils.toJsonNode(value));
  }
  return result;
}
origin: io.sphere.sdk.jvm/sphere-models

@Override
protected String convertEnumValue(final EnumValue enumValue, final Attribute attribute, final ProductType productType) {
  return enumValue.getLabel();
}
origin: commercetools/commercetools-jvm-sdk

static <T> AttributeDraft of(final String name, final T value) {
  final AttributeDraft result;
  if (value instanceof LocalizedEnumValue) {
    result = of(name, ((LocalizedEnumValue) value).getKey());
  } else if (value instanceof EnumValue) {
    result = of(name, ((EnumValue) value).getKey());
  } else if (value instanceof Set) {
    final Set<?> set = (Set<?>) value;
    if (!set.isEmpty()) {
      final Object setValue = set.stream().findAny().get();
      if (setValue instanceof LocalizedEnumValue || setValue instanceof EnumValue) {
        //WithKey is a interface the enum like implement
        final Set<String> newValues = set.stream().map(x -> ((WithKey) x).getKey()).collect(toSet());
        result = of(name, newValues);
      } else {
        result = of(name, SphereJsonUtils.toJsonNode(value));
      }
    } else {
      result = of(name, SphereJsonUtils.toJsonNode(value));
    }
  } else {
    result = of(name, SphereJsonUtils.toJsonNode(value));
  }
  return result;
}
origin: commercetools/commercetools-jvm-sdk

private static FieldDefinition enumFieldDefinition() {
  final List<EnumValue> enumValues = asList(EnumValue.of("key1", "label1"), EnumValue.of("key2", "label2"));
  return fieldDefinition(EnumFieldType.of(enumValues), ENUM_FIELD_NAME);
}
origin: io.sphere.sdk.jvm/sphere-models

static AttributeAccess<EnumValue> ofEnumValue() {
  return AttributeAccessImpl.ofEnumLike(EnumValue.typeReference(), EnumAttributeType.class);
}
origin: commercetools/commercetools-jvm-sdk

@Override
protected String convertEnumValue(final EnumValue enumValue, final Attribute attribute, final ProductType productType) {
  return enumValue.getLabel();
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void facetedSearchOnEnumKeySetAttributes() throws Exception {
  testResultWithTerms(PRODUCT_MODEL.allVariants().attribute().ofEnumSet(ATTR_NAME_ENUM_SET).key().is(ENUM_THREE.getKey()),
      ids -> assertThat(ids).containsOnly(product1.getId()),
      termStats -> assertThat(termStats).containsExactly(
          TermStats.of(ENUM_TWO.getKey(), 2L),
          TermStats.of(ENUM_THREE.getKey(), 1L)));
}
origin: commercetools/commercetools-jvm-sdk

private static FieldDefinition stateFieldDefinition() {
  final List<EnumValue> values = asList(
      EnumValue.of("published", "the category is publicly visible"),
      EnumValue.of("draft", "the category should not be displayed in the frontend")
  );
  final boolean required = false;
  final LocalizedString label = en("state of the category concerning to show it publicly");
  final String fieldName = "state";
  return FieldDefinition
      .of(EnumFieldType.of(values), fieldName, label, required);
}
origin: commercetools/commercetools-jvm-sdk

static AttributeAccess<EnumValue> ofEnumValue() {
  return AttributeAccessImpl.ofEnumLike(EnumValue.typeReference(), EnumAttributeType.class);
}
origin: com.commercetools.sunrise/common

public static String attributeValue(final Attribute attribute, final List<Locale> locales, final MetaProductType metaProductType) {
  final AttributeExtraction<String> attributeExtraction = AttributeExtraction.of(metaProductType, attribute);
  return attributeExtraction
      .ifIs(AttributeAccess.ofLocalizedString(), v -> v.find(locales).orElse(""))
      .ifIs(AttributeAccess.ofLocalizedEnumValue(), v -> v.getLabel().find(locales).orElse(""))
      .ifIs(AttributeAccess.ofEnumValue(), v -> v.getLabel())
      .ifIs(AttributeAccess.ofString(), v -> v)
      .findValue()
      .orElse("");
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void onEnumKeySetAttributes() throws Exception {
  testTermStats(FACET.allVariants().attribute().ofEnumSet(ATTR_NAME_ENUM_SET).key().allTerms(),
      termStats -> assertThat(termStats).containsExactly(
          TermStats.of(ENUM_TWO.getKey(), 2L),
          TermStats.of(ENUM_THREE.getKey(), 1L)));
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void queryByName() throws Exception {
  withTShirtProductType(type -> {
    final ProductType productType = client().executeBlocking(ProductTypeQuery.of().byName("t-shirt")).head().get();
    final Optional<AttributeDefinition> sizeAttribute = productType.findAttribute("size");
    final List<EnumValue> possibleSizeValues = sizeAttribute.
        map(attrib -> ((EnumAttributeType) attrib.getAttributeType()).getValues()).
        orElse(Collections.<EnumValue>emptyList());
    final List<EnumValue> expected =
        asList(EnumValue.of("S", "S"), EnumValue.of("M", "M"), EnumValue.of("X", "X"));
    assertThat(possibleSizeValues).isEqualTo(expected);
  });
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void facetedSearchOnEnumLabelSetAttributes() throws Exception {
  testResultWithTerms(PRODUCT_MODEL.allVariants().attribute().ofEnumSet(ATTR_NAME_ENUM_SET).label().is(ENUM_THREE.getLabel()),
      ids -> assertThat(ids).containsOnly(product1.getId()),
      termStats -> assertThat(termStats).containsExactly(
          TermStats.of(ENUM_TWO.getLabel(), 2L),
          TermStats.of(ENUM_THREE.getLabel(), 1L)));
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void facetedSearchOnEnumKeyAttributes() throws Exception {
  testResultWithTerms(PRODUCT_MODEL.allVariants().attribute().ofEnum(ATTR_NAME_ENUM).key().is(ENUM_TWO.getKey()),
      ids -> assertThat(ids).containsOnly(product1.getId()),
      termStats -> assertThat(termStats).containsOnly(
          TermStats.of(ENUM_TWO.getKey(), 1L),
          TermStats.of(ENUM_THREE.getKey(), 1L)));
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void changePlainEnumValueLabel() throws Exception {
  final String attributeName = randomKey();
  final AttributeDefinition attributeDefinition = AttributeDefinitionBuilder.of(attributeName, randomSlug(),
      EnumAttributeType.of(
          EnumValue.of("key1", "label 1"),
          EnumValue.of("key2", "label 2")
      )).build();
  final String key = randomKey();
  final ProductTypeDraft productTypeDraft = ProductTypeDraft.of(key, key, key, singletonList(attributeDefinition));
  withUpdateableProductType(client(), () -> productTypeDraft, productType -> {
    final ProductType updatedProductType = client().executeBlocking(ProductTypeUpdateCommand.of(productType, ChangePlainEnumValueLabel.of(attributeName, EnumValue.of("key2", "label 2 (updated)"))));
    final EnumAttributeType updatedAttributeType = (EnumAttributeType) updatedProductType.getAttribute(attributeName).getAttributeType();
    assertThat(updatedAttributeType.getValues())
        .containsExactly(EnumValue.of("key1", "label 1"), EnumValue.of("key2", "label 2 (updated)"));
    return updatedProductType;
  });
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void readAttributeGetValueAs() throws Exception {
  final ProductVariant masterVariant = createProduct().getMasterData().getStaged().getMasterVariant();
  final String attributeValue = masterVariant.findAttribute(SIZE_ATTR_NAME)
      .map((Attribute a) -> {
        final EnumValue enumValue = a.getValueAsEnumValue();
        return enumValue.getLabel();
      })
      .orElse("not found");
  assertThat(attributeValue).isEqualTo("S");
}
io.sphere.sdk.modelsEnumValue

Most used methods

  • getLabel
  • getKey
  • of
  • typeReference

Popular in Java

  • Finding current android device location
  • getSystemService (Context)
  • startActivity (Activity)
  • getApplicationContext (Context)
  • SQLException (java.sql)
    An exception that indicates a failed JDBC operation. It provides the following information about pro
  • Calendar (java.util)
    Calendar is an abstract base class for converting between a Date object and a set of integer fields
  • Servlet (javax.servlet)
    Defines methods that all servlets must implement. A servlet is a small Java program that runs within
  • JFrame (javax.swing)
  • Reflections (org.reflections)
    Reflections one-stop-shop objectReflections scans your classpath, indexes the metadata, allows you t
  • Location (org.springframework.beans.factory.parsing)
    Class that models an arbitrary location in a Resource.Typically used to track the location of proble
  • From CI to AI: The AI layer in your organization
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now