public class DateTypeAdapter extends BaseLongTypeAdapter<Date> {

    @Override
    public Long getDefaultValue() {
        return Long.MIN_VALUE;
    }

    @Override
    public Long adaptForPreferences(@Nullable Date value) {
        if (value == null) {
            return Long.MIN_VALUE;
        }
        
        return value.getTime();
    }

    @Nullable
    @Override
    public Date adaptFromPreferences(Long value) {
        if (value == Long.MIN_VALUE) {
            return null;
        }
        
        return new Date(value);
    }
} public class DoubleTypeAdapter extends BaseLongTypeAdapter<Double> {

    @Override
    public Long adaptForPreferences(Double value) {
        return Double.doubleToRawLongBits(value);
    }

    @Override
    public Double adaptFromPreferences(Long value) {
        return Double.longBitsToDouble(value);
    }
} public class EnumTypeAdapter extends BaseStringTypeAdapter<Enum> {
    
    private final Class<? extends Enum> type;
    
    public EnumTypeAdapter(Class<? extends Enum> type) {
        this.type = type;
    }

    @Nullable
    @Override
    public String adaptForPreferences(@Nullable Enum value) {
        if (value == null) {
            return null;
        }
        
        return value.name();
    }

    @Nullable
    @Override
    public Enum adaptFromPreferences(@Nullable String value) {
        if (value == null) {
            return null;
        }
        
        return Enum.valueOf(type, value);
    }
} public interface StoreBoxTypeAdapter<F, T> {
    
    StoreType getStoreType();
    
    T getDefaultValue();

    T adaptForPreferences(F value);

    F adaptFromPreferences(T value);
} public class BooleanTypeAdapter extends BaseBooleanTypeAdapter<Boolean> {
    
    @Override
    public Boolean adaptForPreferences(Boolean value) {
        return value;
    }

    @Override
    public Boolean adaptFromPreferences(Boolean value) {
        return value;
    }
} public class FloatTypeAdapter extends BaseFloatTypeAdapter<Float> {

    @Override
    public Float adaptForPreferences(Float value) {
        return value;
    }

    @Override
    public Float adaptFromPreferences(Float value) {
        return value;
    }
} public class IntegerTypeAdapter extends BaseIntegerTypeAdapter<Integer> {
    
    @Override
    public Integer adaptForPreferences(Integer value) {
        return value;
    }

    @Override
    public Integer adaptFromPreferences(Integer value) {
        return value;
    }
} public class LongTypeAdapter extends BaseLongTypeAdapter<Long> {

    @Override
    public Long adaptForPreferences(Long value) {
        return value;
    }

    @Override
    public Long adaptFromPreferences(Long value) {
        return value;
    }
} public class StringSetTypeAdapter extends
        BaseStringSetTypeAdapter<Set<String>> {

    @Override
    public Set<String> adaptForPreferences(Set<String> value) {
        return value;
    }

    @Override
    public Set<String> adaptFromPreferences(Set<String> value) {
        return value;
    }
} public class StringTypeAdapter extends BaseStringTypeAdapter<String> {

    @Override
    public String adaptForPreferences(String value) {
        return value;
    }

    @Override
    public String adaptFromPreferences(String value) {
        return value;
    }
} public class UriTypeAdapter extends BaseStringTypeAdapter<Uri> {

    @Nullable
    @Override
    public String adaptForPreferences(@Nullable Uri value) {
        if (value == null) {
            return null;
        }
        
        return value.toString();
    }

    @Nullable
    @Override
    public Uri adaptFromPreferences(@Nullable String value) {
        if (value == null) {
            return null;
        }
        
        return Uri.parse(value);
    }
}
import android.net.Uri;
import net.orange_box.storebox.adapters.extra.DateTypeAdapter;
import net.orange_box.storebox.adapters.extra.DoubleTypeAdapter;
import net.orange_box.storebox.adapters.extra.EnumTypeAdapter;
import net.orange_box.storebox.adapters.StoreBoxTypeAdapter;
import net.orange_box.storebox.adapters.standard.BooleanTypeAdapter;
import net.orange_box.storebox.adapters.standard.FloatTypeAdapter;
import net.orange_box.storebox.adapters.standard.IntegerTypeAdapter;
import net.orange_box.storebox.adapters.standard.LongTypeAdapter;
import net.orange_box.storebox.adapters.standard.StringSetTypeAdapter;
import net.orange_box.storebox.adapters.standard.StringTypeAdapter;
import net.orange_box.storebox.adapters.extra.UriTypeAdapter;
import net.orange_box.storebox.annotations.method.TypeAdapter;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
/*
 * Copyright 2015 Martin Bella
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.orange_box.storebox.utils;




public final class TypeUtils {
    
    private static final Map<Class<?>, Class<?>> PRIMITIVE_TO_BOXED_MAP;
    static {
        final Map<Class<?>, Class<?>> map = new HashMap<>(5);
        // standard
        map.put(boolean.class, Boolean.class);
        map.put(float.class, Float.class);
        map.put(int.class, Integer.class);
        map.put(long.class, Long.class);
        // extra
        map.put(double.class, Double.class);
        
        PRIMITIVE_TO_BOXED_MAP = map;
    }
    
    private static final Map<Class<?>, StoreBoxTypeAdapter> ADAPTERS_MAP;
    static {
        final Map<Class<?>, StoreBoxTypeAdapter> map =
                new ConcurrentHashMap<>(9);
        
        // standard
        map.put(Boolean.class, new BooleanTypeAdapter());
        map.put(Float.class, new FloatTypeAdapter());
        map.put(Integer.class, new IntegerTypeAdapter());
        map.put(Long.class, new LongTypeAdapter());
        map.put(String.class, new StringTypeAdapter());
        map.put(Set.class, new StringSetTypeAdapter());
        
        // extra
        map.put(Date.class, new DateTypeAdapter());