/**
  * Create an instance of Credential class.
  *
  * @param usernameOrEmail Username or e-mail.
  * @param password Password.
  * @param consumerKey Consumer key.
  * @param consumerSecret Consumer secret.
  * @throws IllegalArgumentException If any parameter is empty or null.
  */
 public Credential(
     String usernameOrEmail, String password, String consumerKey, String consumerSecret) {
   if (StringUtil.isEmpty(usernameOrEmail)) {
     throw new IllegalArgumentException("Username or e-mail must not be empty/null");
   }
   if (StringUtil.isEmpty(password)) {
     throw new IllegalArgumentException("Password must not be empty/null");
   }
   if (StringUtil.isEmpty(consumerKey)) {
     throw new IllegalArgumentException("Consumer Key must not be empty/null");
   }
   if (StringUtil.isEmpty(consumerSecret)) {
     throw new IllegalArgumentException("Consumer Secret must not be empty/null");
   }
   //
   Hashtable credtls = new Hashtable(4);
   //
   if (usernameOrEmail.indexOf('@') != -1) { // is e-mail?
     credtls.put(MetadataSet.CREDENTIAL_EMAIL, usernameOrEmail);
   } else {
     credtls.put(MetadataSet.CREDENTIAL_USERNAME, usernameOrEmail);
   }
   credtls.put(MetadataSet.CREDENTIAL_PASSWORD, password);
   credtls.put(MetadataSet.CREDENTIAL_CONSUMER_KEY, consumerKey);
   credtls.put(MetadataSet.CREDENTIAL_CONSUMER_SECRET, consumerSecret);
   //
   setData(credtls);
 }
 /**
  * Perform an analyze of a given HttpResponse object's response-code in order to interpret whether
  * the requests to Twitter API went well. Otherwise, an exception is thrown describing the
  * problem.
  *
  * @param response HttpResponse object to be interpreted.
  * @throws IOException If an I/O or service error occurs.
  * @throws LimitExceededException If a request limit exceeded error occurs.
  * @throws InvalidQueryException If an invalid query error occurs.
  * @throws SecurityException If a security error occurs.
  * @throws IllegalArgumentException If response is null.
  */
 public static void perform(HttpResponse response) throws IOException, LimitExceededException {
   if (response == null) {
     throw new IllegalArgumentException("Response must not be null.");
   }
   //
   final int respCode = response.getCode();
   //
   if (respCode != HttpConnection.HTTP_OK && respCode != HttpConnection.HTTP_NOT_MODIFIED) {
     if (isInvalidQueryError(respCode)) {
       throw new InvalidQueryException(getErrorMessage(response));
     } else if (isLimitExceededError(respCode)) {
       String emgs = getErrorMessage(response);
       String raft = response.getResponseField("X-Rate-Limit-Reset");
       //
       if (!StringUtil.isEmpty(raft)) {
         emgs += " / Retry after " + raft + " secs.";
       }
       //
       throw new LimitExceededException(emgs);
     } else if (isSecurityError(respCode)) {
       throw new SecurityException(getErrorMessage(response));
     } else {
       throw new IOException(getErrorMessage(response));
     }
   }
 }
 /**
  * Replace the key of a given property.
  *
  * @param hashtable Hastable.
  * @param searchKey Key to be replaced.
  * @param replacementKey Replacement key.
  */
 protected void replaceProperty(Hashtable hashtable, String searchKey, String replacementKey) {
   Object value = hashtable.get(searchKey);
   //
   if (value != null) {
     hashtable.remove(searchKey);
     //
     if (value instanceof String) {
       String str = value.toString();
       //
       if (StringUtil.isEmpty(str) || "null".equals(str)) {
         return;
       }
     }
     //
     hashtable.put(replacementKey, value);
   }
 }
 /**
  * Verify whether the given string is null, empty or "null".
  *
  * @param str The string.
  * @return true null/empty/"null".
  */
 protected boolean isEmpty(String str) {
   return StringUtil.isEmpty(str) || "null".equals(str.trim());
 }
 /**
  * Checks if the value associated to the is null or empty.
  *
  * @param key Key.
  * @return Empty (true).
  */
 public boolean isEmpty(String key) {
   Object v = data.get(key);
   //
   return v == null || StringUtil.isEmpty(v.toString());
 }