io.permazen.encoding.IntegerEncoding Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of permazen-encoding Show documentation
Show all versions of permazen-encoding Show documentation
Permazen classes for encoding Java values to/from binary representations.
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