PPrimitive implements PDescriptor { public static PPrimitive findByName(String name) { switch (name) { case "void": return VOID; case "bool": return BOOL; case "byte": case "i8": return BYTE; case "i16": return I16; case "i32": return I32; case "i64": return I64; case "double": return DOUBLE; case "string": return STRING; case "binary": return BINARY; } return null; } private  PPrimitive(PType type, Object defValue, boolean nativePrimitive); @Nonnull PPrimitiveProvider provider(); @Override String getProgramName(); @Nonnull @Override String getName(); @Nonnull @Override String getQualifiedName(String programContext); @Override String toString(); @Nonnull @Override PType getType(); @Override boolean equals(Object o); @Override int hashCode(); @Override Object getDefaultValue(); boolean isNativePrimitive(); static PPrimitive findByName(String name); static final PPrimitive VOID; static final PPrimitive BOOL; static final PPrimitive BYTE; static final PPrimitive I16; static final PPrimitive I32; static final PPrimitive I64; static final PPrimitive DOUBLE; static final PPrimitive STRING; static final PPrimitive BINARY; }
@Test public void testFindByName() { assertThat(PPrimitive.findByName("void"), is(PPrimitive.VOID)); assertThat(PPrimitive.findByName("bool"), is(PPrimitive.BOOL)); assertThat(PPrimitive.findByName("byte"), is(PPrimitive.BYTE)); assertThat(PPrimitive.findByName("i8"), is(PPrimitive.BYTE)); assertThat(PPrimitive.findByName("i16"), is(PPrimitive.I16)); assertThat(PPrimitive.findByName("i32"), is(PPrimitive.I32)); assertThat(PPrimitive.findByName("i64"), is(PPrimitive.I64)); assertThat(PPrimitive.findByName("double"), is(PPrimitive.DOUBLE)); assertThat(PPrimitive.findByName("string"), is(PPrimitive.STRING)); assertThat(PPrimitive.findByName("binary"), is(PPrimitive.BINARY)); assertThat(PPrimitive.findByName("goo"), is(nullValue())); }