All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.arangodb.shaded.vertx.uritemplate.Variables Maven / Gradle / Ivy

There is a newer version: 7.8.0
Show newest version
/*
 * Copyright (c) 2011-2021 Contributors to the Eclipse Foundation
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
 * which is available at https://www.apache.org/licenses/LICENSE-2.0.
 *
 * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
 */
package com.arangodb.shaded.vertx.uritemplate;

import com.arangodb.shaded.vertx.codegen.annotations.Fluent;
import com.arangodb.shaded.vertx.codegen.annotations.VertxGen;
import com.arangodb.shaded.vertx.core.json.JsonObject;
import com.arangodb.shaded.vertx.uritemplate.impl.VariablesImpl;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Holds a set of name/value pairs where each value can be a {@code String} or a {@code List} or a {@code Map}.
 */
@VertxGen
public interface Variables {

  /**
   * @return an empty instance
   */
  static Variables variables() {
    return new VariablesImpl();
  }

  /**
   * Create an instance populated from a JSON object:
   *
   * 
    *
  • {@code null} are conserved
  • *
  • {@code JsonArray} is converted to {@code List}
  • *
  • {@code JsonObject} is converted to {@code Map}
  • *
  • any other value is converted to a string
  • *
* * Note that nested JSON elements are converted to a string, so { "user": { "first_name": "John", "last_name": "Doe", "address" : { "city": "Paris", etc... } } } * flattens the JSON "address" to the string "{\"city\":\"Paris\",etc...}". * * @param json the json that populates the returned variables * @return an instance populated from a JSON object */ static Variables variables(JsonObject json) { return variables().addAll(json); } /** * Set a single variable. * @param name the variable name * @param value the variable value * @return a reference to this, so the API can be used fluently */ @Fluent Variables set(String name, String value); /** * Set a list variable. * @param name the variable name * @param value the variable value * @return a reference to this, so the API can be used fluently */ @Fluent Variables set(String name, List value); /** * Set a map variable. * @param name the variable name * @param value the variable value * @return a reference to this, so the API can be used fluently */ @Fluent Variables set(String name, Map value); /** * Like {@link #addAll(JsonObject)} but overwrites previous variables. */ @Fluent default Variables setAll(JsonObject json) { return clear().addAll(json); } /** * Populates with a JSON object: * *
    *
  • {@code null} are conserved
  • *
  • {@code JsonArray} is converted to {@code List}
  • *
  • {@code JsonObject} is converted to {@code Map}
  • *
  • any other value is converted to a string
  • *
* * Note that nested JSON elements are converted to a string, so { "user": { "first_name": "John", "last_name": "Doe", "address" : { "city": "Paris", etc... } } } * flattens the JSON "address" to the string "{\"city\":\"Paris\",etc...}". * * @param json the json that populates the returned variables * @return a reference to this, so the API can be used fluently */ @Fluent Variables addAll(JsonObject json); @Fluent Variables clear(); /** * @return the set of variable names */ Set names(); /** * @return the value of the variable {@code name} */ Object get(String name); /** * @return the single value of the variable {@code name} */ String getSingle(String name); /** * @return the list value of the variable {@code name} */ List getList(String name); /** * @return the map value of the variable {@code name} */ Map getMap(String name); }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy