Example usage for java.util Hashtable isEmpty

List of usage examples for java.util Hashtable isEmpty

Introduction

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

Prototype

public synchronized boolean isEmpty() 

Source Link

Document

Tests if this hashtable maps no keys to values.

Usage

From source file:MainClass.java

public static void main(String[] s) {
    Hashtable table = new Hashtable();
    table.put("key1", "value1");
    table.put("key2", "value2");
    table.put("key3", "value3");

    System.out.println(table.isEmpty());
    System.out.println(table.size());
}

From source file:Main.java

public static void main(String[] s) {
    Hashtable<String, String> table = new Hashtable<String, String>();
    table.put("key1", "value1");
    table.put("key2", "value2");
    table.put("key3", "value3");

    System.out.println(table.isEmpty());
    System.out.println(table.size());
}

From source file:Main.java

public static void main(String args[]) {
    // create hash table 
    Hashtable<Integer, String> htable1 = new Hashtable<Integer, String>();

    // put values in table
    htable1.put(1, "A");
    htable1.put(2, "B");
    htable1.put(3, "C");
    htable1.put(4, "from java2s.com");

    // check if table is empty
    System.out.println("Is hash table empty :" + htable1.isEmpty());
}

From source file:org.wso2.carbon.certificate.mgt.core.dao.CertificateManagementDAOUtil.java

public static DataSource lookupDataSource(String dataSourceName,
        final Hashtable<Object, Object> jndiProperties) {
    try {//w  w w  .  ja v a  2s  .  co  m
        if (jndiProperties == null || jndiProperties.isEmpty()) {
            return (DataSource) InitialContext.doLookup(dataSourceName);
        }
        final InitialContext context = new InitialContext(jndiProperties);
        return (DataSource) context.doLookup(dataSourceName);
    } catch (Exception e) {
        throw new RuntimeException("Error in looking up data source: " + e.getMessage(), e);
    }
}

From source file:org.wso2.carbon.device.mgt.core.dao.util.GroupManagementDAOUtil.java

/**
 * Lookup datasource using name and jndi properties
 *
 * @param dataSourceName Name of datasource to lookup
 * @param jndiProperties Hash table of JNDI Properties
 * @return datasource looked//  www . j  a  va 2s.com
 */
public static DataSource lookupDataSource(String dataSourceName,
        final Hashtable<Object, Object> jndiProperties) {
    try {
        if (jndiProperties == null || jndiProperties.isEmpty()) {
            return (DataSource) InitialContext.doLookup(dataSourceName);
        }
        final InitialContext context = new InitialContext(jndiProperties);
        return (DataSource) context.lookup(dataSourceName);
    } catch (Exception e) {
        throw new RuntimeException("Error in looking up data source: " + e.getMessage(), e);
    }
}

From source file:org.wso2.carbon.device.mgt.mobile.android.impl.dao.util.MobileDeviceManagementDAOUtil.java

public static DataSource lookupDataSource(String dataSourceName,
        final Hashtable<Object, Object> jndiProperties) {

    try {/*from w  w w  .j a  v a  2  s .  c om*/
        if (jndiProperties == null || jndiProperties.isEmpty()) {
            return (DataSource) InitialContext.doLookup(dataSourceName);
        }
        final InitialContext context = new InitialContext(jndiProperties);
        return (DataSource) context.lookup(dataSourceName);
    } catch (Exception e) {
        String msg = "Error in looking up data source: " + e.getMessage();
        log.error(msg, e);
        throw new RuntimeException(msg + e.getMessage(), e);
    }
}

From source file:org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil.java

public static DataSource lookupDataSource(String dataSourceName,
        final Hashtable<Object, Object> jndiProperties) {
    try {//  w  w w . j  a  va  2s  .co  m
        if (jndiProperties == null || jndiProperties.isEmpty()) {
            return (DataSource) InitialContext.doLookup(dataSourceName);
        }
        final InitialContext context = new InitialContext(jndiProperties);
        return (DataSource) context.lookup(dataSourceName);
    } catch (Exception e) {
        throw new RuntimeException("Error in looking up data source: " + e.getMessage(), e);
    }
}

From source file:org.wso2.carbon.cassandra.mgt.util.CassandraManagementUtils.java

public static Cluster lookupCluster(String jndiName, final Hashtable<Object, Object> jndiProperties) {
    try {/*  w  w  w  .  j  a  v a 2  s .c om*/
        if (jndiProperties == null || jndiProperties.isEmpty()) {
            return (Cluster) InitialContext.doLookup(jndiName);
        }
        final InitialContext context = new InitialContext(jndiProperties);
        return (Cluster) context.doLookup(jndiName);
    } catch (Exception e) {
        throw new RuntimeException("Error in looking up cluster instance: " + e.getMessage(), e);
    }
}

From source file:org.chililog.server.data.MongoUtils.java

/**
 * Saves a key-value map to the mongoDB object
 * /*from   w  w  w  .ja  va 2  s.  c  o m*/
 * @param dbObject
 *            mongoDB DBObject to which data will be saved
 * @param fieldName
 *            name of field to save
 * @param fieldValue
 *            value of field to save
 * @param isRequired
 *            flag to indicate if field is required.
 * @throws ChiliLogException
 */
public static void setKeyValuePairs(DBObject dbObject, String fieldName, Hashtable<String, String> fieldValue,
        boolean isRequired) throws ChiliLogException {
    if (dbObject == null) {
        throw new IllegalArgumentException("dbObject is null");
    }
    if (StringUtils.isBlank(fieldName)) {
        throw new IllegalArgumentException("fieldName is blank");
    }
    if (isRequired && (fieldValue == null || fieldValue.isEmpty())) {
        throw new ChiliLogException(Strings.MONGODB_MISSING_REQURIED_FIELD_ERROR, fieldName);
    }

    BasicDBObject obj = new BasicDBObject();
    for (Entry<String, String> s : fieldValue.entrySet()) {
        String key = s.getKey();
        String value = s.getValue();
        obj.put(key, value);
    }
    dbObject.put(fieldName, obj);
}

From source file:com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller.java

/**
 * Checks if the XML-RPC response is an GreenPepper server Exception.
 * If so an GreenPepperServerException will be thrown with the error id found.
 * </p>/*w ww. j  av  a  2s.  c om*/
 *
 * @param xmlRpcResponse a {@link java.lang.Object} object.
 * @throws com.greenpepper.server.GreenPepperServerException if any.
 */
public static void checkForErrors(Object xmlRpcResponse) throws GreenPepperServerException {
    if (xmlRpcResponse instanceof Vector) {
        Vector temp = (Vector) xmlRpcResponse;
        if (!temp.isEmpty()) {
            checkErrors(temp.elementAt(0));
        }
    } else if (xmlRpcResponse instanceof Hashtable) {
        Hashtable table = (Hashtable) xmlRpcResponse;
        if (!table.isEmpty()) {
            checkForErrors(table.get(GreenPepperServerErrorKey.ERROR));
        }
    } else {
        checkErrors(xmlRpcResponse);
    }
}