JBBPNamedNumericFieldMap implements JBBPFieldFinder { @Override public <T extends JBBPAbstractField> T findFieldForNameAndType(final String fieldName, final Class<T> fieldType) { final String normalizedName = JBBPUtils.normalizeFieldNameOrPath(fieldName); JBBPUtils.assertNotNull(fieldType, "Field type must not be null"); T result = null; for (final Map.Entry<JBBPNamedFieldInfo, JBBPNumericField> f : fieldMap.entrySet()) { if (normalizedName.equals(f.getKey().getFieldName()) && fieldType.isAssignableFrom(f.getValue().getClass())) { result = fieldType.cast(f.getValue()); break; } } return result; } JBBPNamedNumericFieldMap();  JBBPNamedNumericFieldMap(final JBBPExternalValueProvider externalValueProvider); JBBPExternalValueProvider getExternalValueProvider(); JBBPNumericField get(final JBBPNamedFieldInfo namedField); void putField(final JBBPNumericField field); JBBPNumericField remove(final JBBPNamedFieldInfo nameInfo); JBBPNumericField findForFieldOffset(final int offset); @Override T findFirstFieldForType(final Class<T> fieldType); @Override T findLastFieldForType(final Class<T> fieldType); @Override T findFieldForType(final Class<T> fieldType); @Override T findFieldForNameAndType(final String fieldName, final Class<T> fieldType); @Override T findFieldForPathAndType(final String fieldPath, final Class<T> fieldType); @Override JBBPAbstractField findFieldForName(final String fieldName); @Override JBBPAbstractField findFieldForPath(final String fieldPath); @Override boolean nameExists(final String fieldName); @Override boolean pathExists(final String fieldPath); void clear(); boolean isEmpty(); int size(); int getExternalFieldValue(final String externalFieldName, final JBBPCompiledBlock compiledBlock, final JBBPIntegerValueEvaluator evaluator);  }
@Test public void testFindFieldForNameAndType() { final JBBPNamedNumericFieldMap map = new JBBPNamedNumericFieldMap(); final JBBPNumericField field = new JBBPFieldInt(new JBBPNamedFieldInfo("test.test", "test", 0), 123); map.putField(field); assertSame(field, map.findFieldForNameAndType("tESt", JBBPFieldInt.class)); assertNull(map.findFieldForNameAndType("test", JBBPFieldByte.class)); assertNull(map.findFieldForNameAndType("test1", JBBPFieldInt.class)); try { map.findFieldForNameAndType(null, JBBPFieldInt.class); fail("Must throw NPE"); } catch (NullPointerException ex) { } try { map.findFieldForNameAndType("test.test", null); fail("Must throw NPE"); } catch (NullPointerException ex) { } }