Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package com.segment.analytics;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.json.JSONObject;
/**
* A {@link Map} wrapper to expose Json functionality. Only the {@link #toString()} method is
* modified to return a json formatted string. All other methods will be forwarded to a delegate
* map.
*
* The purpose of this class is to not limit clients to a custom implementation of a Json type,
* they
* can use existing {@link Map} and {@link java.util.List} implementations as they see fit. It adds
* some utility methods, including methods to coerce numeric types from Strings, and a {@link
* #putValue(String, Object)} to be able to chain method calls.
*
* Although it lets you use custom objects for values, note that type information is lost during
* serialization. You should use one of the coercion methods if you're expecting a type after
* serialization.
*/
class JsonMap implements Map {
private final Map delegate;
JsonMap() {
this.delegate = new LinkedHashMap();
}
JsonMap(Map delegate) {
if (delegate == null) {
throw new IllegalArgumentException("Map must not be null.");
}
if (delegate instanceof JsonMap) {
this.delegate = ((JsonMap) delegate).delegate; // avoid indirection
} else {
this.delegate = delegate;
}
}
JsonMap(String json) {
try {
this.delegate = JsonUtils.jsonToMap(json);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override public void clear() {
delegate.clear();
}
@Override public boolean containsKey(Object key) {
return delegate.containsKey(key);
}
@Override public boolean containsValue(Object value) {
return delegate.containsValue(value);
}
@Override public Set> entrySet() {
return delegate.entrySet();
}
@Override public Object get(Object key) {
return delegate.get(key);
}
@Override public boolean isEmpty() {
return delegate.isEmpty();
}
@Override public Set keySet() {
return delegate.keySet();
}
@Override public Object put(String key, Object value) {
return delegate.put(key, value);
}
@Override public void putAll(Map extends String, ?> map) {
delegate.putAll(map);
}
@Override public Object remove(Object key) {
return delegate.remove(key);
}
@Override public int size() {
return delegate.size();
}
@Override public Collection