JBBPFieldStruct extends JBBPAbstractField implements JBBPFieldFinder { @Override public JBBPAbstractField findFieldForPath(final String fieldPath) { final String[] parsedName = JBBPUtils.splitString(JBBPUtils.normalizeFieldNameOrPath(fieldPath), '.'); JBBPAbstractField found = this; final int firstIndex; if ("".equals(this.getFieldName())) { firstIndex = 0; } else if (parsedName[0].equals(this.getNameInfo().getFieldName())) { firstIndex = 1; found = this; } else { firstIndex = 0; found = null; } for (int i = firstIndex; found != null && i < parsedName.length; i++) { if (found instanceof JBBPFieldStruct) { found = ((JBBPFieldStruct) found).findFieldForName(parsedName[i]); } else { throw new JBBPFinderException("Detected a field instead of a structure as one of nodes in the path '" + fieldPath + '\'', fieldPath, null); } } return found; } JBBPFieldStruct(final JBBPNamedFieldInfo name, final JBBPAbstractField[] fields);  JBBPFieldStruct(final JBBPNamedFieldInfo name, final List<JBBPAbstractField> fields); JBBPAbstractField[] getArray(); @Override JBBPAbstractField findFieldForPath(final String fieldPath); @Override JBBPAbstractField findFieldForName(final String name); @Override T findFieldForType(final Class<T> fieldType); @Override T findFirstFieldForType(final Class<T> fieldType); @Override T findLastFieldForType(final Class<T> fieldType); @Override T findFieldForNameAndType(final String fieldName, final Class<T> fieldType); @Override boolean nameExists(final String fieldName); @Override boolean pathExists(final String fieldPath); @Override T findFieldForPathAndType(final String fieldPath, final Class<T> fieldType); @SafeVarargs final T mapTo(final String path, final T instance, final Function<Class<?>, Object>... instantiators); @SafeVarargs final T mapTo(final String path, final T instance, final int flags, final Function<Class<?>, Object>... instantiators); @SafeVarargs final T mapTo(final String path, final T instance, final JBBPMapperCustomFieldProcessor customFieldProcessor, final Function<Class<?>, Object>... instantiators); @SafeVarargs final T mapTo(final String path, final T instance, final JBBPMapperCustomFieldProcessor customFieldProcessor, final int flags, final Function<Class<?>, Object>... instantiators); @SafeVarargs final T mapTo(final T objectToMap, final Function<Class<?>, Object>... instantiators); @SafeVarargs final T mapTo(final T instance, final int flags, final Function<Class<?>, Object>... instantiators); @SafeVarargs final T mapTo(final T instance, final JBBPMapperCustomFieldProcessor customFieldProcessor, final Function<Class<?>, Object>... instantiators); @SafeVarargs final T mapTo(final T objectToMap, final JBBPMapperCustomFieldProcessor customFieldProcessor, final int flags, final Function<Class<?>, Object>... instantiators); @Override String getTypeAsString();  }
@Test public void testFindFieldForPath() { final JBBPFieldByte field = new JBBPFieldByte(new JBBPNamedFieldInfo("struct1.struct2.field3", "field3", 2048), (byte) 78); final JBBPFieldStruct struct2 = new JBBPFieldStruct(new JBBPNamedFieldInfo("struct1.struct2", "struct2", 1024), new JBBPAbstractField[] {field}); final JBBPFieldStruct struct1 = new JBBPFieldStruct(new JBBPNamedFieldInfo("struct1", "struct1", 1024), new JBBPAbstractField[] {struct2}); try { struct1.findFieldForPath(null); fail("Must throw NPE"); } catch (NullPointerException ex) { } try { struct1.findFieldForPath("struct1.struct2.field3.unknown"); fail("Must throw finder exception for attempt to find inside a field"); } catch (JBBPFinderException ex) { } assertNull(struct1.findFieldForPath("struct1.struct2.field0")); assertNull(struct1.findFieldForPath("struct")); assertSame(field, struct1.findFieldForPath("struct1.struct2.field3")); }