public final class Bundle extends Object implements NestableData<Bundle>
Note: unlike a vertex, a bundle can contain null values in its data map, though these values will not be externally visible. Null values are however used in merge operations, where the secondary bundle's null data values will indicate that the key/value should be removed from the primary bundle's data.
Modifier and Type | Class and Description |
---|---|
static class |
Bundle.Builder |
Modifier and Type | Field and Description |
---|---|
static String |
DATA_KEY |
static String |
ID_KEY
Serialization constant definitions
|
static String |
META_KEY |
static String |
REL_KEY |
static String |
TYPE_KEY |
Modifier and Type | Method and Description |
---|---|
static com.tinkerpop.blueprints.CloseableIterable<Bundle> |
bundleStream(InputStream inputStream) |
Bundle |
dependentsOnly()
Return a bundle consisting of only dependent relations.
|
int |
depth()
The depth of this bundle tree, i.e.
|
String |
diff(Bundle target)
Return a JSON-Patch representation of the difference between
this bundle and another.
|
boolean |
equals(Object o) |
Bundle |
filterRelations(BiPredicate<String,Bundle> filter)
Filter relations, removing items that *match* the given
filter function.
|
Optional<Bundle> |
find(Predicate<Bundle> f) |
boolean |
forAny(Predicate<Bundle> f)
Test if a predicate function holds true for any item in the
bundle, including the top level.
|
static Bundle |
fromData(Object data)
Create a bundle from raw data.
|
static Bundle |
fromStream(InputStream stream)
Create a bundle from a stream containing JSON data..
|
static Bundle |
fromString(String json)
Create a bundle from a (JSON) string.
|
Bundle |
generateIds(Collection<String> scopes)
Generate missing IDs for the subtree.
|
Class<?> |
getBundleJavaClass()
Get the target class.
|
Map<String,Object> |
getData()
Get the bundle data.
|
<T> T |
getDataValue(String key)
Get a data value by its key.
|
com.google.common.collect.Multimap<String,Bundle> |
getDependentRelations()
Get only the bundle's relations which have a dependent
relationship.
|
String |
getId()
Get the id of the bundle's graph vertex (or null if it does not yet
exist).
|
Map<String,Object> |
getMetaData()
Get the bundle metadata
|
Collection<String> |
getPropertyKeys()
Return a list of names for mandatory properties, as represented in the
graph.
|
com.google.common.collect.Multimap<String,Bundle> |
getRelations()
Get the bundle's relation bundles.
|
List<Bundle> |
getRelations(String relation)
Get a set of relations.
|
EntityClass |
getType()
Get the type of entity this bundle represents as per the target class's
entity type key.
|
Collection<String> |
getUniquePropertyKeys()
Return a list of property keys which must be unique.
|
boolean |
hasGeneratedId()
Check if this bundle as a generated ID.
|
int |
hashCode() |
boolean |
hasMetaData()
Check if this bundle has associated metadata.
|
boolean |
hasRelations(String relation)
Check if this bundle contains the given relation set.
|
Bundle |
map(Function<Bundle,Bundle> f)
Run a function transforming all items in the bundle, including the top level,
returning a new bundle.
|
Bundle |
mergeDataWith(Bundle otherBundle)
Merge this bundle's data with that of another.
|
static Bundle |
of(EntityClass type)
Constructor for just a type.
|
static Bundle |
of(EntityClass type,
Map<String,Object> data)
Constructor for bundle without existing id or relations.
|
static Bundle |
of(EntityClass type,
Map<String,Object> data,
com.google.common.collect.Multimap<String,Bundle> relations)
Factory for bundle without existing id.
|
static Bundle |
of(String id,
EntityClass type,
Map<String,Object> data,
com.google.common.collect.Multimap<String,Bundle> relations)
Factory for bundle without existing id.
|
static Bundle |
of(String id,
EntityClass type,
Map<String,Object> data,
com.google.common.collect.Multimap<String,Bundle> relations,
Map<String,Object> meta)
Factory.
|
Bundle |
removeDataValue(String key)
Remove a value in the bundle's data.
|
Bundle |
removeRelation(String relation,
Bundle item)
Remove a single relation.
|
Bundle |
replaceRelations(com.google.common.collect.Multimap<String,Bundle> relations)
Set entire set of relations.
|
Map<String,Object> |
toData()
Serialize a bundle to raw data.
|
String |
toJson()
Serialize a bundle to a JSON string.
|
static void |
toStream(Bundle bundle,
OutputStream stream)
Write a bundle to a JSON stream.
|
String |
toString() |
Bundle |
withData(Map<String,Object> data)
Set the entire data map for this bundle.
|
Bundle |
withDataValue(String key,
Object value)
Set a value in the bundle's data.
|
Bundle |
withId(String id)
Get a bundle with the given id.
|
Bundle |
withMetaData(Map<String,Object> meta)
Set the entire meta data map for this bundle.
|
Bundle |
withMetaDataValue(String key,
Object value)
Set a value in the bundle's meta data.
|
Bundle |
withRelation(String relation,
Bundle other)
Add a bundle for a particular relation.
|
Bundle |
withRelations(com.google.common.collect.Multimap<String,Bundle> others)
Add a map of addition relationships.
|
Bundle |
withRelations(String relation,
List<Bundle> others)
Set bundles for a particular relation.
|
public static final String ID_KEY
public static final String REL_KEY
public static final String DATA_KEY
public static final String TYPE_KEY
public static final String META_KEY
public static Bundle of(String id, EntityClass type, Map<String,Object> data, com.google.common.collect.Multimap<String,Bundle> relations)
id
- The bundle's idtype
- The bundle's type classdata
- An initial map of datarelations
- An initial set of relationspublic static Bundle of(String id, EntityClass type, Map<String,Object> data, com.google.common.collect.Multimap<String,Bundle> relations, Map<String,Object> meta)
id
- The bundle's idtype
- The bundle's type classdata
- An initial map of datarelations
- An initial set of relationsmeta
- An initial map of metadatapublic static Bundle of(EntityClass type, Map<String,Object> data, com.google.common.collect.Multimap<String,Bundle> relations)
type
- The bundle's type classdata
- An initial map of datarelations
- An initial set of relationspublic static Bundle of(EntityClass type)
type
- The bundle's type classpublic static Bundle of(EntityClass type, Map<String,Object> data)
type
- The bundle's type classdata
- An initial map of datapublic String getId()
public Bundle withId(String id)
id
- The bundle's idpublic EntityClass getType()
public <T> T getDataValue(String key) throws ClassCastException
getDataValue
in interface NestableData<Bundle>
ClassCastException
- if the fetched data does not match the
type requestedpublic Bundle withDataValue(String key, Object value)
withDataValue
in interface NestableData<Bundle>
key
- The data keyvalue
- The data valuepublic Bundle withMetaDataValue(String key, Object value)
key
- The metadata keyvalue
- The metadata valuepublic Bundle removeDataValue(String key)
removeDataValue
in interface NestableData<Bundle>
key
- The data key to removepublic Map<String,Object> getMetaData()
public boolean hasMetaData()
public Bundle withData(Map<String,Object> data)
data
- The full data map to setpublic Bundle withMetaData(Map<String,Object> meta)
meta
- The full metadata map to setpublic com.google.common.collect.Multimap<String,Bundle> getRelations()
getRelations
in interface NestableData<Bundle>
public com.google.common.collect.Multimap<String,Bundle> getDependentRelations()
public Bundle replaceRelations(com.google.common.collect.Multimap<String,Bundle> relations)
replaceRelations
in interface NestableData<Bundle>
relations
- A full set of relationspublic Bundle withRelations(com.google.common.collect.Multimap<String,Bundle> others)
withRelations
in interface NestableData<Bundle>
others
- Additional relationship mappublic List<Bundle> getRelations(String relation)
getRelations
in interface NestableData<Bundle>
relation
- A relationship keypublic Bundle withRelations(String relation, List<Bundle> others)
withRelations
in interface NestableData<Bundle>
relation
- A relationship keyothers
- A set of relations for the given keypublic Bundle withRelation(String relation, Bundle other)
withRelation
in interface NestableData<Bundle>
relation
- A relationship keyother
- A related bundlepublic boolean hasRelations(String relation)
hasRelations
in interface NestableData<Bundle>
relation
- A relationship keypublic Bundle removeRelation(String relation, Bundle item)
relation
- A relationship keyitem
- The item to removepublic Bundle mergeDataWith(Bundle otherBundle)
otherBundle
- Another bundlepublic Bundle filterRelations(BiPredicate<String,Bundle> filter)
filter
- a predicate taking a string relation name
and a bundle itempublic Bundle map(Function<Bundle,Bundle> f)
f
- A (pure) function transforming the bundlepublic boolean forAny(Predicate<Bundle> f)
f
- A predicate functionpublic Class<?> getBundleJavaClass()
public Collection<String> getPropertyKeys()
public Collection<String> getUniquePropertyKeys()
public static Bundle fromData(Object data) throws DeserializationError
data
- A raw data objectDeserializationError
public Map<String,Object> toData()
public static Bundle fromString(String json) throws DeserializationError
json
- A JSON representationDeserializationError
public static Bundle fromStream(InputStream stream) throws DeserializationError
stream
- A JSON streamDeserializationError
public static void toStream(Bundle bundle, OutputStream stream) throws SerializationError
bundle
- the bundlestream
- the output streamSerializationError
public static com.tinkerpop.blueprints.CloseableIterable<Bundle> bundleStream(InputStream inputStream) throws DeserializationError
DeserializationError
public String toJson()
public boolean hasGeneratedId()
public int depth()
public Bundle dependentsOnly()
public Bundle generateIds(Collection<String> scopes)
scopes
- A set of parent scopes.Copyright © 2018 The European Holocaust Research Infrastructure (EHRI). All rights reserved.