Search in sources :

Example 1 with MutableChar

use of com.helger.commons.mutable.MutableChar in project ph-commons by phax.

the class JsonWriterTest method testMutableValues.

@Test
public void testMutableValues() {
    assertEquals("true", JsonConverter.convertToJson(new MutableBoolean(true)).getAsJsonString());
    assertEquals("0", JsonConverter.convertToJson(new MutableByte(0)).getAsJsonString());
    assertEquals("\"\\u0000\"", JsonConverter.convertToJson(new MutableChar('\0')).getAsJsonString());
    assertEquals("3.1234", JsonConverter.convertToJson(new MutableDouble(3.1234D)).getAsJsonString());
    assertEquals("3.1234", JsonConverter.convertToJson(new MutableFloat(3.1234F)).getAsJsonString());
    assertEquals("15", JsonConverter.convertToJson(new MutableInt(15)).getAsJsonString());
    assertEquals("15", JsonConverter.convertToJson(new MutableLong(15L)).getAsJsonString());
    assertEquals("15", JsonConverter.convertToJson(new MutableShort((short) 15)).getAsJsonString());
}
Also used : MutableChar(com.helger.commons.mutable.MutableChar) MutableFloat(com.helger.commons.mutable.MutableFloat) MutableLong(com.helger.commons.mutable.MutableLong) MutableByte(com.helger.commons.mutable.MutableByte) MutableDouble(com.helger.commons.mutable.MutableDouble) MutableBoolean(com.helger.commons.mutable.MutableBoolean) MutableInt(com.helger.commons.mutable.MutableInt) MutableShort(com.helger.commons.mutable.MutableShort) Test(org.junit.Test)

Example 2 with MutableChar

use of com.helger.commons.mutable.MutableChar in project ph-commons by phax.

the class MutableTypeConverterRegistrar method registerTypeConverter.

