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

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

The newest version!

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

package io.permazen.encoding;

import com.google.common.base.Preconditions;

import io.permazen.util.ByteReader;
import io.permazen.util.ByteWriter;
import io.permazen.util.UnsignedIntEncoder;

import java.util.OptionalInt;

import org.dellroad.stuff.java.Primitive;

/**
 * Non-null encoding for unsigned {@code int} values in the manner of {@link UnsignedIntEncoder}.
 *
 * 

* This type is internally for encoding various non-negative integer values. */ public class UnsignedIntEncoding extends AbstractEncoding { private static final long serialVersionUID = 4653435311425384497L; // Constructors /** * Constructor. */ public UnsignedIntEncoding() { super(Integer.class); } // Encoding @Override public Integer read(ByteReader reader) { Preconditions.checkArgument(reader != null); return UnsignedIntEncoder.read(reader); } @Override public void write(ByteWriter writer, Integer value) { Preconditions.checkArgument(value != null, "null value"); Preconditions.checkArgument(writer != null); UnsignedIntEncoder.write(writer, value); } @Override public void skip(ByteReader reader) { Preconditions.checkArgument(reader != null); reader.skip(UnsignedIntEncoder.decodeLength(reader.peek())); } @Override public String toString(Integer value) { Preconditions.checkArgument(value != null, "null value"); return String.valueOf(value); } @Override public Integer fromString(String string) { Preconditions.checkArgument(string != null, "null string"); return Primitive.INTEGER.parseValue(string); } @Override public int compare(Integer value1, Integer value2) { return Integer.compare(value1, value2); } @Override public boolean supportsNull() { return false; } @Override public boolean sortsNaturally() { return true; } @Override public boolean hasPrefix0x00() { return true; } @Override public boolean hasPrefix0xff() { return false; } @Override public OptionalInt getFixedWidth() { return OptionalInt.empty(); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy