### Question:
SpatialMetadata extends IIOMetadata implements WarningProducer { public <T> T getInstanceForType(final Class<T> type) throws IllegalArgumentException { if (instances == null) { instances = new HashMap<>(); } @SuppressWarnings("unchecked") T object = (T) instances.get(type); if (object == null) { if (CoordinateReferenceSystem.class.isAssignableFrom(type)) { final ReferencingBuilder builder; try { builder = new ReferencingBuilder(new MetadataNodeParser(this, SpatialMetadataFormat.GEOTK_FORMAT_NAME, ReferencingBuilder.PATH, null)); } catch (NoSuchElementException e) { return null; } object = type.cast(builder.build()); } else { final MetadataNodeParser accessor; try { accessor = new MetadataNodeParser(this, getMetadataFormatName(type), type); } catch (NoSuchElementException e) { return null; } object = getInstanceForType(type, accessor); } instances.put(type, object); } return object; } private  SpatialMetadata();  SpatialMetadata(final IIOMetadataFormat format);  SpatialMetadata(final IIOMetadataFormat format, final ImageReader reader, final IIOMetadata fallback);  SpatialMetadata(final boolean isStreamMetadata, final ImageReader reader, final IIOMetadata fallback);  SpatialMetadata(final IIOMetadataFormat format, final ImageWriter writer, final IIOMetadata fallback);  SpatialMetadata(final boolean isStreamMetadata, final ImageWriter writer, final IIOMetadata fallback); private  SpatialMetadata(final IIOMetadataFormat format, final boolean isStreamMetadata,
            final Object owner, final ImageReaderWriterSpi spi, final IIOMetadata fallback); T getInstanceForType(final Class<T> type); void clearInstancesCache(); T getInstanceForType(final Class<T> type, final String path); List<T> getListForType(final Class<T> type); List<T> getListForType(final Class<T> type, final String path, final String children); @Override IIOMetadataFormat getMetadataFormat(final String formatName); @Override Node getAsTree(final String formatName); @Override void mergeTree(final String formatName, final Node root); @Override boolean isReadOnly(); void setReadOnly(final boolean ro); @Override Locale getLocale(); Level getWarningLevel(); void setWarningLevel(final Level level); @Override boolean warningOccurred(final LogRecord record); @Override void reset(); @Override String toString(); static final SpatialMetadata EMPTY; final IIOMetadataFormat format; }### Answer:
@Test public void testRectifiedGrid() { final SpatialMetadata metadata = new SpatialMetadata(SpatialMetadataFormat.getImageInstance(GEOTK_FORMAT_NAME)); final int[] limitsLow = new int[] {4, 10, 16}; final int[] limitsHigh = new int[] {6, 2, 8}; final double[] vector0 = new double[] {2, 5, 8}; final double[] vector1 = new double[] {3, 1, 4}; MetadataNodeAccessor accessor = new MetadataNodeAccessor(metadata, null, "RectifiedGridDomain/Limits", null); accessor.setAttribute("low", limitsLow); accessor.setAttribute("high", limitsHigh); accessor = new MetadataNodeAccessor(metadata, null, "RectifiedGridDomain/OffsetVectors", "OffsetVector"); accessor.selectChild(accessor.appendChild()); accessor.setAttribute("values", vector0); accessor.selectChild(accessor.appendChild()); accessor.setAttribute("values", vector1); final RectifiedGrid grid = metadata.getInstanceForType(RectifiedGrid.class); final GridEnvelope ge = grid.getExtent(); final List<double[]> vectors = grid.getOffsetVectors(); assertEquals(2, vectors.size()); assertTrue(Arrays.equals(vector0, vectors.get(0))); assertTrue(Arrays.equals(vector1, vectors.get(1))); }