@Override public Void visit(BsonJavaScriptWithScope value, ByteBuf arg) { final int codeWsStart = arg.writerIndex(); arg.writeInt(0); // reserve space for code_w_s size writeString(arg, value.getJavaScript()); value.getScope().accept(VISITOR, arg); final int codeWsEnds = arg.writerIndex(); arg.writerIndex(codeWsStart).writeInt(codeWsEnds - codeWsStart).writerIndex(codeWsEnds); return null; }
@Override public KVValue visit(BsonJavaScriptWithScope value, Void arg) { throw new UnsupportedBsonTypeException(value.getType()); }
@Override public int compareTo(BsonValue<?> obj) { if (obj == this) { return 0; } int diff = BsonTypeComparator.INSTANCE.compare(getType(), obj.getType()); if (diff != 0) { return diff; } assert obj.isJavaScriptWithScope(); BsonJavaScriptWithScope other = obj.asJavaScriptWithScope(); //TODO: Check how MongoDB compares js with scope! diff = this.getValue().compareTo(other.getValue()); if (diff != 0) { return diff; } return this.getScope().compareTo(other.getScope()); }
@Override public final boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!(obj instanceof BsonJavaScriptWithScope)) { return false; } BsonJavaScriptWithScope other = (BsonJavaScriptWithScope) obj; if (!this.getJavaScript().equals(other.getJavaScript())) { return false; } return this.getScope().equals(other.getScope()); }
com.eightkdata.mongowp.bson.BsonJavaScriptWithScope casted = (com.eightkdata.mongowp.bson.BsonJavaScriptWithScope) value; return new BsonJavaScriptWithScope(casted.getJavaScript(), translate(casted.getScope()));