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 android.content.Context;
import android.content.SharedPreferences;
import com.segment.analytics.internal.Utils;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.json.JSONObject;
import static com.segment.analytics.internal.Utils.getSegmentSharedPreferences;
import static com.segment.analytics.internal.Utils.isNullOrEmpty;
/**
* A class that wraps an existing {@link Map} to expose value type functionality. All {@link
* java.util.Map} methods will simply be forwarded to a delegate map. This class is meant to
* subclassed and provide methods to access values in keys.
*
* Library users won't need to create instances of this class, they can use plain old {@link Map}
* instead, and our library will handle serializing them.
*
* 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 instead to get objects of a concrete
* type.
*/
public class ValueMap implements Map {
private final Map delegate;
/**
* Uses reflection to create an instance of a subclass of {@link ValueMap}. The subclass
* must declare a map constructor.
*/
static T createValueMap(Map map, Class clazz) {
try {
Constructor constructor = clazz.getDeclaredConstructor(Map.class);
constructor.setAccessible(true);
return constructor.newInstance(map);
} catch (Exception e) {
throw new AssertionError(
"Could not create instance of " + clazz.getCanonicalName() + ".\n" + e);
}
}
public ValueMap() {
delegate = new LinkedHashMap<>();
}
public ValueMap(int initialCapacity) {
delegate = new LinkedHashMap<>(initialCapacity);
}
public ValueMap(Map map) {
if (map == null) {
throw new IllegalArgumentException("Map must not be null.");
}
this.delegate = map;
}
@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