de.deepamehta.core.model
Class CompositeValueModel

Show UML class diagram
java.lang.Object
  extended by de.deepamehta.core.model.CompositeValueModel
All Implemented Interfaces:
Iterable<String>
Direct Known Subclasses:
FacetValue, TopicmapsPlugin.StandardViewProperties

public class CompositeValueModel
extends Object
implements Iterable<String>

A recursive composite of key/value pairs. ### FIXDOC

Keys are strings, values are non-null atomic (string, int, long, double, boolean) or again a CompositeValueModel. ### FIXDOC


Field Summary
private  Map<String,Object> childTopics
          Internal representation.
private static String DEL_PREFIX
           
private  Logger logger
           
private static String REF_ID_PREFIX
           
private static String REF_URI_PREFIX
           
 
Constructor Summary
CompositeValueModel()
           
CompositeValueModel(JSONObject values)
           
 
Method Summary
 CompositeValueModel add(String childTypeUri, TopicModel value)
          Adds a value to a multiple-valued child.
 CompositeValueModel addDeletionRef(String childTypeUri, long refTopicId)
          Adds a by-ID topic deletion reference to a multiple-valued child.
 CompositeValueModel addRef(String childTypeUri, long refTopicId)
          Adds a by-ID topic reference to a multiple-valued child.
 CompositeValueModel addRef(String childTypeUri, String refTopicUri)
          Adds a by-URI topic reference to a multiple-valued child.
 CompositeValueModel clone()
           
private  TopicModel createTopicModel(String childTypeUri, Object value)
          Creates a topic model from a JSON value.
private  long delTopicId(String val)
           
 Object get(String childTypeUri)
          Accesses a child generically, regardless of single-valued or multiple-valued.
 boolean getBoolean(String childTypeUri)
          Convenience accessor for the *simple* value of a single-valued child.
 boolean getBoolean(String childTypeUri, boolean defaultValue)
          Convenience accessor for the *simple* value of a single-valued child.
 CompositeValueModel getCompositeValueModel(String childTypeUri)
          Convenience accessor for the *composite* value of a single-valued child.
 CompositeValueModel getCompositeValueModel(String childTypeUri, CompositeValueModel defaultValue)
          Convenience accessor for the *composite* value of a single-valued child.
 double getDouble(String childTypeUri)
          Convenience accessor for the *simple* value of a single-valued child.
 double getDouble(String childTypeUri, double defaultValue)
          Convenience accessor for the *simple* value of a single-valued child.
 int getInt(String childTypeUri)
          Convenience accessor for the *simple* value of a single-valued child.
 int getInt(String childTypeUri, int defaultValue)
          Convenience accessor for the *simple* value of a single-valued child.
 long getLong(String childTypeUri)
          Convenience accessor for the *simple* value of a single-valued child.
 long getLong(String childTypeUri, long defaultValue)
          Convenience accessor for the *simple* value of a single-valued child.
 Object getObject(String childTypeUri)
          Convenience accessor for the *simple* value of a single-valued child.
 Object getObject(String childTypeUri, Object defaultValue)
          Convenience accessor for the *simple* value of a single-valued child.
 String getString(String childTypeUri)
          Convenience accessor for the *simple* value of a single-valued child.
 String getString(String childTypeUri, String defaultValue)
          Convenience accessor for the *simple* value of a single-valued child.
 TopicModel getTopic(String childTypeUri)
          Accesses a single-valued child.
 TopicModel getTopic(String childTypeUri, TopicModel defaultValue)
          Accesses a single-valued child.
 List<TopicModel> getTopics(String childTypeUri)
          Accesses a multiple-valued child.
 List<TopicModel> getTopics(String childTypeUri, List<TopicModel> defaultValue)
          Accesses a multiple-valued child.
 boolean has(String childTypeUri)
          Checks if a child is directly contained in this composite value.
 Iterator<String> iterator()
          Returns an interator which iterates this composite value's child type URIs.
 CompositeValueModel put(String childTypeUri, CompositeValueModel value)
          Convenience method to put a *composite* value in a single-valued child.
 CompositeValueModel put(String childTypeUri, List<TopicModel> values)
          Sets the values of a multiple-valued child.
 CompositeValueModel put(String childTypeUri, Object value)
          Convenience method to put a *simple* value in a single-valued child.
 CompositeValueModel put(String childTypeUri, TopicModel value)
          Puts a value in a single-valued child.
 CompositeValueModel putRef(String childTypeUri, long refTopicId)
          Puts a by-ID topic reference for a single-valued child.
 CompositeValueModel putRef(String childTypeUri, String refTopicUri)
          Puts a by-URI topic reference for a single-valued child.
