OrderedItemMetadataFilter extends MetadataFilterImpl { @Override public MetadataCollection filter(MetadataCollection originalCollection) { MetadataCollection results = new MetadataCollection(); Map<String, String> original; if(ignoreCase()) { original = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); original.putAll(MetadataCollection.asMap(originalCollection)); } else { original = MetadataCollection.asMap(originalCollection); } for (String key : getMetadataKeys()) { String value = original.get(key); if (value != null) { results.add(new MetadataElement(key, value)); } else { results.add(new MetadataElement(key, "")); } } return results; }  @Override MetadataCollection filter(MetadataCollection originalCollection); void setMetadataKeys(List<String> metadataKeys); List<String> getMetadataKeys(); void setIgnoreCase(Boolean ignoreCase); Boolean getIgnoreCase();  }
@Test public void testFilter(){ OrderedItemMetadataFilter filter = new OrderedItemMetadataFilter(); filter.setMetadataKeys(Arrays.asList("key1", "key2", "key3")); AdaptrisMessage message = AdaptrisMessageFactory.getDefaultInstance().newMessage(); message.addMetadata("Key1", "value1"); message.addMetadata("key3", "value3"); MetadataCollection collection = filter.filter(message); assertEquals(3,collection.size()); assertEquals("key1", collection.get(0).getKey()); assertEquals("", collection.get(0).getValue()); assertEquals("key2", collection.get(1).getKey()); assertEquals("", collection.get(1).getValue()); assertEquals("key3", collection.get(2).getKey()); assertEquals("value3", collection.get(2).getValue()); }