io.sphere.sdk.http.NameValuePair类的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(133)

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

NameValuePair介绍

暂无

代码示例

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

static Map<String, String> convertToStringMap(final List<NameValuePair> data) {
  final Map<String, String> map = new HashMap<>();
  data.forEach(pair -> map.put(pair.getName(), pair.getValue()));
  return Collections.unmodifiableMap(map);
}

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

@Override
public ProductProjectionSearch withMarkingMatchingVariants(final Boolean markMatchingVariants) {
  final Stream<NameValuePair> oldQueryParametersStream = additionalQueryParameters().stream()
      .filter(p -> !MARK_MATCHING_VARIANTS.equals(p.getName()));
  final Stream<NameValuePair> parameter = markMatchingVariants == null
      ? Stream.empty()
      : Stream.of(NameValuePair.of(MARK_MATCHING_VARIANTS, markMatchingVariants.toString()));
  final List<NameValuePair> parameters = Stream.concat(oldQueryParametersStream, parameter).collect(Collectors.toList());
  return withAdditionalQueryParameters(parameters);
}

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

/**
 * Creator if the order does not matter and there are no duplicates.
 * @param data name value pairs for the body
 * @return FormUrlEncodedHttpRequestBody
 */
public static FormUrlEncodedHttpRequestBody of(final Map<String, List<String>> data) {
  return of(NameValuePair.convertStringListMapToList(data));
}

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

@Nullable
public static PriceSelection extractPriceSelectionFromHttpQueryParameters(final List<NameValuePair> additionalHttpQueryParameters) {
  final List<NameValuePair> priceSelectionCandidates = additionalHttpQueryParameters
      .stream()
      .filter(pair -> ALL_PARAMETERS.contains(pair.getName()))
      .collect(Collectors.toList());
  final boolean containsPriceSelection = priceSelectionCandidates.stream()
      .anyMatch(pair -> PRICE_CURRENCY.equals(pair.getName()));
  return containsPriceSelection ? extractPriceSelection(priceSelectionCandidates) : null;
}

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

private static void addParamIfNotNull(final List<NameValuePair> resultingParameters, final String name, final String value) {
    if (value != null) {
      resultingParameters.add(NameValuePair.of(name, value));
    }
  }
}

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

@Nullable
public static PriceSelection extractPriceSelectionFromHttpQueryParameters(final List<NameValuePair> additionalHttpQueryParameters) {
  final List<NameValuePair> priceSelectionCandidates = additionalHttpQueryParameters
      .stream()
      .filter(pair -> ALL_PARAMETERS.contains(pair.getName()))
      .collect(Collectors.toList());
  final boolean containsPriceSelection = priceSelectionCandidates.stream()
      .anyMatch(pair -> PRICE_CURRENCY.equals(pair.getName()));
  return containsPriceSelection ? extractPriceSelection(priceSelectionCandidates) : null;
}

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

private static void addParamIfNotNull(final List<NameValuePair> resultingParameters, final String name, final String value) {
    if (value != null) {
      resultingParameters.add(NameValuePair.of(name, value));
    }
  }
}

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

/**
 * Gets the header as list since they can occur multiple times. If it does exist, the list is empty.
 * @param key the key of the header to find
 * @return empty or filled list of header values
 */
public List<String> getHeader(final String key) {
  return data.stream()
      .filter(entry -> entry.getName().equals(key))
      .map(entry -> entry.getValue())
      .collect(toList());
}

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

/**
 * SDK internal method to to add price selection query parameters to the additional query parameters list.
 * If {@code priceSelection} is null, the price selection parameters will be removed.
 *
 * @param priceSelection the new price selection which should be applied or null to remove the price selection
 * @param currentParameters list containing the additional query parameters, won't be changed
 * @return a new list with additional query parameters where the priceSelection is applied
 */
public static List<NameValuePair> getQueryParametersWithPriceSelection(@Nullable final PriceSelection priceSelection, final List<NameValuePair> currentParameters) {
  final List<NameValuePair> currentParametersWithoutPriceSelectionParameters = currentParameters.stream()
      .filter(pair -> !ALL_PARAMETERS.contains(pair.getName()))
      .collect(toList());
  final List<NameValuePair> resultingParameters = new LinkedList<>(currentParametersWithoutPriceSelectionParameters);
  if (priceSelection != null && priceSelection.getPriceCurrency() != null) {
    addParamIfNotNull(resultingParameters, PRICE_CURRENCY, priceSelection.getPriceCurrency());
    addParamIfNotNull(resultingParameters, PRICE_COUNTRY, priceSelection.getPriceCountry());
    addParamIfNotNull(resultingParameters, PRICE_CUSTOMER_GROUP, priceSelection.getPriceCustomerGroup());
    addParamIfNotNull(resultingParameters, PRICE_CHANNEL, priceSelection.getPriceChannel());
  }
  return resultingParameters;
}

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

