Refine search
function Foo() {} var foo = new Foo(); typeof Foo; // == "function" typeof foo; // == "object" foo instanceof Foo; // == true foo.constructor.name; // == "Foo" Foo.name // == "Foo" Foo.prototype.isPrototypeOf(foo); // == true Foo.prototype.bar = function (x) {return x+x;}; foo.bar(21); // == 42
public class Main{ public static void main(String[] args){ Foo f = new Foo("f"); changeReference(f); // It won't change the reference! modifyReference(f); // It will modify the object that the reference variable "f" refers to! } public static void changeReference(Foo a){ Foo b = new Foo("b"); a = b; } public static void modifyReference(Foo c){ c.setAttribute("c"); } }
public void testEmptyFooInner() throws Exception { Bar bar = new Bar(); Foo foo = new Foo(); ArrayList<Bar> bars = new ArrayList<Bar>(); bars.add(bar); foo.setSomeBar(bars); byte[] output = toByteArray(foo); Foo parsedFoo = new Foo(); mergeFrom(output, 0, output.length, parsedFoo, parsedFoo.cachedSchema()); }
public void testFooNullFields() throws Exception { Foo b = new Foo(); JsonIOUtil.mergeFrom(JsonIOUtil.DEFAULT_JSON_FACTORY.createJsonParser( "{\"someInt\":[null]" + ",\"someString\":[null]" + ",\"someBar\":[null]" + ",\"someEnum\":[null]" + ",\"someBytes\":[null]" + ",\"someBoolean\":[null]" + ",\"someFloat\":[null]" + ",\"someDouble\":[null]" + ",\"someLong\":[null]}"), b, b.cachedSchema(), false); assertNull(b.getSomeInt()); assertNull(b.getSomeString()); assertNull(b.getSomeBar()); assertNull(b.getSomeEnum()); assertNull(b.getSomeBytes()); assertNull(b.getSomeBoolean()); assertNull(b.getSomeFloat()); assertNull(b.getSomeDouble()); assertNull(b.getSomeLong()); }
final CustomSchema<Bar> barSchema = new CustomSchema<Bar>(bar.cachedSchema()) baz.setId(1); baz.setName("baz"); final Bar bar = new Bar(); bar.setSomeBaz(baz); bar.setSomeInt(2); bar.setSomeString("bar"); Foo foo = new Foo(); mergeFrom(coded, 0, coded.length, foo, foo.cachedSchema()); assertTrue(bar.getSomeInt() == foo.getSomeInt().get(0)); assertEquals(bar.getSomeString(), foo.getSomeString().get(0)); assertTrue(bar.getSomeDouble() == foo.getSomeDouble().get(0)); assertTrue(bar.getSomeFloat() == foo.getSomeFloat().get(0));
public void testFoo() throws Exception { Bar bar = new Bar(); bar.setSomeInt(1); bar.setSomeBytes(ByteString.copyFromUtf8(ESCAPE_TARGET)); bar.setSomeString(ESCAPE_TARGET); ArrayList<Bar> bars = new ArrayList<Bar>(); bars.add(bar); bars.add(bar); ArrayList<String> strings = new ArrayList<String>(); strings.add(ESCAPE_TARGET); strings.add(""); strings.add(ESCAPE_TARGET); Foo foo = new Foo(); foo.setSomeBar(bars); foo.setSomeString(strings); byte[] protostuff = ProtostuffIOUtil.toByteArray(foo, foo.cachedSchema(), buf()); byte[] json = JsonIOUtil.toByteArray(ProtostuffIOUtil.newPipe(protostuff), Foo.getPipeSchema(), false); byte[] json2 = JsonXIOUtil.toByteArray(ProtostuffIOUtil.newPipe(protostuff), Foo.getPipeSchema(), false, buf()); assertTrue(json.length == json2.length); String strJson = STRING.deser(json); String strJson2 = STRING.deser(json2); assertEquals(strJson, strJson2); System.err.println(strJson); System.err.println(strJson2); }
public void testEmptyFoo() throws Exception { Foo foo = new Foo(); byte[] output = toByteArray(foo); Foo parsedFoo = new Foo(); mergeFrom(output, 0, output.length, parsedFoo, parsedFoo.cachedSchema()); }
public void testFoo() throws Exception { Foo foo = SerializableObjects.foo; protobufRoundTrip(foo, Foo.getSchema(), Foo.getPipeSchema()); protostuffRoundTrip(foo, Foo.getSchema(), Foo.getPipeSchema()); }
static Foo newFoo() { // one-instance of Baz. Baz baz = new Baz(); baz.setId(100); Bar bar1 = new Bar(); bar1.setSomeInt(1); bar1.setSomeBaz(baz); Bar bar2 = new Bar(); bar2.setSomeInt(2); bar2.setSomeBaz(baz); ArrayList<Bar> bars = new ArrayList<Bar>(); bars.add(bar1); bars.add(bar2); Foo foo = new Foo(); foo.setSomeBar(bars); return foo; }
public void testJavaSerializableEmptyFooInner() throws Exception { ArrayList<Bar> bars = new ArrayList<Bar>(); Bar bar = new Bar(); bar.setSomeBaz(new Baz()); bars.add(bar); Foo foo = new Foo(); ByteArrayOutputStream out = new ByteArrayOutputStream(); ObjectOutputStream oout = new ObjectOutputStream(out); oout.writeObject(foo); byte[] coded = out.toByteArray(); ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(coded)); Foo parsedFoo = (Foo) in.readObject(); SerializableObjects.assertEquals(parsedFoo, foo); }
public void testReference() throws Exception { Foo fooCompare = newFoo(); // verify checkReference(fooCompare); byte[] data = toByteArray(fooCompare, Foo.getSchema()); // from byte array Foo fooFromByteArray = new Foo(); mergeFrom(data, 0, data.length, fooFromByteArray, Foo.getSchema()); SerializableObjects.assertEquals(fooCompare, fooFromByteArray); // verify parsed message checkReference(fooFromByteArray); // from inputstream Foo fooFromStream = new Foo(); ByteArrayInputStream in = new ByteArrayInputStream(data); mergeFrom(in, fooFromStream, Foo.getSchema()); SerializableObjects.assertEquals(fooCompare, fooFromStream); // verify parsed message checkReference(fooFromStream); }
public static void main(String[] args) { final Foo f = new Foo(); final Bar b = new Bar(); new Thread(new Runnable() { public void run() { f.doSomethingWithBar(b); } }).start(); new Thread(new Runnable() { public void run() { b.doSomethingWithFoo(f); } }).start(); }
public void testFoo() throws Exception { Schema<Foo> schema = Foo.getSchema(); Foo message = foo; byte[] data = XmlXIOUtil.toByteArray(message, schema, buf()); ByteArrayOutputStream out = new ByteArrayOutputStream(); XmlXIOUtil.writeTo(out, message, schema, buf()); assertTrue(Arrays.equals(data, out.toByteArray())); }
public void testEmptyList() throws Exception { ArrayList<Foo> foos = new ArrayList<Foo>(); ByteArrayOutputStream out = new ByteArrayOutputStream(); final int bytesWritten = writeListTo(out, foos, SerializableObjects.foo.cachedSchema()); assertEquals(0, bytesWritten); byte[] data = out.toByteArray(); ByteArrayInputStream in = new ByteArrayInputStream(data); List<Foo> parsedFoos = parseListFrom(in, SerializableObjects.foo.cachedSchema()); assertTrue(parsedFoos.size() == foos.size()); int i = 0; for (Foo f : parsedFoos) SerializableObjects.assertEquals(foos.get(i++), f); }
static void checkReference(Foo foo) { Bar bar1 = foo.getSomeBar().get(0); assertNotNull(bar1); assert (bar1.getSomeInt() == 1); Bar bar2 = foo.getSomeBar().get(1); assertNotNull(bar2); assert (bar2.getSomeInt() == 2); // check if its same instance assertTrue(bar1.getSomeBaz() == bar2.getSomeBaz()); }