@Test public void testCStruct() { CStructDescriptor descriptor = new CStructDescriptor( null, "test", "Test", ImmutableList.of( new CField(null, 1, PRequirement.OPTIONAL, "first", PPrimitive.STRING.provider(), null, null), new CField(null, 2, PRequirement.OPTIONAL, "second", PPrimitive.STRING.provider(), null, null), new CField(null, 3, PRequirement.OPTIONAL, "third", PPrimitive.STRING.provider(), null, null) ), null); CStructDescriptor d2 = new CStructDescriptor( null, "test", "Test2", ImmutableList.of( new CField(null, 1, PRequirement.OPTIONAL, "first", PPrimitive.STRING.provider(), null, null), new CField(null, 2, PRequirement.OPTIONAL, "second", PPrimitive.STRING.provider(), null, null), new CField(null, 3, PRequirement.OPTIONAL, "third", PPrimitive.STRING.provider(), null, null), new CField(null, 4, PRequirement.OPTIONAL, "msg", () -> descriptor, null, null) ), ImmutableMap.of("nothing", "special")); assertThat(descriptor.isJsonCompactible(), is(false)); CStruct.Builder builder = new CStruct.Builder(descriptor); builder.set(1, "first"); builder.set(2, "second"); assertThat(builder.valid(), is(true)); CStruct struct = builder.build(); builder = new CStruct.Builder(descriptor); builder.set(2, "second"); builder.set(3, "third"); assertThat(builder.valid(), is(true)); CStruct struct2 = builder.build(); assertThat(struct, is(not(struct2))); assertThat(struct, is(not(MessageType.builder().build()))); assertThat(struct.equals(getNull()), is(false)); assertThat(struct.compareTo(d2.builder().build()), is(-1)); assertThat(struct.compareTo(struct2), is(1)); CStruct m1 = d2.builder() .set(4, descriptor.builder().build()) .build(); CStruct m2 = d2.builder() .set(4, descriptor.builder() .set(1, "boo") .build()) .build(); assertThat(m1, is(m1)); assertThat(m1, is(not(m2))); assertThat(m1.equals(m2), is(false)); assertThat(m1.equals(struct), is(false)); assertThat(m1.compareTo(m2), is(-1)); assertThat(m1.hashCode(), is(not(m2.hashCode()))); assertThat(m1.hashCode(), is(not(struct.hashCode()))); assertThat(d2.getDocumentation(), is(nullValue())); assertThat(d2.findFieldByName("msg"), is(d2.getFields()[3])); assertThat(d2.findFieldByName("boo"), is(nullValue())); assertThat(d2.findFieldById(4), is(d2.getFields()[3])); assertThat(d2.findFieldById(55), is(nullValue())); assertThat(descriptor.getAnnotations(), is(Collections.EMPTY_SET)); assertThat(d2.getAnnotations(), hasSize(1)); assertThat(d2.getAnnotations(), hasItem("nothing")); assertThat(descriptor.hasAnnotation("nothing"), is(false)); assertThat(d2.hasAnnotation("nothing"), is(true)); assertThat(descriptor.getAnnotationValue("nothing"), is(nullValue())); assertThat(d2.getAnnotationValue("nothing"), is("special")); assertThat(descriptor.isSimple(), is(true)); assertThat(d2.isSimple(), is(false)); }
private CStruct(Builder builder) { descriptor = builder.descriptor; values = builder.getValueMap(); }
CStruct implements CMessage<CStruct>, JsonCompactible { private CStruct(Builder builder) { descriptor = builder.descriptor; values = builder.getValueMap(); } }
CStruct implements CMessage<CStruct>, JsonCompactible { private CStruct(Builder builder) { descriptor = builder.descriptor; values = builder.getValueMap(); } private  CStruct(Builder builder); }
CStruct implements CMessage<CStruct>, JsonCompactible { private CStruct(Builder builder) { descriptor = builder.descriptor; values = builder.getValueMap(); } private  CStruct(Builder builder); Map<Integer,Object> values(); @Override boolean jsonCompact(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); @Nonnull @Override PMessageBuilder<CStruct,CField> mutate(); @Nonnull @Override CStructDescriptor descriptor(); }
CStruct implements CMessage<CStruct>, JsonCompactible { private CStruct(Builder builder) { descriptor = builder.descriptor; values = builder.getValueMap(); } private  CStruct(Builder builder); Map<Integer,Object> values(); @Override boolean jsonCompact(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); @Nonnull @Override PMessageBuilder<CStruct,CField> mutate(); @Nonnull @Override CStructDescriptor descriptor();  }