public void registerTypeConverter(@Nonnull final ITypeConverterRegistry aRegistry) {
    // MutableBigDecimal
    aRegistry.registerTypeConverter(MutableBigDecimal.class, BigDecimal.class, MutableBigDecimal::getAsBigDecimal);
    aRegistry.registerTypeConverter(BigDecimal.class, MutableBigDecimal.class, MutableBigDecimal::new);
    aRegistry.registerTypeConverterRuleFixedSourceAnyDestination(MutableBigDecimal.class, MutableBigDecimal::getAsBigDecimal);
    aRegistry.registerTypeConverterRuleAnySourceFixedDestination(MutableBigDecimal.class, aSource -> new MutableBigDecimal(TypeConverter.convert(aSource, BigDecimal.class)));
    // MutableBigInteger
    aRegistry.registerTypeConverter(MutableBigInteger.class, BigInteger.class, MutableBigInteger::getAsBigInteger);
    aRegistry.registerTypeConverter(BigInteger.class, MutableBigInteger.class, MutableBigInteger::new);
    aRegistry.registerTypeConverterRuleFixedSourceAnyDestination(MutableBigInteger.class, MutableBigInteger::getAsBigInteger);
    aRegistry.registerTypeConverterRuleAnySourceFixedDestination(MutableBigInteger.class, aSource -> new MutableBigInteger(TypeConverter.convert(aSource, BigInteger.class)));
    // MutableBoolean
    aRegistry.registerTypeConverter(MutableBoolean.class, Boolean.class, MutableBoolean::getAsBoolean);
    aRegistry.registerTypeConverter(Boolean.class, MutableBoolean.class, MutableBoolean::new);
    aRegistry.registerTypeConverterRuleFixedSourceAnyDestination(MutableBoolean.class, MutableBoolean::getAsBoolean);
    aRegistry.registerTypeConverterRuleAnySourceFixedDestination(MutableBoolean.class, aSource -> new MutableBoolean(TypeConverter.convert(aSource, Boolean.class)));
    // MutableByte
    aRegistry.registerTypeConverter(MutableByte.class, Byte.class, MutableByte::getAsByte);
    aRegistry.registerTypeConverter(Byte.class, MutableByte.class, MutableByte::new);
    aRegistry.registerTypeConverterRuleFixedSourceAnyDestination(MutableByte.class, MutableByte::getAsByte);
    aRegistry.registerTypeConverterRuleAnySourceFixedDestination(MutableByte.class, aSource -> new MutableByte(TypeConverter.convert(aSource, Byte.class)));
    // MutableChar
    aRegistry.registerTypeConverter(MutableChar.class, Character.class, MutableChar::getAsCharacter);
    aRegistry.registerTypeConverter(Character.class, MutableChar.class, MutableChar::new);
    aRegistry.registerTypeConverterRuleFixedSourceAnyDestination(MutableChar.class, MutableChar::getAsCharacter);
    aRegistry.registerTypeConverterRuleAnySourceFixedDestination(MutableChar.class, aSource -> new MutableChar(TypeConverter.convert(aSource, Character.class)));
    // MutableDouble
    aRegistry.registerTypeConverter(MutableDouble.class, Double.class, MutableDouble::getAsDouble);
    aRegistry.registerTypeConverter(Double.class, MutableDouble.class, MutableDouble::new);
    aRegistry.registerTypeConverterRuleFixedSourceAnyDestination(MutableDouble.class, MutableDouble::getAsDouble);
    aRegistry.registerTypeConverterRuleAnySourceFixedDestination(MutableDouble.class, aSource -> new MutableDouble(TypeConverter.convert(aSource, Double.class)));
    // MutableFloat
    aRegistry.registerTypeConverter(MutableFloat.class, Float.class, MutableFloat::getAsFloat);
    aRegistry.registerTypeConverter(Float.class, MutableFloat.class, MutableFloat::new);
    aRegistry.registerTypeConverterRuleFixedSourceAnyDestination(MutableFloat.class, MutableFloat::getAsFloat);
    aRegistry.registerTypeConverterRuleAnySourceFixedDestination(MutableFloat.class, aSource -> new MutableFloat(TypeConverter.convert(aSource, Float.class)));
    // MutableInt
    aRegistry.registerTypeConverter(MutableInt.class, Integer.class, MutableInt::getAsInteger);
    aRegistry.registerTypeConverter(Integer.class, MutableInt.class, MutableInt::new);
    aRegistry.registerTypeConverterRuleFixedSourceAnyDestination(MutableInt.class, MutableInt::getAsInteger);
    aRegistry.registerTypeConverterRuleAnySourceFixedDestination(MutableInt.class, aSource -> new MutableInt(TypeConverter.convert(aSource, Integer.class)));
    // MutableLong
    aRegistry.registerTypeConverter(MutableLong.class, Long.class, MutableLong::getAsLong);
    aRegistry.registerTypeConverter(Long.class, MutableLong.class, MutableLong::new);
    aRegistry.registerTypeConverterRuleFixedSourceAnyDestination(MutableLong.class, MutableLong::getAsLong);
    aRegistry.registerTypeConverterRuleAnySourceFixedDestination(MutableLong.class, aSource -> new MutableLong(TypeConverter.convert(aSource, Long.class)));
    // MutableShort
    aRegistry.registerTypeConverter(MutableShort.class, Short.class, MutableShort::getAsShort);
    aRegistry.registerTypeConverter(Short.class, MutableShort.class, MutableShort::new);
    aRegistry.registerTypeConverterRuleFixedSourceAnyDestination(MutableShort.class, MutableShort::getAsShort);
    aRegistry.registerTypeConverterRuleAnySourceFixedDestination(MutableShort.class, aSource -> new MutableShort(TypeConverter.convert(aSource, Short.class)));
}
Also used : MutableBigInteger(com.helger.commons.mutable.MutableBigInteger) MutableChar(com.helger.commons.mutable.MutableChar) MutableFloat(com.helger.commons.mutable.MutableFloat) MutableLong(com.helger.commons.mutable.MutableLong) MutableByte(com.helger.commons.mutable.MutableByte) MutableDouble(com.helger.commons.mutable.MutableDouble) MutableBoolean(com.helger.commons.mutable.MutableBoolean) MutableInt(com.helger.commons.mutable.MutableInt) MutableBigDecimal(com.helger.commons.mutable.MutableBigDecimal) MutableShort(com.helger.commons.mutable.MutableShort)

Aggregations

MutableBoolean (com.helger.commons.mutable.MutableBoolean)2 MutableByte (com.helger.commons.mutable.MutableByte)2 MutableChar (com.helger.commons.mutable.MutableChar)2 MutableDouble (com.helger.commons.mutable.MutableDouble)2 MutableFloat (com.helger.commons.mutable.MutableFloat)2 MutableInt (com.helger.commons.mutable.MutableInt)2 MutableLong (com.helger.commons.mutable.MutableLong)2 MutableShort (com.helger.commons.mutable.MutableShort)2 MutableBigDecimal (com.helger.commons.mutable.MutableBigDecimal)1 MutableBigInteger (com.helger.commons.mutable.MutableBigInteger)1 Test (org.junit.Test)1