@Override
public ProductProjectionSearch withMarkingMatchingVariants(final Boolean markMatchingVariants) {
  final Stream<NameValuePair> oldQueryParametersStream = additionalQueryParameters().stream()
      .filter(p -> !MARK_MATCHING_VARIANTS.equals(p.getName()));
  final Stream<NameValuePair> parameter = markMatchingVariants == null
      ? Stream.empty()
      : Stream.of(NameValuePair.of(MARK_MATCHING_VARIANTS, markMatchingVariants.toString()));
  final List<NameValuePair> parameters = Stream.concat(oldQueryParametersStream, parameter).collect(Collectors.toList());
  return withAdditionalQueryParameters(parameters);
}

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

private static List<NameValuePair> createQueryParameters(final String cartId) {
  return Collections.singletonList(NameValuePair.of("cartId", cartId));
}

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

public static HttpHeaders of(final Map<String, List<String>> headers) {
  return new HttpHeaders(NameValuePair.convertStringListMapToList(headers));
}

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

static Map<String, List<String>> convertToStringListMap(final List<NameValuePair> data) {
    final Map<String, List<String>> map = new HashMap<>();
    data.forEach(pair -> {
      final List<String> headersForKey = map.computeIfAbsent(pair.getName(), name -> new LinkedList<>());
      headersForKey.add(pair.getValue());
    });
    return Collections.unmodifiableMap(map);
  }
}

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

/**
 * SDK internal method to to add price selection query parameters to the additional query parameters list.
 * If {@code priceSelection} is null, the price selection parameters will be removed.
 *
 * @param priceSelection the new price selection which should be applied or null to remove the price selection
 * @param currentParameters list containing the additional query parameters, won't be changed
 * @return a new list with additional query parameters where the priceSelection is applied
 */
public static List<NameValuePair> getQueryParametersWithPriceSelection(@Nullable final PriceSelection priceSelection, final List<NameValuePair> currentParameters) {
  final List<NameValuePair> currentParametersWithoutPriceSelectionParameters = currentParameters.stream()
      .filter(pair -> !ALL_PARAMETERS.contains(pair.getName()))
      .collect(toList());
  final List<NameValuePair> resultingParameters = new LinkedList<>(currentParametersWithoutPriceSelectionParameters);
  if (priceSelection != null && priceSelection.getPriceCurrency() != null) {
    addParamIfNotNull(resultingParameters, PRICE_CURRENCY, priceSelection.getPriceCurrency());
    addParamIfNotNull(resultingParameters, PRICE_COUNTRY, priceSelection.getPriceCountry());
    addParamIfNotNull(resultingParameters, PRICE_CUSTOMER_GROUP, priceSelection.getPriceCustomerGroup());
    addParamIfNotNull(resultingParameters, PRICE_CHANNEL, priceSelection.getPriceChannel());
  }
  return resultingParameters;
}

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

private static List<NameValuePair> createQueryParameters(final String cartId) {
  return Collections.singletonList(NameValuePair.of("cartId", cartId));
}

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

private static HttpEntity urlEncodedOf(final FormUrlEncodedHttpRequestBody body) throws UnsupportedEncodingException {
  final List<BasicNameValuePair> values = body.getParameters()
      .stream()
      .map(entry -> new BasicNameValuePair(entry.getName(), entry.getValue()))
      .collect(Collectors.toList());
  return new UrlEncodedFormEntity(values);
}

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

static List<NameValuePair> convertStringListMapToList(final Map<String, List<String>> data) {
  final List<NameValuePair> list = new LinkedList<>();
  data.forEach((key, entriesList) -> {
    entriesList.forEach(value -> {
      list.add(NameValuePair.of(key, value));
    });
  });
  return Collections.unmodifiableList(list);
}

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

/**
 * @return the unordered data without duplicate names
 * @deprecated use {@link #getParameters()} instead
 */
@Deprecated
public Map<String, String> getData() {
  final Map<String, String> map = new HashMap<>();
  getParameters().forEach(pair -> map.put(pair.getName(), pair.getValue()));
  return map;
}

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

static List<NameValuePair> convertStringMapToList(final Map<String, String> data) {
  final List<NameValuePair> list = new ArrayList<>(data.size());
  data.forEach((key, value) -> list.add(NameValuePair.of(key, value)));
  return Collections.unmodifiableList(list);
}

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

private static HttpEntity urlEncodedOf(final FormUrlEncodedHttpRequestBody body) throws UnsupportedEncodingException {
  final List<BasicNameValuePair> values = body.getParameters()
      .stream()
      .map(entry -> new BasicNameValuePair(entry.getName(), entry.getValue()))
      .collect(Collectors.toList());
  return new UrlEncodedFormEntity(values);
}

相关文章

微信公众号

最新文章

更多