content: package net.amygdalum.testrecorder.deserializers.matcher;
  
  import static java.util.Collections.emptyList;
  import static net.amygdalum.testrecorder.deserializers.Templates.equalToMatcher;
  import static net.amygdalum.testrecorder.deserializers.Templates.newObject;
  import static net.amygdalum.testrecorder.types.Computation.expression;
  import static net.amygdalum.testrecorder.util.Literals.asLiteral;
  import static net.amygdalum.testrecorder.util.Types.equalBaseTypes;
  import static net.amygdalum.testrecorder.util.Types.parameterized;
  
  import java.lang.reflect.Type;
  import java.math.BigDecimal;
  
  import org.hamcrest.CoreMatchers;
  import org.hamcrest.Matcher;
  
  import net.amygdalum.testrecorder.deserializers.Deserializer;
  import net.amygdalum.testrecorder.types.Computation;
  import net.amygdalum.testrecorder.types.DeserializerContext;
  import net.amygdalum.testrecorder.types.TypeManager;
  import net.amygdalum.testrecorder.values.SerializedImmutable;
  
  public class DefaultBigDecimalAdaptor extends DefaultMatcherGenerator<SerializedImmutable<BigDecimal>> implements MatcherGenerator<SerializedImmutable<BigDecimal>> {
  
  	@SuppressWarnings("rawtypes")
  	@Override
  	public Class<SerializedImmutable> getAdaptedClass() {
  		return SerializedImmutable.class;
  	}
  
  	@Override
  	public boolean matches(Type type) {
  		return equalBaseTypes(type, BigDecimal.class);
  	}
  
  	@Override
  	public Computation tryDeserialize(SerializedImmutable<BigDecimal> value, Deserializer generator) {
  		DeserializerContext context = generator.getContext();
  		TypeManager types = context.getTypes();
  		types.registerImport(BigDecimal.class);
  		types.staticImport(CoreMatchers.class, "equalTo");
  
  		String literal = asLiteral(value.getValue().toPlainString());
  
  		String bigDecimalLiteral = newObject("BigDecimal", literal);
  
  		String equalToMatcher = equalToMatcher(bigDecimalLiteral);
  		return expression(equalToMatcher, parameterized(Matcher.class, null, value.getType()), emptyList());
  	}
  
  }
  