Example usage for java.util Hashtable size

List of usage examples for java.util Hashtable size

Introduction

In this page you can find the example usage for java.util Hashtable size.

Prototype

public synchronized int size() 

Source Link

Document

Returns the number of keys in this hashtable.

Usage

From source file:org.wso2.carbon.mashup.javascript.hostobjects.pooledhttpclient.PooledHttpClientHostObject.java

/**
 * <p/>/*ww w .jav  a2  s . c o  m*/
 * This method executes the given HTTP method with user configured
 * details.ject to invoke a Web service. This method corresponds to the
 * following function of the HttpClient java script object.
 * </p>
 * <p/>
 * 
 * <pre>
 *    int executeMethod (
 *          in String method | in String url [, in String/Object content [, in Object params [,
 * Object headers]]]);
 */
public static Scriptable jsFunction_executeMethod(Context cx, Scriptable thisObj, Object[] args,
        Function funObj) {

    HttpMethod method = null;
    PooledHttpClientHostObject httpClientHostObject = (PooledHttpClientHostObject) thisObj;

    List<String> authSchemes = new ArrayList<String>();

    String contentType = PooledHttpClientHostObject.DEFAULT_CONTENT_TYPE;
    String charset = PooledHttpClientHostObject.DEFAULT_CHARSET;

    /*
     * we check weather authSchemes Priority has been set and put them into
     * a List
     */
    if (httpClientHostObject.authSchemePriority != null) {
        setAuthSchemes(httpClientHostObject, authSchemes);
    }

    if (httpClientHostObject.credentials != null) {
        setCredentials(httpClientHostObject, authSchemes);
    }

    if (httpClientHostObject.proxyCredentials != null) {
        setProxyCredentials(httpClientHostObject, authSchemes);
    }

    // checks whether cookies have been set
    if (httpClientHostObject.cookies != null) {
        setCookies(httpClientHostObject);
    }

    String methodName = null;
    // String url = null;
    NativeArray urls = null;
    Object content = null;
    NativeObject params = null;
    NativeArray headers = null;

    if (args[0] instanceof String) {
        methodName = (String) args[0];
    } else {
        throw new RuntimeException("HTTP method should be a String value");
    }

    if (args[1] instanceof String) {
        Object[] tmp = { args[1] };
        urls = (NativeArray) cx.newArray(thisObj, tmp);
    } else if (args[1] instanceof NativeArray) {
        urls = (NativeArray) args[1];
    } else {
        throw new RuntimeException("Url should be a String value or Array of Strings");
    }

    if (args.length > 2) {
        if (args[2] instanceof String) {
            content = (String) args[2];
        } else if (args[2] instanceof NativeArray) {
            content = (NativeArray) args[2];
        } else if (args[2] != null) {
            throw new RuntimeException("Content should be a String value or Array of Name-value pairs");
        }
    }

    if (args.length > 3) {
        if (args[3] instanceof NativeObject) {
            params = (NativeObject) args[3];
        } else if (args[3] != null) {
            throw new RuntimeException("Params argument should be an Object");
        }
    }

    if (args.length > 4) {
        if (args[4] instanceof NativeArray) {
            headers = (NativeArray) args[4];
        } else if (args[4] != null) {
            throw new RuntimeException("Headers argument should be an Object");
        }
    }

    Hashtable<String, SimpleHttpResponse> result = new Hashtable<String, SimpleHttpResponse>();
    int i = 0;
    for (i = 0; i < urls.getLength(); i++) {
        String url = urls.get(i, urls).toString();

        if (url != null) {
            if (methodName.equals("GET")) {
                method = new GetMethod(url);
            } else if (methodName.equals("POST")) {
                method = new PostMethod(url);
            } else if (methodName.equals("PUT")) {
                method = new PutMethod(url);
            } else if (methodName.equals("DELETE")) {
                method = new DeleteMethod(url);
            } else {
                throw new RuntimeException("HTTP method you specified is not supported");
            }
        } else {
            throw new RuntimeException("A url should be specified");
        }

        if (headers != null) {
            setHeaders(method, headers);
        }

        if (params != null) {
            setParams(httpClientHostObject, method, contentType, charset, methodName, content, params);
        } else if (content != null) {
            setContent(method, contentType, charset, methodName, content);
        }

        // check whether host configuration details has been set
        if (httpClientHostObject.host != null) {
            setHostConfig(httpClientHostObject);
        }

        pool.execute(new HttpCommand(httpClientHostObject.httpClient, method, result, i));
    }

    // wait for the result.
    int total = i;
    do {
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    } while (result.size() < total);

    if (result.size() == 1) {
        return Context.toObject(result.get("0"), thisObj);
    } else {
        // order matters
        Object[] res = new Object[result.size()];
        for (i = 0; i < result.size(); i++) {
            res[i] = result.get(i + "");
        }
        return Context.toObject(res, thisObj);
    }
}

From source file:org.lexevs.system.ResourceManager.java

/**
 * Removes the internal map.//  w w w.  ja  v a2 s . c o m
 * 
 * @param lcs the lcs
 */
