mockit.internal.util.DefaultValues Maven / Gradle / Ivy
/*
* Copyright (c) 2006-2012 Rogério Liesenfeld
* This file is subject to the terms of the MIT license (see LICENSE.txt).
*/
package mockit.internal.util;
import java.lang.reflect.*;
import java.util.*;
import mockit.external.asm4.Type;
import static java.util.Collections.*;
/**
* Provides default values for each type, typically used for returning default values according to
* method return types.
*/
@SuppressWarnings("ZeroLengthArrayAllocation")
public final class DefaultValues
{
private DefaultValues() {}
private static final Integer ZERO_INT = 0;
private static final Long ZERO_LONG = 0L;
private static final Float ZERO_FLOAT = 0.0F;
private static final Double ZERO_DOUBLE = 0.0;
private static final Byte ZERO_BYTE = 0;
private static final Short ZERO_SHORT = 0;
private static final Character ZERO_CHAR = '\0';
private static final Map TYPE_DESC_TO_VALUE_MAP = new HashMap();
private static final Map ELEM_TYPE_TO_ONE_D_ARRAY = new HashMap();
static {
TYPE_DESC_TO_VALUE_MAP.put("Z", Boolean.FALSE);
TYPE_DESC_TO_VALUE_MAP.put("C", ZERO_CHAR);
TYPE_DESC_TO_VALUE_MAP.put("B", ZERO_BYTE);
TYPE_DESC_TO_VALUE_MAP.put("S", ZERO_SHORT);
TYPE_DESC_TO_VALUE_MAP.put("I", ZERO_INT);
TYPE_DESC_TO_VALUE_MAP.put("F", ZERO_FLOAT);
TYPE_DESC_TO_VALUE_MAP.put("J", ZERO_LONG);
TYPE_DESC_TO_VALUE_MAP.put("D", ZERO_DOUBLE);
TYPE_DESC_TO_VALUE_MAP.put("Ljava/util/Enumeration;", enumeration(emptyList()));
TYPE_DESC_TO_VALUE_MAP.put("Ljava/util/Collection;", emptyList());
TYPE_DESC_TO_VALUE_MAP.put("Ljava/util/List;", emptyList());
TYPE_DESC_TO_VALUE_MAP.put("Ljava/util/Set;", emptySet());
TYPE_DESC_TO_VALUE_MAP.put("Ljava/util/SortedSet;", unmodifiableSortedSet(new TreeSet