mirror of
https://github.com/valitydev/geck.git
synced 2024-11-06 09:45:24 +00:00
BJ-76: Add byteStack, double value
This commit is contained in:
parent
a8d3f6c2d9
commit
d73a1f12ad
59
src/main/java/com/rbkmoney/kebab/ByteStack.java
Normal file
59
src/main/java/com/rbkmoney/kebab/ByteStack.java
Normal file
@ -0,0 +1,59 @@
|
||||
package com.rbkmoney.kebab;
|
||||
|
||||
/**
|
||||
* Created by vpankrashkin on 31.01.17.
|
||||
*/
|
||||
public class ByteStack {
|
||||
private byte[] stack;
|
||||
private int size;
|
||||
|
||||
|
||||
public ByteStack(final int initialCapacity) {
|
||||
if (initialCapacity <= 0) {
|
||||
throw new IllegalArgumentException("Size must be > 0");
|
||||
}
|
||||
this.stack = new byte[initialCapacity];
|
||||
this.size = 0;
|
||||
}
|
||||
|
||||
public ByteStack() {
|
||||
this(10);
|
||||
}
|
||||
|
||||
public final void push(final byte item) {
|
||||
if (size == stack.length) {
|
||||
byte[] newStack = new byte[size << 1];
|
||||
for (int i = 0; i < stack.length; ++i) {
|
||||
newStack[i] = stack[i];
|
||||
}
|
||||
stack = newStack;
|
||||
}
|
||||
stack[size++] = item;
|
||||
}
|
||||
|
||||
|
||||
public final byte pop() {
|
||||
if (size == 0) {
|
||||
throw new RuntimeException("No more elements");
|
||||
}
|
||||
return stack[--size];
|
||||
}
|
||||
|
||||
public final byte peek() {
|
||||
if (size == 0) {
|
||||
throw new RuntimeException("No more elements");
|
||||
}
|
||||
return stack[size];
|
||||
}
|
||||
|
||||
public final int size() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public final boolean isEmpty() {
|
||||
return size == 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -64,6 +64,9 @@ public class TBaseSerializer implements Serializer<TBase> {
|
||||
case LONG:
|
||||
out.value((long) object);
|
||||
break;
|
||||
case DOUBLE:
|
||||
out.value((double) object);
|
||||
break;
|
||||
case LIST:
|
||||
write(out, (List) object, (ListMetaData) fieldValueMetaData);
|
||||
break;
|
||||
|
@ -4,7 +4,6 @@ import com.rbkmoney.kebab.test.Fail;
|
||||
import com.rbkmoney.kebab.test.Ids;
|
||||
import com.rbkmoney.kebab.test.Status;
|
||||
import com.rbkmoney.kebab.test.TestObject;
|
||||
import com.rbkmoney.kebab.thrift.ThriftElement;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.*;
|
||||
|
Loading…
Reference in New Issue
Block a user