save booleans in one byte format

This commit is contained in:
Maxim.Mossienko
2013-08-19 17:07:26 +02:00
parent b7638dc239
commit 287ce0bdc1
2 changed files with 17 additions and 2 deletions
@@ -31,4 +31,8 @@ public class BooleanDataDescriptor extends InlineKeyDescriptor<Boolean> {
public int toInt(Boolean aBoolean) {
return aBoolean == Boolean.TRUE ? 1 : 0;
}
protected boolean isCompactFormat() {
return true;
}
}
@@ -24,6 +24,12 @@ import java.io.DataOutput;
import java.io.IOException;
public abstract class InlineKeyDescriptor<T> implements KeyDescriptor<T> {
private final boolean myCompactFormat = isCompactFormat();
protected boolean isCompactFormat() {
return false;
}
public final int getHashCode(T value) {
return toInt(value);
}
@@ -33,11 +39,16 @@ public abstract class InlineKeyDescriptor<T> implements KeyDescriptor<T> {
}
public final void save(DataOutput out, T value) throws IOException {
out.writeInt(toInt(value));
int v = toInt(value);
if (myCompactFormat) DataInputOutputUtil.writeINT(out, v);
else out.writeInt(v);
}
public final T read(DataInput in) throws IOException {
return fromInt(in.readInt());
int n;
if (myCompactFormat) n = DataInputOutputUtil.readINT(in);
else n = in.readInt();
return fromInt(n);
}
public abstract T fromInt(int n);