Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove ValueRef interface
  • Loading branch information
xerial committed Nov 28, 2014
commit 7a94130babfe39637b629e1d473cc3dc2a2ce38e
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,11 @@ public static void readAndWriteFile() throws IOException {
switch(format.getValueType()) {
case NIL:
Value nil = v.get();
nil.isNil(); // true
nil.isNilValue(); // true
System.out.println("read nil");
break;
case BOOLEAN:
boolean b = v.get().asBoolean().toBoolean();
boolean b = v.get().asBooleanValue().toBoolean();
System.out.println("read boolean: " + b);
break;
case INTEGER:
Expand All @@ -206,22 +206,22 @@ public static void readAndWriteFile() throws IOException {
System.out.println("read float: " + d);
break;
case STRING:
String s = v.get().asString().toString();
String s = v.get().asStringValue().toString();
System.out.println("read string: " + s);
break;
case BINARY:
// Message buffer is an efficient byte buffer
MessageBuffer mb = v.get().asBinary().toMessageBuffer();
MessageBuffer mb = v.get().asBinaryValue().toMessageBuffer();
System.out.println("read binary: " + mb.toHexString(0, mb.size()));
break;
case ARRAY:
ArrayValue arr = v.get().asArrayValue();
for(ValueRef a : arr) {
for(Value a : arr) {
System.out.println("read array element: " + a);
}
break;
case EXTENDED:
ExtendedValue ev = v.get().asExtended();
ExtendedValue ev = v.get().asExtendedValue();
int extType = ev.getExtType();
byte[] extValue = ev.toByteArray();
break;
Expand Down
8 changes: 4 additions & 4 deletions msgpack-core/src/main/java/org/msgpack/value/ArrayCursor.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
/**
* Created on 6/16/14.
*/
public interface ArrayCursor extends ValueRef, Iterable<ValueRef> {
public interface ArrayCursor extends Value, Iterable<Value> {
public int size();

public boolean hasNext();
public ValueRef next();
public Value next();
public void skip();

/**
* Skips all of the remaining values
*/
public void skipAll();

public Iterator<ValueRef> iterator();
public Iterator<Value> iterator();

public ArrayValue toValue();
public ArrayValue toImmutable();

}
6 changes: 3 additions & 3 deletions msgpack-core/src/main/java/org/msgpack/value/ArrayValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
* Implementation note: We do not implement List<Value> interface here, because
* we cannot reuse AbstractList and AbstractValue implementations simultaneously since
* Java does not support mixin of classes. Instead, it provides {@link #iterator} or
* {@link #toValueArray()} methods to traverse the array contents.
* {@link #toArray()} methods to traverse the array contents.
*/
public interface ArrayValue extends Value, ArrayCursor {

public Value[] toValueArray();
public Value[] toArray();

public Value get(int index);
public Value apply(int index);

public ArrayValue toValue();
public ArrayValue toImmutable();

}
13 changes: 4 additions & 9 deletions msgpack-core/src/main/java/org/msgpack/value/Cursor.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import java.util.Iterator;

/**
* Cursor for traversing a stream of message-packed values
* Cursor for traversing a stream of message-packed values.
* Returned value might be changed for efficiency. To retrieving an immutable value,
* call {@link org.msgpack.value.Value#toImmutable()} after retrieving a value.
*/
public interface Cursor extends Iterator<Value>, Closeable {

Expand All @@ -16,14 +18,7 @@ public interface Cursor extends Iterator<Value>, Closeable {
public boolean hasNext();

/**
* Returns a reference to the value, then proceeds the cursor.
* The returned reference is valid until {@link #hasNext()} is called.
* @return
*/
public ValueRef nextRef();

/**
* Returns the materialized value of the referenced value, then proceeds the cursor.
* Returns the next value, then proceeds the cursor.
* @return
*/
public Value next();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.msgpack.value;

/**
* Created on 5/30/14.
* ExtendedValue interface
*/
public interface ExtendedValue extends RawValue {
public int getExtType();
public ExtendedValue toValue();
public ExtendedValue toImmutable();
}
4 changes: 2 additions & 2 deletions msgpack-core/src/main/java/org/msgpack/value/FloatValue.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.msgpack.value;

/**
* Created on 5/30/14.
* FloatValue interface
*/
public interface FloatValue extends NumberValue {
FloatValue toValue();
FloatValue toImmutable();
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.msgpack.value;

/**
* Created on 5/30/14.
* IntegerValue interface
*/
public interface IntegerValue extends NumberValue {
IntegerValue toValue();
IntegerValue toImmutable();
}
14 changes: 14 additions & 0 deletions msgpack-core/src/main/java/org/msgpack/value/KeyValuePair.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.msgpack.value;

/**
*
*/
public class KeyValuePair {
public final Value key;
public final Value value;

public KeyValuePair(Value key, Value value) {
this.key = key;
this.value = value;
}
}
14 changes: 6 additions & 8 deletions msgpack-core/src/main/java/org/msgpack/value/MapCursor.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package org.msgpack.value;

import java.util.Iterator;
import java.util.Map;

/**
* Cursor for traversing map value entries. This cursor reports a sequence of key and value pairs.
*/
public interface MapCursor extends ValueRef {
public interface MapCursor extends Value {
public int size();

/**
Expand All @@ -16,20 +14,20 @@ public interface MapCursor extends ValueRef {
public boolean hasNext();

/**
* Retrieves a reference to the next key or value.
* Retrieves the next key and value.
* @return
*/
public ValueRef nextKeyOrValue();
public KeyValuePair next();

/**
* Skips a next key or value
* Skips a next key-value pair
*/
public void skipKeyOrValue();
public void skip();

/**
* Skips all of the remaining keys and values.
*/
public void skipAll();

MapValue toValue();
public MapValue toImmutable();
}
7 changes: 4 additions & 3 deletions msgpack-core/src/main/java/org/msgpack/value/MapValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
import java.util.Map;

/**
* Created on 5/30/14.
* MapValue interface
*/
public interface MapValue extends Value, MapCursor {
public Value[] toKeyValueSeq();
public Value[] toKeyValueArray();
public KeyValuePair[] toArray();
public Map<Value, Value> toMap();

public MapValue toValue();
public MapValue toImmutable();
}
2 changes: 1 addition & 1 deletion msgpack-core/src/main/java/org/msgpack/value/NilValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
* References to values
*/
public interface NilValue extends Value {
NilValue toValue();
NilValue toImmutable();
}
6 changes: 3 additions & 3 deletions msgpack-core/src/main/java/org/msgpack/value/NumberValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.math.BigInteger;

/**
* Created on 5/30/14.
* NumberValue interface
*/
public interface NumberValue extends Value {

Expand Down Expand Up @@ -60,11 +60,11 @@ public interface NumberValue extends Value {
*/
public BigInteger toBigInteger();
/**
* Convert this value into a float value
* Convert this value into a 32-bit float
*/
public float toFloat();
/**
* Convert this value into a double value
* Convert this value into a 64-bit double
*/
public double toDouble();

Expand Down
18 changes: 16 additions & 2 deletions msgpack-core/src/main/java/org/msgpack/value/RawValue.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.msgpack.value;

import org.msgpack.core.MessageStringCodingException;
import org.msgpack.core.buffer.MessageBuffer;

import java.nio.ByteBuffer;
Expand All @@ -9,12 +8,27 @@
* Base type of StringValue, BinaryValue and ExtendedValue
*/
public interface RawValue extends Value {

/**
* Returns byte array representation of this value
* @return
*/
public byte[] toByteArray();

/**
* Returns ByteBuffer representation of this value
* @return
*/
public ByteBuffer toByteBuffer();

/**
* Returns MessageBuffer representation of this value
* @return
*/
public MessageBuffer toMessageBuffer();

@Override
public String toString();

public RawValue toValue();
public RawValue toImmutable();
}
4 changes: 2 additions & 2 deletions msgpack-core/src/main/java/org/msgpack/value/StringValue.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.msgpack.value;

/**
* Created on 5/30/14.
* StringValue interface
*/
public interface StringValue extends RawValue {
public StringValue toValue();
public StringValue toImmutable();
}
56 changes: 53 additions & 3 deletions msgpack-core/src/main/java/org/msgpack/value/Value.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,65 @@
//
package org.msgpack.value;

import org.msgpack.core.MessagePacker;
import org.msgpack.core.MessageTypeException;

import org.msgpack.core.*;
import java.io.IOException;

/**
* Value is a holder of a message-packed value.
* Value is an object representation of a message pack value.
*/
public interface Value extends ValueRef {
public interface Value {

public ValueType getValueType();

public NilValue asNilValue() throws MessageTypeException;
public BooleanValue asBooleanValue() throws MessageTypeException;
public NumberValue asNumberValue() throws MessageTypeException;
public IntegerValue asIntegerValue() throws MessageTypeException;
public FloatValue asFloatValue() throws MessageTypeException;
public BinaryValue asBinaryValue() throws MessageTypeException;
public StringValue asStringValue() throws MessageTypeException;
public RawValue asRawValue() throws MessageTypeException;
public ExtendedValue asExtendedValue() throws MessageTypeException;
public ArrayValue asArrayValue() throws MessageTypeException;
public MapValue asMapValue() throws MessageTypeException;

public boolean isNilValue();
public boolean isBooleanValue();
public boolean isNumberValue();
public boolean isIntegerValue();
public boolean isFloatValue();
public boolean isBinaryValue();
public boolean isStringValue();
public boolean isRawValue();
public boolean isArrayValue();
public boolean isMapValue();
public boolean isExtendedValue();

/**
* Write this value into the specified packer
* @param packer
* @throws IOException
*/
public void writeTo(MessagePacker packer) throws IOException;

/**
* Accepting a visitor
* @param visitor
*/
public void accept(ValueVisitor visitor);

/**
* Create an immutable representation of this value. If this value is already immutable, it returns self
* @return
*/
public Value toImmutable();

/**
* Test whether this value is an immutable or not
* @return true if this value is an immutable object, otherwise false.
*/
public boolean isImmutable();

}
Loading