@Override public void encode(final BsonWriter writer, final Code value, final EncoderContext encoderContext) { writer.writeJavaScript(value.getCode()); }
@Override public Code decode(final BsonReader bsonReader, final DecoderContext decoderContext) { return new Code(bsonReader.readJavaScript()); }
@Override public boolean equals(final Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } if (!super.equals(o)) { return false; } CodeWithScope that = (CodeWithScope) o; if (scope != null ? !scope.equals(that.scope) : that.scope != null) { return false; } return true; }
/** * Tests if {@code JavaScript} objects can be deserialized * @throws Exception if something goes wrong */ @Test public void javascript() throws Exception { Code code = new Code("code"); TC.J obj = generateAndParse(code, TC.J.class); assertEquals(code.getCode(), obj.obj.getCode()); CodeWScope codews = new CodeWScope("code", new BasicBSONObject("key", "value")); obj = generateAndParse(codews, TC.J.class); assertEquals(code.getCode(), obj.obj.getCode()); assertEquals(codews.getScope().toMap(), obj.obj.getScope()); }
Code code = new Code(); code.setA((byte) 'a'); code.setB((byte) 'b'); ... JNATest.printStruct(code.getPointer()); code.free(); // free the memory allocated in the constructor
private String playerName = ""; private int numberOfPegs = 0; private boolean gameRunning = "True"; private Display display; public static void main(String[] args) { Game game = new Game(); game.setupGame(); game.playGame(); } public void setupGame() { display = new Display(); Code code = new Code(); display.showGreeting(); playerName = display.getUserInput("Enter your name: "); numberOfPegs = Integer.parseInt(display.getUserInput("How many pegs would you like?")); code.generateNewCode(numberOfPegs); } public void playGame() { String result = display.getGuess(); }
@Override public void gotCode(final String name, final String code) { _put(name, new Code(code)); }
@Override public void serialize(final Object obj, final StringBuilder buf) { Code c = (Code) obj; BasicDBObject temp = new BasicDBObject(); temp.put("$code", c.getCode()); serializer.serialize(temp, buf); }
@Override public Document convert(NamedMongoScript source) { if (source == null) { return new Document(); } Document document = new Document(); document.put("_id", source.getName()); document.put("value", new Code(source.getCode())); return document; } }
/** * Encodes a field to a {@link org.bson.BsonType#JAVASCRIPT} value. * * @param name the field name * @param code the value */ protected void putCode(final String name, final Code code) { putName(name); bsonWriter.writeJavaScript(code.getCode()); }
putCode(name, new Code((String) initialValue));
@Override public NamedMongoScript convert(Document source) { if (source == null) { return null; } String id = source.get("_id").toString(); Object rawValue = source.get("value"); return new NamedMongoScript(id, ((Code) rawValue).getCode()); } }
o = new CodeWScope((String) b.get("$code"), (DBObject) b.get("$scope")); } else { o = new Code((String) b.get("$code"));
@Override public NamedMongoScript convert(Document source) { if (source == null) { return null; } String id = source.get("_id").toString(); Object rawValue = source.get("value"); return new NamedMongoScript(id, ((Code) rawValue).getCode()); } }
@Override public Document convert(NamedMongoScript source) { if (source == null) { return new Document(); } Document document = new Document(); document.put("_id", source.getName()); document.put("value", new Code(source.getCode())); return document; } }
@Override public String toString() { return getCode(); }
return callback.createDBRef(dbPointer.getNamespace(), dbPointer.getId()); case JAVASCRIPT: return new Code(reader.readJavaScript()); case SYMBOL: return new Symbol(reader.readSymbol());
@Override public void serialize(final Object obj, final StringBuilder buf) { Code c = (Code) obj; BasicDBObject temp = new BasicDBObject(); temp.put("$code", c.getCode()); serializer.serialize(temp, buf); }
if (O[ID].code == null) { O[ID].code = new Code(); // <-- you didn't tell us. } // Then you could O[ID].code.MapFile = new short[data.length / 4][4];