private boolean equals(MsgPackToken x, MsgPackToken y) { if (x.getType() == MsgPackType.NIL || y.getType() == MsgPackType.NIL) { return x.getType() == y.getType(); } else { ensureSameType(x, y); switch (x.getType()) { case STRING: return BufferUtil.equals(x.getValueBuffer(), y.getValueBuffer()); case BOOLEAN: return x.getBooleanValue() == y.getBooleanValue(); case INTEGER: return x.getIntegerValue() == y.getIntegerValue(); case FLOAT: return x.getFloatValue() == y.getFloatValue(); default: throw new JsonConditionException( String.format("Cannot compare value of type: %s", x.getType())); } } }
private void ensureSameType(MsgPackToken x, MsgPackToken y) { // transform number types for comparison if (x.getType() == MsgPackType.INTEGER && y.getType() == MsgPackType.FLOAT) { x.setType(MsgPackType.FLOAT); x.setValue((double) x.getIntegerValue()); } else if (x.getType() == MsgPackType.FLOAT && y.getType() == MsgPackType.INTEGER) { y.setType(MsgPackType.FLOAT); y.setValue((double) y.getIntegerValue()); } else if (x.getType() != y.getType()) { throw new JsonConditionException( String.format( "Cannot compare values of different types: %s and %s", x.getType(), y.getType())); } }
private boolean lessThanOrEqual(MsgPackToken x, MsgPackToken y) { ensureSameType(x, y); ensureNumber(x); if (x.getType() == MsgPackType.INTEGER) { return x.getIntegerValue() <= y.getIntegerValue(); } else { return x.getFloatValue() <= y.getFloatValue(); } }
public DirectBuffer getString() { if (!isString()) { throw new RuntimeException( String.format("expected String but found '%s'", token.getType())); } return token.getValueBuffer(); }
token.setType(MsgPackType.INTEGER); token.setValue(readInteger()); break; case FLOAT: token.setType(MsgPackType.FLOAT); token.setValue(readFloat()); break; case BOOLEAN: token.setType(MsgPackType.BOOLEAN); token.setValue(readBoolean()); break; case MAP: token.setType(MsgPackType.MAP); token.setMapHeader(readMapHeader()); break; case ARRAY: token.setType(MsgPackType.ARRAY); token.setArrayHeader(readArrayHeader()); break; case NIL: token.setType(MsgPackType.NIL); skipValue(); break; case BINARY: token.setType(MsgPackType.BINARY); final int binaryLength = readBinaryLength(); token.setValue(buffer, offset, binaryLength); skipBytes(binaryLength); break;
public boolean isString() { return token.getType() == MsgPackType.STRING; }
private String parseMapKey(MsgPackToken currentValue) { final DirectBuffer valueBuffer = currentValue.getValueBuffer(); return valueBuffer.getStringWithoutLengthUtf8(0, valueBuffer.capacity()); }
public DirectBuffer getLongAsString() { if (!isLong()) { throw new RuntimeException(String.format("expected Long but found '%s'", token.getType())); } final long key = token.getIntegerValue(); final String converted = String.valueOf(key); longResultBuffer.wrap(converted.getBytes()); return longResultBuffer; } }
final MsgPackType currentValueType = currentValue.getType(); if (MsgPackType.ARRAY == currentValueType || MsgPackType.MAP == currentValueType) { context.appendElement(); context.numElements( currentValueType == MsgPackType.MAP ? currentValue.getSize() * 2 : currentValue.getSize()); context.applyingFilter(-1); context.setIsMap(MsgPackType.MAP == currentValueType); if (currentValue.getType().isScalar()) { addResult(position, currentValue.getTotalLength()); } else { matchingContainer = this.context.size() - 1; addResult( matchingContainerStartPosition, position + currentValue.getTotalLength() - matchingContainerStartPosition); matchingContainer = -1;
private void parseMapValue(TokenParseContext tokenContext, String key, MsgPackToken value) { final String nodeId = msgPackTree.addMapNode(tokenContext.parentNodeId, key); final int mapElements = value.getSize(); if (mapElements > 0) { parsingContextStack.push( new TokenParseContext(ParsingMode.MAP_ENTRY, nodeId, mapElements * 2)); } }
private void parsePrimitiveValue( TokenParseContext tokenContext, String key, int valuePosition, MsgPackToken value) { msgPackTree.addValueNode( tokenContext.parentNodeId, key, documentId, valuePosition, value.getTotalLength()); }
private boolean greaterThan(MsgPackToken x, MsgPackToken y) { ensureSameType(x, y); ensureNumber(x); if (x.getType() == MsgPackType.INTEGER) { return x.getIntegerValue() > y.getIntegerValue(); } else { return x.getFloatValue() > y.getFloatValue(); } }
public DirectBuffer getString() { if (!isString()) { throw new RuntimeException( String.format("expected String but found '%s'", token.getType())); } return token.getValueBuffer(); }
token.setType(MsgPackType.INTEGER); token.setValue(readInteger()); break; case FLOAT: token.setType(MsgPackType.FLOAT); token.setValue(readFloat()); break; case BOOLEAN: token.setType(MsgPackType.BOOLEAN); token.setValue(readBoolean()); break; case MAP: token.setType(MsgPackType.MAP); token.setMapHeader(readMapHeader()); break; case ARRAY: token.setType(MsgPackType.ARRAY); token.setArrayHeader(readArrayHeader()); break; case NIL: token.setType(MsgPackType.NIL); skipValue(); break; case BINARY: token.setType(MsgPackType.BINARY); final int binaryLength = readBinaryLength(); token.setValue(buffer, offset, binaryLength); skipBytes(binaryLength); break;
public boolean isLong() { return token.getType() == MsgPackType.INTEGER; }
private String parseMapKey(MsgPackToken currentValue) { final DirectBuffer valueBuffer = currentValue.getValueBuffer(); return valueBuffer.getStringWithoutLengthUtf8(0, valueBuffer.capacity()); }
public DirectBuffer getLongAsString() { if (!isLong()) { throw new RuntimeException(String.format("expected Long but found '%s'", token.getType())); } final long key = token.getIntegerValue(); final String converted = String.valueOf(key); longResultBuffer.wrap(converted.getBytes()); return longResultBuffer; } }
final MsgPackType currentValueType = currentValue.getType(); if (MsgPackType.ARRAY == currentValueType || MsgPackType.MAP == currentValueType) { context.appendElement(); context.numElements( currentValueType == MsgPackType.MAP ? currentValue.getSize() * 2 : currentValue.getSize()); context.applyingFilter(-1); context.setIsMap(MsgPackType.MAP == currentValueType); if (currentValue.getType().isScalar()) { addResult(position, currentValue.getTotalLength()); } else { matchingContainer = this.context.size() - 1; addResult( matchingContainerStartPosition, position + currentValue.getTotalLength() - matchingContainerStartPosition); matchingContainer = -1;
private void parseArrayValue(TokenParseContext tokenContext, String key, MsgPackToken value) { final String arrayNodeId = msgPackTree.addArrayNode(tokenContext.parentNodeId, key); final int arrayElements = value.getSize(); if (arrayElements > 0) { parsingContextStack.push( new TokenParseContext(ParsingMode.ARRAY_ENTRY, arrayNodeId, arrayElements)); } }
private void parsePrimitiveValue( TokenParseContext tokenContext, String key, int valuePosition, MsgPackToken value) { msgPackTree.addValueNode( tokenContext.parentNodeId, key, documentId, valuePosition, value.getTotalLength()); }