public function add($key, $object, $lifetime = 0)
    {
        // check if a key has been passed
        if (is_null($key)) {
            throw new NullPointerException('Passed key is null');
        }
        // check if lifetime is of type integer
        if (is_integer($lifetime) === false) {
            throw new InvalidLifetimeException(sprintf('Passed lifetime must be an integer, but is %s instead', $lifetime));
        }
        // check if a primitive datatype is passed
        if (is_integer($key) || is_string($key) || is_double($key) || is_bool($key)) {
            // add the item and lifetime to the array
            $this->items[$key] = $object;
            // add a lifetime if passed lifetime > 0
            if ($lifetime > 0) {
                $this->lifetime[$key] = time() + $lifetime;
            }
            // and return
            return;
        }
        // check if an object is passed
        if (is_object($key)) {
            if ($key instanceof String) {
                $newKey = $key->stringValue();
            } elseif ($key instanceof Float) {
                $newKey = $key->floatValue();
            } elseif ($key instanceof Integer) {
                $newKey = $key->intValue();
            } elseif ($key instanceof Boolean) {
                $newKey = $key->booleanValue();
            } elseif (method_exists($key, '__toString')) {
                $newKey = $key->__toString();
            } else {
                throw new InvalidKeyException('Passed key has to be a primitive datatype or has to implement the __toString() method');
            }
            // add the item and lifetime to the array
            $this->items[$newKey] = $object;
            // add a lifetime if passed lifetime > 0
            if ($lifetime > 0) {
                $this->lifetime[$newKey] = time() + $lifetime;
            }
            // and return
            return;
        }
        throw new InvalidKeyException('Passed key has to be a primitive datatype or has to implement the __toString() method');
    }
public function add($key, $object, $lifetime = 0)
    {
        // check if a key has been passed
        if (is_null($key)) {
            throw new NullPointerException('Passed key is null');
        }
        // check if lifetime is of type integer
        if (is_integer($lifetime) === false) {
            throw new InvalidLifetimeException(sprintf('Passed lifetime must be an integer, but is %s instead', $lifetime));
        }
        // check if a primitive datatype is passed
        if (is_integer($key) || is_string($key) || is_double($key) || is_bool($key)) {
            // add the item and lifetime to the array
            $this->items[$key] = $object;
            // add a lifetime if passed lifetime > 0
            if ($lifetime > 0) {
                $this->lifetime[$key] = time() + $lifetime;
            }
            // and return
            return;
        }
        // check if an object is passed
        if (is_object($key)) {
            if ($key instanceof String) {
                $newKey = $key->stringValue();
            } elseif ($key instanceof Float) {
                $newKey = $key->floatValue();
            } elseif ($key instanceof Integer) {
                $newKey = $key->intValue();
            } elseif ($key instanceof Boolean) {
                $newKey = $key->booleanValue();
            } elseif (method_exists($key, '__toString')) {
                $newKey = $key->__toString();
            } else {
                throw new InvalidKeyException('Passed key has to be a primitive datatype or has to implement the __toString() method');
            }
            // add the item and lifetime to the array
            $this->items[$newKey] = $object;
            // add a lifetime if passed lifetime > 0
            if ($lifetime > 0) {
                $this->lifetime[$newKey] = time() + $lifetime;
            }
            // and return
            return;
        }
        throw new InvalidKeyException('Passed key has to be a primitive datatype or has to implement the __toString() method');
    }
public function add ( $ key , $ object , $ lifetime = 0 ) { // check if a key has been passed if ( is_null ( $ key ) ) { throw new NullPointerException ( 'Passed key is null' ) ; } // check if lifetime is of type integer if ( is_integer ( $ lifetime ) === false ) { throw new InvalidLifetimeException ( sprintf ( 'Passed lifetime must be an integer, but is %s instead' , $ lifetime ) ) ; } // check if a primitive datatype is passed if ( is_integer ( $ key ) || is_string ( $ key ) || is_double ( $ key ) || is_bool ( $ key ) ) { // add the item and lifetime to the array $ this -> items [ $ key ] = $ object ; // add a lifetime if passed lifetime > 0 if ( $ lifetime > 0 ) { $ this -> lifetime [ $ key ] = time ( ) + $ lifetime ; } // and return return ; } // check if an object is passed if ( is_object ( $ key ) ) { if ( $ key instanceof String ) { $ newKey = $ key -> stringValue ( ) ; } elseif ( $ key instanceof Float ) { $ newKey = $ key -> floatValue ( ) ; } elseif ( $ key instanceof Integer ) { $ newKey = $ key -> intValue ( ) ; } elseif ( $ key instanceof Boolean ) { $ newKey = $ key -> booleanValue ( ) ; } elseif ( method_exists ( $ key , '__toString' ) ) { $ newKey = $ key -> __toString ( ) ; } else { throw new InvalidKeyException ( 'Passed key has to be a primitive datatype or has to implement the __toString() method' ) ; } // add the item and lifetime to the array $ this -> items [ $ newKey ] = $ object ; // add a lifetime if passed lifetime > 0 if ( $ lifetime > 0 ) { $ this -> lifetime [ $ newKey ] = time ( ) + $ lifetime ; } // and return return ; } throw new InvalidKeyException ( 'Passed key has to be a primitive datatype or has to implement the __toString() method' ) ; }
This method adds the passed object with the passed key
to the instance.

@param mixed   $key      The key to add the passed value under
@param mixed   $object   The object to add to the instance
@param integer $lifetime The items lifetime

@return null
@throws \AppserverIo\Collections\InvalidKeyException Is thrown if the passed key is NOT an primitive datatype
@throws \AppserverIo\Lang\NullPointerException Is thrown if the passed key is null or not a flat datatype like Integer, String, Double or Boolean
This method adds the passed object with the passed key to the instance .