public class BasicContentItem extends HashMap<String,Object> implements ContentItem
Convenience class to extend when implementing ContentItem
This class implements a copy constructor and a constructor that requires only the content item type. In addition, it implements all of the typed getters from ContentItem
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Constructor and Description |
---|
BasicContentItem()
Creates a new BasicContentItem without a type.
|
BasicContentItem(ContentItem pContentItem)
Copy constructor.
|
BasicContentItem(String pType)
Creates a new BasicContentItem without the specified type.
|
Modifier and Type | Method and Description |
---|---|
boolean |
getBooleanProperty(String key,
boolean defaultValue)
Convenience method for getting a boolean property value.
|
int |
getIntProperty(String key,
int defaultValue)
Convenience method for getting an int property value.
|
long |
getLongProperty(String key,
long defaultValue)
Convenience method for getting a long property value.
|
String |
getType()
Returns the type of this content item.
|
<T> T |
getTypedProperty(String key)
Convenience method for returning a property value without having to cast
the return value to the desired type.
|
protected void |
setType(String type)
Sets the type for this content item.
|
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
equals, hashCode, toString
finalize, getClass, notify, notifyAll, wait, wait, wait
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
public BasicContentItem()
public BasicContentItem(String pType)
pType
- the content item typegetType()
public BasicContentItem(ContentItem pContentItem)
pContentItem
- the contents for this instancepublic String getType()
getType
in interface ContentItem
protected void setType(String type)
public <T> T getTypedProperty(String key)
e.g. instead of
Object value = contentItem.get("record"); Record record = (Record)value;use
Record record = contentItem.getTypedProperty("record");
key
- key whose associated value is to be returned.ClassCastException
- if the property value could not be coerced
to the required typeHashMap.put(K, V)
public int getIntProperty(String key, int defaultValue)
key
- key whose associated int value is to be returned.
The value may be of type Integer or a String that
parses to an int.defaultValue
- the value to return if the ContentItem
does not contain the given key.RuntimeException
- if the value associated with the key cannot
be parsed into an intpublic long getLongProperty(String key, long defaultValue)
key
- key whose associated long value is to be returned.
The value may be of type Long or a String that
parses to a long.defaultValue
- the value to return if the ContentItem
does not contain the given key.RuntimeException
- if the value associated with the key cannot
be parsed into a longpublic boolean getBooleanProperty(String key, boolean defaultValue)
key
- key whose associated boolean value is to be
returned. The value may be of type Boolean or a
String that parses to a boolean.defaultValue
- the value to return if the ContentItem
does not contain the specified key.RuntimeException
- if the value associated with the key cannot
be parsed into a booleanCopyright © 2015, Oracle and/or its affiliates. All rights reserved.