private  long refTopicId(String val)
           
private  String refTopicUri(String val)
           
 CompositeValueModel remove(String childTypeUri, TopicModel value)
          Removes a value from a multiple-valued child.
 int size()
          Returns the number of childs directly contained in this composite value.
 void throwInvalidAccess(String childTypeUri, ClassCastException e)
          ### TODO: should not be public.
 JSONObject toJSON()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

REF_ID_PREFIX

private static final String REF_ID_PREFIX
See Also:
Constant Field Values

REF_URI_PREFIX

private static final String REF_URI_PREFIX
See Also:
Constant Field Values

DEL_PREFIX

private static final String DEL_PREFIX
See Also:
Constant Field Values

childTopics

private Map<String,Object> childTopics
Internal representation. Key: String, value: TopicModel or List


logger

private Logger logger
Constructor Detail

CompositeValueModel

public CompositeValueModel()

CompositeValueModel

public CompositeValueModel(JSONObject values)
Method Detail

getTopic

public TopicModel getTopic(String childTypeUri)
Accesses a single-valued child. Throws if there is no such child.


getTopic

public TopicModel getTopic(String childTypeUri,
                           TopicModel defaultValue)
Accesses a single-valued child. Returns a default value if there is no such child.


getTopics

public List<TopicModel> getTopics(String childTypeUri)
Accesses a multiple-valued child. Throws if there is no such child.


getTopics

public List<TopicModel> getTopics(String childTypeUri,
                                  List<TopicModel> defaultValue)
Accesses a multiple-valued child. Returns a default value if there is no such child.


get

public Object get(String childTypeUri)
Accesses a child generically, regardless of single-valued or multiple-valued. Returns null if there is no such child.

Returns:
A TopicModel or List, or null if there is no such child.

has

public boolean has(String childTypeUri)
Checks if a child is directly contained in this composite value. ### TODO: could be renamed to "contains()"


size

public int size()
Returns the number of childs directly contained in this composite value. Multiple-valued childs count as one.


getString

public String getString(String childTypeUri)
Convenience accessor for the *simple* value of a single-valued child. Throws if the child doesn't exist.


getString

public String getString(String childTypeUri,
                        String defaultValue)
Convenience accessor for the *simple* value of a single-valued child. Returns a default value if the child doesn't exist.


getInt

public int getInt(String childTypeUri)
Convenience accessor for the *simple* value of a single-valued child. Throws if the child doesn't exist.


getInt

public int getInt(String childTypeUri,
                  int defaultValue)
Convenience accessor for the *simple* value of a single-valued child. Returns a default value if the child doesn't exist.


getLong

public long getLong(String childTypeUri)
Convenience accessor for the *simple* value of a single-valued child. Throws if the child doesn't exist.


getLong

public long getLong(String childTypeUri,
                    long defaultValue)
Convenience accessor for the *simple* value of a single-valued child. Returns a default value if the child doesn't exist.


getDouble

public double getDouble(String childTypeUri)
Convenience accessor for the *simple* value of a single-valued child. Throws if the child doesn't exist.


getDouble

public double getDouble(String childTypeUri,
                        double defaultValue)
Convenience accessor for the *simple* value of a single-valued child. Returns a default value if the child doesn't exist.


getBoolean

public boolean getBoolean(String childTypeUri)
Convenience accessor for the *simple* value of a single-valued child. Throws if the child doesn't exist.


getBoolean

public boolean getBoolean(String childTypeUri,
                          boolean defaultValue)
