@Test public void testGet() { Map<String, String> attributes = ImmutableMap.of("submission_timestamp", "2018-03-12T21:02:18.123456Z"); Map<String, String> derived = DerivedAttributesMap.of(attributes); assertEquals("2018-03-12", derived.get("submission_date")); assertEquals("21", derived.get("submission_hour")); assertNull(derived.get("nonexistent_attribute")); assertThrows(IllegalArgumentException.class, () -> derived.get(1)); }
@Override public String get(Object key) { if (!(key instanceof String)) { throw new IllegalArgumentException("Key must be of type String"); } String value = attributes.get(key); if (value != null) { return value; } else if ("submission_date".equals(key)) { return submissionTimestampSubstring(0, 10); } else if ("submission_hour".equals(key)) { return submissionTimestampSubstring(11, 13); } return null; }
DerivedAttributesMap extends ForwardingMap<String, String> { @Override public String get(Object key) { if (!(key instanceof String)) { throw new IllegalArgumentException("Key must be of type String"); } String value = attributes.get(key); if (value != null) { return value; } else if ("submission_date".equals(key)) { return submissionTimestampSubstring(0, 10); } else if ("submission_hour".equals(key)) { return submissionTimestampSubstring(11, 13); } return null; } }
DerivedAttributesMap extends ForwardingMap<String, String> { @Override public String get(Object key) { if (!(key instanceof String)) { throw new IllegalArgumentException("Key must be of type String"); } String value = attributes.get(key); if (value != null) { return value; } else if ("submission_date".equals(key)) { return submissionTimestampSubstring(0, 10); } else if ("submission_hour".equals(key)) { return submissionTimestampSubstring(11, 13); } return null; } private  DerivedAttributesMap(Map<String, String> attributes); }
DerivedAttributesMap extends ForwardingMap<String, String> { @Override public String get(Object key) { if (!(key instanceof String)) { throw new IllegalArgumentException("Key must be of type String"); } String value = attributes.get(key); if (value != null) { return value; } else if ("submission_date".equals(key)) { return submissionTimestampSubstring(0, 10); } else if ("submission_hour".equals(key)) { return submissionTimestampSubstring(11, 13); } return null; } private  DerivedAttributesMap(Map<String, String> attributes); static Map<String, String> of(Map<String, String> m); @Override String get(Object key); @Override String getOrDefault(Object key, String defaultValue); @Override boolean containsKey(@Nullable Object key); }
DerivedAttributesMap extends ForwardingMap<String, String> { @Override public String get(Object key) { if (!(key instanceof String)) { throw new IllegalArgumentException("Key must be of type String"); } String value = attributes.get(key); if (value != null) { return value; } else if ("submission_date".equals(key)) { return submissionTimestampSubstring(0, 10); } else if ("submission_hour".equals(key)) { return submissionTimestampSubstring(11, 13); } return null; } private  DerivedAttributesMap(Map<String, String> attributes); static Map<String, String> of(Map<String, String> m); @Override String get(Object key); @Override String getOrDefault(Object key, String defaultValue); @Override boolean containsKey(@Nullable Object key);  }