Source: vertx-js/multi_map.js

/*
 * Copyright 2014 Red Hat, Inc.
 *
 * Red Hat licenses this file to you under the Apache License, version 2.0
 * (the "License"); you may not use this file except in compliance with the
 * License.  You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

/** @module vertx-js/multi_map */
var utils = require('vertx-js/util/utils');
var Promise = require('vertx-js/promise');

var io = Packages.io;
var JsonObject = io.vertx.core.json.JsonObject;
var JsonArray = io.vertx.core.json.JsonArray;
var JMultiMap = Java.type('io.vertx.core.MultiMap');

/**
 This class represents a MultiMap of String keys to a List of String values.
 <p>
 It's useful in Vert.x to represent things in Vert.x like HTTP headers and HTTP parameters which allow
 multiple values for keys.

 @class
*/
var MultiMap = function(j_val) {

  var j_multiMap = j_val;
  var that = this;

  var __super_caseInsensitiveMultiMap = this.caseInsensitiveMultiMap;
  var __super_get = this.get;
  var __super_getAll = this.getAll;
  var __super_contains = this.contains;
  var __super_contains = this.contains;
  var __super_isEmpty = this.isEmpty;
  var __super_names = this.names;
  var __super_add = this.add;
  var __super_addAll = this.addAll;
  var __super_set = this.set;
  var __super_setAll = this.setAll;
  var __super_remove = this.remove;
  var __super_clear = this.clear;
  var __super_size = this.size;
  /**
   Returns the value of with the specified name.  If there are
   more than one values for the specified name, the first value is returned.

   @public
   @param name {string} The name of the header to search 
   @return {string} The first header value or <code>null</code> if there is no such entry
   */
  this.get =  function(name) {
    var __args = arguments;
    if (__args.length === 1 && typeof __args[0] === 'string') {
      return j_multiMap["get(java.lang.String)"](name) ;
    } else if (typeof __super_get != 'undefined') {
      return __super_get.apply(this, __args);
    }
    else throw new TypeError('function invoked with invalid arguments');
  };

  /**
   Returns the values with the specified name

   @public
   @param name {string} The name to search 
   @return {Array.<string>} A immutable List of values which will be empty if no values are found
   */
  this.getAll =  function(name) {
    var __args = arguments;
    if (__args.length === 1 && typeof __args[0] === 'string') {
      return j_multiMap["getAll(java.lang.String)"](name) ;
    } else if (typeof __super_getAll != 'undefined') {
      return __super_getAll.apply(this, __args);
    }
    else throw new TypeError('function invoked with invalid arguments');
  };

  /**
   Check if there is a header with the specified <code>name</code> and <code>value</code>.

   If <code>caseInsensitive</code> is <code>true</code>, <code>value</code> is compared in a case-insensitive way.

   @public
   @param name {string} the name to search for 
   @param value {string} the value to search for 
   @param caseInsensitive {boolean} 
   @return {boolean} <code>true</code> if at least one entry is found
   */
  this.contains =  function() {
    var __args = arguments;
    if (__args.length === 1 && typeof __args[0] === 'string') {
      return j_multiMap["contains(java.lang.String)"](__args[0]) ;
    } else if (__args.length === 3 && typeof __args[0] === 'string' && typeof __args[1] === 'string' && typeof __args[2] ==='boolean') {
      return j_multiMap["contains(java.lang.String,java.lang.String,boolean)"](__args[0], __args[1], __args[2]) ;
    } else if (typeof __super_contains != 'undefined') {
      return __super_contains.apply(this, __args);
    }
    else throw new TypeError('function invoked with invalid arguments');
  };

  /**
   Return true if empty

   @public

   @return {boolean}
   */
  this.isEmpty =  function() {
    var __args = arguments;
    if (__args.length === 0) {
      return j_multiMap["isEmpty()"]() ;
    } else if (typeof __super_isEmpty != 'undefined') {
      return __super_isEmpty.apply(this, __args);
    }
    else throw new TypeError('function invoked with invalid arguments');
  };

  /**
   Gets a immutable Set of all names

   @public

   @return {Array.<string>} A Set of all names
   */
  this.names =  function() {
    var __args = arguments;
    if (__args.length === 0) {
      return utils.convReturnSet(j_multiMap["names()"]()) ;
    } else if (typeof __super_names != 'undefined') {
      return __super_names.apply(this, __args);
    }
    else throw new TypeError('function invoked with invalid arguments');
  };

  /**
   Adds a new value with the specified name and value.

   @public
   @param name {string} The name 
   @param value {string} The value being added 
   @return {MultiMap} a reference to this, so the API can be used fluently
   */
  this.add =  function(name, value) {
    var __args = arguments;
    if (__args.length === 2 && typeof __args[0] === 'string' && typeof __args[1] === 'string') {
      j_multiMap["add(java.lang.String,java.lang.String)"](name, value) ;
      return that;
    } else if (typeof __super_add != 'undefined') {
      return __super_add.apply(this, __args);
    }
    else throw new TypeError('function invoked with invalid arguments');
  };

  /**
   Adds all the entries from another MultiMap to this one

   @public
   @param map {MultiMap} 
   @return {MultiMap} a reference to this, so the API can be used fluently
   */
  this.addAll =  function(map) {
    var __args = arguments;
    if (__args.length === 1 && typeof __args[0] === 'object' && __args[0]._jdel) {
      j_multiMap["addAll(io.vertx.core.MultiMap)"](map._jdel) ;
      return that;
    } else if (typeof __super_addAll != 'undefined') {
      return __super_addAll.apply(this, __args);
    }
    else throw new TypeError('function invoked with invalid arguments');
  };

  /**
   Sets a value under the specified name.
   <p>
   If there is an existing header with the same name, it is removed.

   @public
   @param name {string} The name 
   @param value {string} The value 
   @return {MultiMap} a reference to this, so the API can be used fluently
   */
  this.set =  function(name, value) {
    var __args = arguments;
    if (__args.length === 2 && typeof __args[0] === 'string' && typeof __args[1] === 'string') {
      j_multiMap["set(java.lang.String,java.lang.String)"](name, value) ;
      return that;
    } else if (typeof __super_set != 'undefined') {
      return __super_set.apply(this, __args);
    }
    else throw new TypeError('function invoked with invalid arguments');
  };

  /**
   Cleans this instance.

   @public
   @param map {MultiMap} 
   @return {MultiMap} a reference to this, so the API can be used fluently
   */
  this.setAll =  function(map) {
    var __args = arguments;
    if (__args.length === 1 && typeof __args[0] === 'object' && __args[0]._jdel) {
      j_multiMap["setAll(io.vertx.core.MultiMap)"](map._jdel) ;
      return that;
    } else if (typeof __super_setAll != 'undefined') {
      return __super_setAll.apply(this, __args);
    }
    else throw new TypeError('function invoked with invalid arguments');
  };

  /**
   Removes the value with the given name

   @public
   @param name {string} The name of the value to remove 
   @return {MultiMap} a reference to this, so the API can be used fluently
   */
  this.remove =  function(name) {
    var __args = arguments;
    if (__args.length === 1 && typeof __args[0] === 'string') {
      j_multiMap["remove(java.lang.String)"](name) ;
      return that;
    } else if (typeof __super_remove != 'undefined') {
      return __super_remove.apply(this, __args);
    }
    else throw new TypeError('function invoked with invalid arguments');
  };

  /**
   Removes all

   @public

   @return {MultiMap} a reference to this, so the API can be used fluently
   */
  this.clear =  function() {
    var __args = arguments;
    if (__args.length === 0) {
      j_multiMap["clear()"]() ;
      return that;
    } else if (typeof __super_clear != 'undefined') {
      return __super_clear.apply(this, __args);
    }
    else throw new TypeError('function invoked with invalid arguments');
  };

  /**
   Return the number of keys.

   @public

   @return {number}
   */
  this.size =  function() {
    var __args = arguments;
    if (__args.length === 0) {
      return j_multiMap["size()"]() ;
    } else if (typeof __super_size != 'undefined') {
      return __super_size.apply(this, __args);
    }
    else throw new TypeError('function invoked with invalid arguments');
  };

  // A reference to the underlying Java delegate
  // NOTE! This is an internal API and must not be used in user code.
  // If you rely on this property your code is likely to break if we change it / remove it without warning.
  this._jdel = j_multiMap;
};

MultiMap._jclass = utils.getJavaClass("io.vertx.core.MultiMap");
MultiMap._jtype = {accept: function(obj) {
    return MultiMap._jclass.isInstance(obj._jdel);
  },wrap: function(jdel) {
    var obj = Object.create(MultiMap.prototype, {});
    MultiMap.apply(obj, arguments);
    return obj;
  },
  unwrap: function(obj) {
    return obj._jdel;
  }
};
MultiMap._create = function(jdel) {var obj = Object.create(MultiMap.prototype, {});
  MultiMap.apply(obj, arguments);
  return obj;
}
/**
 Create a multi-map implementation with case insensitive keys, for instance it can be used to hold some HTTP headers.

 @memberof module:vertx-js/multi_map

 @return {MultiMap} the multi-map
 */
MultiMap.caseInsensitiveMultiMap =  function() {
  var __args = arguments;
  if (__args.length === 0) {
    return utils.convReturnVertxGen(MultiMap, JMultiMap["caseInsensitiveMultiMap()"]()) ;
  }else throw new TypeError('function invoked with invalid arguments');
};

module.exports = MultiMap;