Convenience accessor for the *simple* value of a single-valued child. Returns a default value if the child doesn't exist.


getObject

public Object getObject(String childTypeUri)
Convenience accessor for the *simple* value of a single-valued child. Throws if the child doesn't exist.


getObject

public Object getObject(String childTypeUri,
                        Object defaultValue)
Convenience accessor for the *simple* value of a single-valued child. Returns a default value if the child doesn't exist.


getCompositeValueModel

public CompositeValueModel getCompositeValueModel(String childTypeUri)
Convenience accessor for the *composite* value of a single-valued child. Throws if the child doesn't exist.


getCompositeValueModel

public CompositeValueModel getCompositeValueModel(String childTypeUri,
                                                  CompositeValueModel defaultValue)
Convenience accessor for the *composite* value of a single-valued child. Returns a default value if the child doesn't exist.


put

public CompositeValueModel put(String childTypeUri,
                               TopicModel value)
Puts a value in a single-valued child. An existing value is overwritten.


put

public CompositeValueModel put(String childTypeUri,
                               Object value)
Convenience method to put a *simple* value in a single-valued child. An existing value is overwritten.

Parameters:
value - a String, Integer, Long, Double, or a Boolean.
Returns:
this CompositeValueModel.

put

public CompositeValueModel put(String childTypeUri,
                               CompositeValueModel value)
Convenience method to put a *composite* value in a single-valued child. An existing value is overwritten.

Returns:
this CompositeValueModel.

putRef

public CompositeValueModel putRef(String childTypeUri,
                                  long refTopicId)
Puts a by-ID topic reference for a single-valued child. An existing reference is overwritten.

Used to maintain the assigment of an *aggregated* child. Not applicable for a *compositioned* child.


putRef

public CompositeValueModel putRef(String childTypeUri,
                                  String refTopicUri)
Puts a by-URI topic reference for a single-valued child. An existing reference is overwritten.

Used to maintain the assigment of an *aggregated* child. Not applicable for a *compositioned* child.


add

public CompositeValueModel add(String childTypeUri,
                               TopicModel value)
Adds a value to a multiple-valued child.


put

public CompositeValueModel put(String childTypeUri,
                               List<TopicModel> values)
Sets the values of a multiple-valued child. Existing values are overwritten.


remove

public CompositeValueModel remove(String childTypeUri,
                                  TopicModel value)
Removes a value from a multiple-valued child.


addRef

public CompositeValueModel addRef(String childTypeUri,
                                  long refTopicId)
Adds a by-ID topic reference to a multiple-valued child. Used to maintain the assigments of *aggregated* childs. Not applicable for *compositioned* childs.


addRef

public CompositeValueModel addRef(String childTypeUri,
                                  String refTopicUri)
Adds a by-URI topic reference to a multiple-valued child. Used to maintain the assigments of *aggregated* childs. Not applicable for *compositioned* childs.


addDeletionRef

public CompositeValueModel addDeletionRef(String childTypeUri,
                                          long refTopicId)
Adds a by-ID topic deletion reference to a multiple-valued child. Used to maintain the assigments of *aggregated* childs. Not applicable for *compositioned* childs.


iterator

public Iterator<String> iterator()
Returns an interator which iterates this composite value's child type URIs.

Specified by:
iterator in interface Iterable<String>

toJSON

public JSONObject toJSON()

clone

public CompositeValueModel clone()
Overrides:
clone in class Object

toString

public String toString()
Overrides:
toString in class Object

createTopicModel

private TopicModel createTopicModel(String childTypeUri,
                                    Object value)
Creates a topic model from a JSON value. Both topic serialization formats are supported: 1) canonic format -- contains entire topic models. 2) compact format -- contains the topic value only (simple or composite).


refTopicId

private long refTopicId(String val)

refTopicUri

private String refTopicUri(String val)

delTopicId

private long delTopicId(String val)

throwInvalidAccess

public void throwInvalidAccess(String childTypeUri,
                               ClassCastException e)
### TODO: should not be public. Specify interfaces also for model classes?



Copyright © 2014. All Rights Reserved.