private void removeInternalMap(LocalCodingScheme lcs) {

    Enumeration<String> e = codingSchemeLocalNamesToInternalNameMap_.keys();
    while (e.hasMoreElements()) {
        String key = (String) e.nextElement();
        Hashtable<String, String> temp = codingSchemeLocalNamesToInternalNameMap_.get(key);
        String temp_cs = temp.get(lcs.version);
        if (temp_cs != null && temp_cs.equals(lcs.codingSchemeName)) {
            temp.remove(lcs.version);
            if (temp.size() == 0) {
                codingSchemeLocalNamesToInternalNameMap_.remove(key);
            }
        }

    }

}

From source file:org.accada.reader.rprm.core.ReaderDevice.java

/**
 * Conversion of Hashtable of strings to a string array.
 * @param h//  ww  w.  ja  v  a  2 s .co  m
 *           The hashtable to convert
 * @return The array
 */
public final String[] stringsToArray(final Hashtable h) {

    String[] array = new String[h.size()];
    Enumeration iterator = h.elements();
    int i = 0;
    while (iterator.hasMoreElements()) {
        array[i] = (String) iterator.nextElement();
        i++;
    }

    return array;

}

From source file:org.accada.reader.rprm.core.ReaderDevice.java

/**
 * Conversion of Hashtable of sources to a source array.
 * @param h//from w  w  w  .j  a va2 s.com
 *           The hashtable to convert
 * @return The array
 */
public final Source[] sourcesToArray(final Hashtable h) {

    Source[] array = new Source[h.size()];
    Enumeration iterator = h.elements();
    int i = 0;
    while (iterator.hasMoreElements()) {
        array[i] = (Source) iterator.nextElement();
        i++;
    }

    return array;

}

From source file:org.accada.reader.rprm.core.ReaderDevice.java

/**
 * Conversion of Hashtable of triggers to a trigger array.
 * @param h/*from ww w. ja v a2  s. c om*/
 *           The hashtable to convert
 * @return The array
 */
public final Trigger[] triggersToArray(final Hashtable h) {

    Trigger[] array = new Trigger[h.size()];
    Enumeration iterator = h.elements();
    int i = 0;
    while (iterator.hasMoreElements()) {
        array[i] = (Trigger) iterator.nextElement();
        i++;
    }

    return array;

}

From source file:org.accada.reader.rprm.core.ReaderDevice.java

/**
 * Conversion of Hashtable of tag fields to a tag field array.
 * @param h//from  w w  w . ja v  a  2s.co m
 *           The hashtable to convert
 * @return The array
 */
public final TagField[] tagFieldsToArray(final Hashtable h) {

    TagField[] array = new TagField[h.size()];
    Enumeration iterator = h.elements();
    int i = 0;
    while (iterator.hasMoreElements()) {
        array[i] = (TagField) iterator.nextElement();
        i++;
    }

    return array;

}

From source file:org.accada.reader.rprm.core.ReaderDevice.java

/**
 * Conversion of Hashtable of read points to a read point array.
 * @param h//from w  ww .  ja  va2s .c  o  m
 *           The hashtable to convert
 * @return The array
 */
public final ReadPoint[] readPointsToArray(final Hashtable h) {

    ReadPoint[] array = new ReadPoint[h.size()];
    Enumeration iterator = h.elements();
    int i = 0;
    while (iterator.hasMoreElements()) {
        array[i] = (ReadPoint) iterator.nextElement();
        i++;
    }

    return array;

}

From source file:org.accada.reader.rprm.core.ReaderDevice.java

/**
 * Conversion of Hashtable of tag selectors to a tag selector array.
 * @param h// w w w  .j a va  2s . c om
 *           The hashtable to convert
 * @return The array
 */
public final TagSelector[] tagSelectorsToArray(final Hashtable h) {

    TagSelector[] array = new TagSelector[h.size()];
    Enumeration iterator = h.elements();
    int i = 0;
    while (iterator.hasMoreElements()) {
        array[i] = (TagSelector) iterator.nextElement();
        i++;
    }

    return array;

}

From source file:org.accada.reader.rprm.core.ReaderDevice.java

/**
 * Conversion of Hashtable of data selectors to a data selector array.
 * @param h/*from ww  w. jav  a 2s.  c  o  m*/
 *           The hashtable to convert
 * @return The array
 */
public final DataSelector[] dataSelectorsToArray(final Hashtable h) {

    DataSelector[] array = new DataSelector[h.size()];
    Enumeration iterator = h.elements();
    int i = 0;
    while (iterator.hasMoreElements()) {
        array[i] = (DataSelector) iterator.nextElement();
        i++;
    }

    return array;

}

From source file:org.accada.reader.rprm.core.ReaderDevice.java

/**
 * Conversion of Hashtable of notification channels to a notification.
 * channels array/*from   w w w.j  av a 2  s .  co  m*/
 * @param h
 *           The hashtable to convert
 * @return The array
 */
public final NotificationChannel[] notificationChannelsToArray(final Hashtable h) {

    NotificationChannel[] array = new NotificationChannel[h.size()];
    Enumeration iterator = h.elements();
    int i = 0;
    while (iterator.hasMoreElements()) {
        array[i] = (NotificationChannel) iterator.nextElement();
        i++;
    }

    return array;

}