Android Open Source - gm-httpengine-eclipse G M Http Parameters






From Project

Back to project page gm-httpengine-eclipse.

License

The source code is released under:

MIT License

If you think the Android project gm-httpengine-eclipse listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.gemini.net;
/*w  w w . j a  va  2 s .c o m*/
import java.util.Set;
import java.util.TreeMap;

import org.apache.http.params.HttpParams;

public class GMHttpParameters implements HttpParams {
  private final TreeMap<String, Object>  httpParams;

  public GMHttpParameters() {
    httpParams = new TreeMap<String, Object>();
  }

  public GMHttpParameters(GMHttpParameters other) {
    this.httpParams = new TreeMap<String, Object>(other.httpParams);
  }

  @Override
  public HttpParams copy() {
    GMHttpParameters copy = new GMHttpParameters(this);
    return copy;
  }

  public int size() {
    return httpParams.size();
  }

  @Override
  public boolean getBooleanParameter(String name, boolean defaultValue) {
    Object value = httpParams.get(name);
    Boolean result = defaultValue;
    try {
      result = (Boolean) value;
    } catch (ClassCastException e) {
      result = defaultValue;
    } finally {
      result = result == null ? defaultValue : result;
    }
    return result;
  }

  @Override
  public double getDoubleParameter(String name, double defaultValue) {
    Object value = httpParams.get(name);
    Double result = defaultValue;
    try {
      result = ((Number) value).doubleValue();
    } catch (ClassCastException e) {
      result = defaultValue;
    }
    return result;
  }

  @Override
  public int getIntParameter(String name, int defaultValue) {
    Object value = httpParams.get(name);
    int result = defaultValue;
    try {
      result = ((Number) value).intValue();
    } catch (ClassCastException e) {
      result = defaultValue;
    }
    return result;
  }

  @Override
  public long getLongParameter(String name, long defaultValue) {
    Object value = httpParams.get(name);
    long result = defaultValue;
    try {
      result = ((Number) value).longValue();
    } catch (ClassCastException e) {
      result = defaultValue;
    }
    return result;
  }

  @Override
  public Object getParameter(String name) {
    return httpParams.get(name);
  }

  @Override
  public boolean isParameterFalse(String name) {
    Object value = httpParams.get(name);
    Boolean result = null;
    try {
      result = (Boolean) value;
    } catch (ClassCastException e) {
      result = true;
    }
    return result;
  }

  @Override
  public boolean isParameterTrue(String name) {
    Object value = httpParams.get(name);
    Boolean result = null;
    try {
      result = (Boolean) value;
    } catch (ClassCastException e) {
      result = false;
    }
    return result;
  }

  public String getStringParameter(String name) {
    Object obj = httpParams.get(name);
    return obj != null ? obj.toString() : null;
  }

  @Override
  public boolean removeParameter(String name) {
    return httpParams.remove(name) != null;
  }

  @Override
  public HttpParams setBooleanParameter(String name, boolean value) {
    httpParams.put(name, value);
    return this;
  }

  @Override
  public HttpParams setDoubleParameter(String name, double value) {
    httpParams.put(name, value);
    return this;
  }

  @Override
  public HttpParams setIntParameter(String name, int value) {
    httpParams.put(name, value);
    return this;
  }

  @Override
  public HttpParams setLongParameter(String name, long value) {
    httpParams.put(name, value);
    return this;
  }

  @Override
  public HttpParams setParameter(String name, Object value) {
    httpParams.put(name, value);
    return this;
  }

  public Set<String> getNames() {
    return httpParams.keySet();
  }

  @Override
  public String toString() {
    return httpParams.toString();
  }

}




Java Source Code List

org.gemini.listener.OnProgressUpdateListener.java
org.gemini.listener.OnResponseListener.java
org.gemini.net.GMHttpEngine.java
org.gemini.net.GMHttpParameters.java
org.gemini.net.GMHttpRequest.java
org.gemini.net.GMHttpResponse.java
org.gemini.net.GMHttpService.java
org.gemini.net.GMNetStateManager.java
org.gemini.parser.DefaultHttpRequestParser.java
org.gemini.parser.HttpRequestParser.java
org.gemini.parser.HttpResponseParser.java
org.gemini.util.LOG.java