All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.permazen.encoding.IntegerEncoding Maven / Gradle / Ivy

The newest version!

/*
 * Copyright (C) 2015 Archie L. Cobbs. All rights reserved.
 */

package io.permazen.encoding;

import org.dellroad.stuff.java.Primitive;

/**
 * {@code int} primitive type.
 */
public class IntegerEncoding extends IntegralEncoding {

    private static final long serialVersionUID = 1978611631822982974L;

    public IntegerEncoding(EncodingId encodingId) {
       super(encodingId, Primitive.INTEGER);
    }

    @Override
    protected Integer convertNumber(Number value) {
        return value.intValue();
    }

    @Override
    protected Integer downCast(long value) {
        return (int)value;
    }

    @Override
    public Integer validate(Object obj) {
        if (obj instanceof Character)
            return (int)(Character)obj;
        if (obj instanceof Byte || obj instanceof Short)
            return ((Number)obj).intValue();
        return super.validate(obj);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy